1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: */
7:
8: namespace Nette\Forms;
9:
10: use Nette;
11:
12:
13: /**
14: * A user group of form controls.
15: *
16: * @property-read array $controls
17: * @property-read array $options
18: */
19: class ControlGroup extends Nette\Object
20: {
21: /** @var \SplObjectStorage */
22: protected $controls;
23:
24: /** @var array user options */
25: private $options = array();
26:
27:
28: public function __construct()
29: {
30: $this->controls = new \SplObjectStorage;
31: }
32:
33:
34: /**
35: * @return self
36: */
37: public function add()
38: {
39: foreach (func_get_args() as $num => $item) {
40: if ($item instanceof IControl) {
41: $this->controls->attach($item);
42:
43: } elseif ($item instanceof \Traversable || is_array($item)) {
44: foreach ($item as $control) {
45: $this->controls->attach($control);
46: }
47:
48: } else {
49: throw new Nette\InvalidArgumentException("Only IFormControl items are allowed, the #$num parameter is invalid.");
50: }
51: }
52: return $this;
53: }
54:
55:
56: /**
57: * @return array IFormControl
58: */
59: public function getControls()
60: {
61: return iterator_to_array($this->controls);
62: }
63:
64:
65: /**
66: * Sets user-specific option.
67: * Options recognized by DefaultFormRenderer
68: * - 'label' - textual or Html object label
69: * - 'visual' - indicates visual group
70: * - 'container' - container as Html object
71: * - 'description' - textual or Html object description
72: * - 'embedNext' - describes how render next group
73: *
74: * @param string key
75: * @param mixed value
76: * @return self
77: */
78: public function setOption($key, $value)
79: {
80: if ($value === NULL) {
81: unset($this->options[$key]);
82:
83: } else {
84: $this->options[$key] = $value;
85: }
86: return $this;
87: }
88:
89:
90: /**
91: * Returns user-specific option.
92: * @param string key
93: * @param mixed default value
94: * @return mixed
95: */
96: public function getOption($key, $default = NULL)
97: {
98: return isset($this->options[$key]) ? $this->options[$key] : $default;
99: }
100:
101:
102: /**
103: * Returns user-specific options.
104: * @return array
105: */
106: public function getOptions()
107: {
108: return $this->options;
109: }
110:
111: }
112: