~ubuntu-branches/ubuntu/trusty/php-horde-view/trusty-proposed

« back to all changes in this revision

Viewing changes to Horde_View-2.0.1/lib/Horde/View/Helper/Form/Builder.php

  • Committer: Package Import Robot
  • Author(s): Mathieu Parent
  • Date: 2012-11-30 22:14:57 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20121130221457-n9gb5mxywd01k800
Tags: 2.0.1-1
* New upstream version 2.0.1
* Fixed watchfile
* Updated Standards-Version to 3.9.3: no change
* Updated copyright format URL
* Updated debian/pearrc to install Horde apps in /usr/share/horde
  instead of /usr/share/horde4
* Updated Homepage
* Added Vcs-* fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright 2007-2008 Maintainable Software, LLC
 
4
 * Copyright 2008-2012 Horde LLC (http://www.horde.org/)
 
5
 *
 
6
 * @author     Mike Naberezny <mike@maintainable.com>
 
7
 * @author     Derek DeVries <derek@maintainable.com>
 
8
 * @author     Chuck Hagenbuch <chuck@horde.org>
 
9
 * @license    http://www.horde.org/licenses/bsd
 
10
 * @category   Horde
 
11
 * @package    View
 
12
 * @subpackage Helper
 
13
 */
 
14
 
 
15
/**
 
16
 * @author     Mike Naberezny <mike@maintainable.com>
 
17
 * @author     Derek DeVries <derek@maintainable.com>
 
18
 * @author     Chuck Hagenbuch <chuck@horde.org>
 
19
 * @license    http://www.horde.org/licenses/bsd
 
20
 * @category   Horde
 
21
 * @package    View
 
22
 * @subpackage Helper
 
23
 */
 
24
class Horde_View_Helper_Form_Builder
 
25
{
 
26
    private $_objectName;
 
27
    private $_object;
 
28
    private $_view;
 
29
    private $_options;
 
30
    private $_end;
 
31
 
 
32
    public function __construct($objectName, $object, $view, $options)
 
33
    {
 
34
        $this->_objectName = $objectName;
 
35
        $this->_object     = $object;
 
36
        $this->_view       = $view;
 
37
 
 
38
        $this->_end = isset($options['end']) ? $options['end'] : '';
 
39
        unset($options['end']);
 
40
        $this->_options = $options;
 
41
    }
 
42
 
 
43
    public function __call($method, $args)
 
44
    {
 
45
        if (empty($args)) {
 
46
            throw new InvalidArgumentException('No object property specified');
 
47
        }
 
48
        $objectProperty = $args[0];
 
49
        $options        = array_merge(isset($args[1]) ? $args[1] : array(),
 
50
                                      array('object' => $this->_object));
 
51
 
 
52
        return $this->_view->{$method}($this->_objectName, $objectProperty, $options);
 
53
    }
 
54
 
 
55
    public function fieldsFor($name)
 
56
    {
 
57
        $name = "{$this->_objectName}[$name]";
 
58
        $args = func_get_args();
 
59
        $args[0] = $name;
 
60
        return call_user_func_array(array($this->_view, 'fieldsFor'), $args);
 
61
    }
 
62
 
 
63
    public function checkBox($method, $options = array(), $checkedValue = '1',
 
64
                             $uncheckedValue = '0')
 
65
    {
 
66
        $options = array_merge($options, array('object' => $this->_object));
 
67
        return $this->_view->checkBox($this->_objectName, $method, $options, $checkedValue, $uncheckedValue);
 
68
    }
 
69
 
 
70
    public function radioButton($method, $tagValue, $options = array())
 
71
    {
 
72
        $options = array_merge($options, array('object' => $this->_object));
 
73
        return $this->_view->radioButton($this->_objectName, $method, $tagValue, $options);
 
74
    }
 
75
 
 
76
    public function submit($value = 'Save changes', $options = array())
 
77
    {
 
78
        $options = array_merge(array('id' => "{$this->_objectName}_submit"), $options);
 
79
        return $this->_view->submitTag($value, $options);
 
80
    }
 
81
 
 
82
    public function end()
 
83
    {
 
84
        echo $this->_end;
 
85
    }
 
86
}