1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19: 20: 21: 22: 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: }
87: