1: <?php
2:
3: 4: 5:
6: class Quform_Element_Page extends Quform_Element_Group
7: {
8: 9: 10: 11: 12: 13:
14: public function render(array $context = array())
15: {
16: $context = $this->prepareContext($context);
17:
18: $output = sprintf('<div class="%s">', Quform::escape(Quform::sanitizeClass($this->getContainerClasses())));
19: $output .= $this->getTitleDescriptionHtml();
20: $output .= '<div class="quform-child-elements">';
21:
22: foreach ($this->elements as $key => $element) {
23: $output .= $element->render($context);
24: }
25:
26: $output .= '</div></div>';
27:
28: return $output;
29: }
30:
31: 32: 33: 34: 35:
36: protected function getContainerClasses()
37: {
38: $classes = array(
39: 'quform-element',
40: 'quform-element-page',
41: sprintf('quform-page-%s', $this->getId()),
42: sprintf('quform-page-%s', $this->getIdentifier()),
43: 'quform-cf',
44: sprintf('quform-group-style-%s', $this->config('groupStyle'))
45: );
46:
47: if ($this->isFirstPage()) {
48: $classes[] = 'quform-first-page';
49: }
50:
51: if ($this->isLastPage()) {
52: $classes[] = 'quform-last-page';
53: }
54:
55: if ($this->isCurrentPage()) {
56: $classes[] = 'quform-current-page';
57: }
58:
59: $classes = apply_filters('quform_container_classes', $classes, $this);
60: $classes = apply_filters('quform_container_classes_' . $this->getIdentifier(), $classes, $this);
61:
62: return $classes;
63: }
64:
65: 66: 67: 68: 69:
70: public function getLabel()
71: {
72: return apply_filters('quform_page_label_' . $this->getIdentifier(), $this->config('label'), $this, $this->getForm());
73: }
74:
75: 76: 77:
78: public function isFirstPage()
79: {
80: return $this->form->getFirstPage() == $this;
81: }
82:
83: 84: 85:
86: public function isLastPage()
87: {
88: return $this->form->getLastPage() == $this;
89: }
90:
91: 92: 93:
94: public function isCurrentPage()
95: {
96: return $this->form->getCurrentPage() == $this;
97: }
98:
99: 100: 101: 102: 103:
104: public function isValid()
105: {
106: $valid = true;
107:
108: foreach ($this->getRecursiveIterator() as $element) {
109: if ( ! $element instanceof Quform_Element_Field) {
110: continue;
111: }
112:
113: if ( ! $element->isValid()) {
114: $valid = false;
115: }
116: }
117:
118: return $valid;
119: }
120:
121: 122: 123: 124: 125:
126: public function getErrors()
127: {
128: $errors = array();
129:
130: foreach ($this->getRecursiveIterator() as $element) {
131: if ( ! $element instanceof Quform_Element_Field) {
132: continue;
133: }
134:
135: if ($element->hasError()) {
136: foreach ($element->getErrorArray() as $identifier => $message) {
137: $errors[$identifier] = $message;
138: }
139: }
140: }
141:
142: return $errors;
143: }
144:
145: 146: 147: 148: 149:
150: protected function getCssSelectors()
151: {
152: return array(
153: 'page' => '%s .quform-page-%s',
154: 'pageTitle' => '%s .quform-page-%s .quform-page-title',
155: 'pageDescription' => '%s .quform-page-%s .quform-page-description',
156: 'pageElements' => '%s .quform-page-%s > .quform-child-elements'
157: );
158: }
159:
160: 161: 162: 163: 164: 165:
166: public static function getDefaultConfig($key = null)
167: {
168: $config = apply_filters('quform_default_config_page', array(
169:
170: 'label' => '',
171: 'title' => '',
172: 'titleTag' => 'h3',
173: 'description' => '',
174:
175:
176: 'fieldSize' => 'inherit',
177: 'fieldWidth' => 'inherit',
178: 'fieldWidthCustom' => '',
179: 'groupStyle' => 'plain',
180: 'borderColor' => '',
181: 'backgroundColor' => '',
182: 'styles' => array(),
183:
184:
185: 'tooltipType' => 'inherit',
186: 'tooltipEvent' => 'inherit',
187: 'labelPosition' => 'inherit',
188: 'labelWidth' => '',
189: 'showLabelInEmail' => false,
190: 'showLabelInEntry' => false,
191:
192:
193: 'logicEnabled' => false,
194: 'logicAction' => true,
195: 'logicMatch' => 'all',
196: 'logicRules' => array(),
197:
198:
199: 'elements' => array()
200: ));
201:
202: $config['type'] = 'page';
203:
204: if (Quform::isNonEmptyString($key)) {
205: return Quform::get($config, $key);
206: }
207:
208: return $config;
209: }
210: }
211: