1: <?php
2:
3: 4: 5:
6: abstract class Quform_Element_Container extends Quform_Element
7: {
8: 9: 10: 11:
12: protected $elements = array();
13:
14: 15: 16: 17:
18: protected $hasNonEmptyChild = false;
19:
20: 21: 22: 23:
24: protected $hasVisibleChild = false;
25:
26: 27: 28: 29: 30:
31: public function getElements()
32: {
33: return $this->elements;
34: }
35:
36: 37: 38: 39: 40:
41: public function addElement(Quform_Element $element)
42: {
43: $this->elements[$element->getName()] = $element;
44: }
45:
46: 47: 48: 49: 50: 51:
52: public function insertElementAt(Quform_Element $element, $offset)
53: {
54: $offset = max(0, min($offset, count($this->elements)));
55:
56: $this->elements = array_slice($this->elements, 0, $offset, true)
57: + array($element->getName() => $element)
58: + array_slice($this->elements, $offset, null, true);
59: }
60:
61: 62: 63: 64: 65:
66: protected function getTitleDescriptionHtml()
67: {
68: $output = '';
69: $title = $this->config('title');
70: $description = $this->config('description');
71: $showTitle = Quform::isNonEmptyString($title);
72: $showDescription = Quform::isNonEmptyString($description);
73:
74: switch (get_class($this)) {
75: case 'Quform_Element_Page':
76: $prefix = 'page';
77: break;
78: case 'Quform_Element_Group':
79: $prefix = 'group';
80: break;
81: }
82:
83: if ($showTitle || $showDescription) {
84: $output .= sprintf('<div class="quform-%s-title-description">', $prefix);
85:
86: if ($showTitle) {
87: $output .= Quform::getHtmlTag($this->config('titleTag'), array('class' => sprintf('quform-%s-title', $prefix)), do_shortcode($title));
88: }
89:
90: if ($showDescription) {
91: $output .= Quform::getHtmlTag('p', array('class' => sprintf('quform-%s-description', $prefix)), do_shortcode($description));
92: }
93:
94: $output .= '</div>';
95: }
96:
97: return $output;
98: }
99:
100: 101: 102:
103: abstract protected function getContainerClasses();
104:
105: 106: 107: 108: 109: 110:
111: protected function renderCss(array $context = array())
112: {
113: $css = '';
114:
115: foreach ($this->elements as $element) {
116: $css .= $element->getCss($context);
117: }
118:
119: $css .= parent::renderCss($context);
120:
121: return $css;
122: }
123:
124: 125: 126: 127: 128:
129: public function setHasNonEmptyChild($flag)
130: {
131: $this->hasNonEmptyChild = (bool) $flag;
132: }
133:
134: 135: 136: 137: 138:
139: public function setHasVisibleChild($flag)
140: {
141: $this->hasVisibleChild = (bool) $flag;
142: }
143:
144: 145: 146: 147: 148:
149: public function getHasVisibleChild()
150: {
151: return $this->hasVisibleChild;
152: }
153:
154: 155: 156: 157: 158:
159: public function isEmpty()
160: {
161: return ! $this->hasNonEmptyChild;
162: }
163:
164: 165: 166: 167: 168:
169: public function isHidden()
170: {
171: return $this->isConditionallyHidden() || ! $this->hasVisibleChild;
172: }
173:
174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185:
186: public function getRecursiveIterator($mode = RecursiveIteratorIterator::LEAVES_ONLY)
187: {
188: return new RecursiveIteratorIterator(
189: new Quform_Element_Container_Iterator($this),
190: $mode
191: );
192: }
193: }
194: