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