1 |
a45e4bc1
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Conditional engine to process dependencies within the webform's conditionals.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Performs analysis and topological sorting on the conditionals.
|
10 |
|
|
*/
|
11 |
|
|
class WebformConditionals {
|
12 |
|
|
|
13 |
|
|
// Define constants for the result of an analysis of the conditionals on
|
14 |
|
|
// a page for a given set of input values. Determines whether the component
|
15 |
|
|
// is always hidden, always shown, or may or may not be shown depending upon
|
16 |
|
|
// other values on the same page. In the last case, the component needs to be
|
17 |
|
|
// rendered on the page because at least one source component is on the same
|
18 |
|
|
// page. The field will be hidden with JavaScript.
|
19 |
|
|
const componentHidden = 0;
|
20 |
|
|
const componentShown = 1;
|
21 |
|
|
const componentDependent = 2;
|
22 |
|
|
|
23 |
|
|
protected static $conditionals = array();
|
24 |
|
|
|
25 |
|
|
protected $node;
|
26 |
|
|
protected $topologicalOrder;
|
27 |
|
|
protected $pageMap;
|
28 |
|
|
protected $childrenMap;
|
29 |
|
|
protected $visibilityMap;
|
30 |
|
|
protected $requiredMap;
|
31 |
|
|
protected $setMap;
|
32 |
|
|
protected $markupMap;
|
33 |
|
|
|
34 |
|
|
public $errors;
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* Creates and caches a WebformConditional for a given node.
|
38 |
|
|
*/
|
39 |
|
|
static function factory($node) {
|
40 |
|
|
if (!isset(self::$conditionals[$node->nid])) {
|
41 |
|
|
self::$conditionals[$node->nid] = new WebformConditionals($node);
|
42 |
|
|
}
|
43 |
|
|
return self::$conditionals[$node->nid];
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* Constructs a WebformConditional.
|
48 |
|
|
*/
|
49 |
|
|
function __construct($node) {
|
50 |
|
|
$this->node = $node;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* Sorts the conditionals into topological order.
|
55 |
|
|
*
|
56 |
|
|
* The "nodes" of the list are the conditionals, not the components that
|
57 |
|
|
* they operate upon.
|
58 |
|
|
*
|
59 |
|
|
* The webform components must already be sorted into component tree order
|
60 |
|
|
* before calling this method.
|
61 |
|
|
*
|
62 |
|
|
* See http://en.wikipedia.org/wiki/Topological_sorting
|
63 |
|
|
*/
|
64 |
|
|
protected function topologicalSort() {
|
65 |
|
|
$components = $this->node->webform['components'];
|
66 |
|
|
$conditionals = $this->node->webform['conditionals'];
|
67 |
|
|
$errors = array();
|
68 |
|
|
|
69 |
|
|
// Generate a component to conditional map for conditional targets.
|
70 |
|
|
$cid_to_target_rgid = array();
|
71 |
|
|
$cid_hidden = array();
|
72 |
|
|
foreach ($conditionals as $rgid => $conditional) {
|
73 |
|
|
foreach ($conditional['actions'] as $aid => $action) {
|
74 |
|
|
$target_id = $action['target'];
|
75 |
|
|
$cid_to_target_rgid[$target_id][$rgid] = $rgid;
|
76 |
|
|
if ($action['action'] == 'show') {
|
77 |
|
|
$cid_hidden[$target_id] = isset($cid_hidden[$target_id]) ? $cid_hidden[$target_id] + 1 : 1;
|
78 |
|
|
if ($cid_hidden[$target_id] == 2) {
|
79 |
|
|
$component = $components[$target_id];
|
80 |
|
|
$errors[$component['page_num']][] = t('More than one conditional hides or shows component "@name".',
|
81 |
|
|
array('@name' => $component['name']));
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
// Generate T-Orders for each page
|
88 |
|
|
$new_entry = array('in' => array(), 'out' => array(), 'rgid' => array());
|
89 |
|
|
$page_num = 0;
|
90 |
|
|
// If the first component is a page break, then no component is on page 1. Create empty arrays for page 1.
|
91 |
|
|
$sorted = array(1 => array());
|
92 |
|
|
$page_map = array(1 => array());
|
93 |
|
|
$component = reset($components);
|
94 |
|
|
while ($component) {
|
95 |
|
|
$cid = $component['cid'];
|
96 |
|
|
|
97 |
|
|
// Start a new page, if needed
|
98 |
|
|
if ($component['page_num'] > $page_num ) {
|
99 |
|
|
$page_num = $component['page_num'];
|
100 |
|
|
// Create an empty list that will contain the sorted elements.
|
101 |
|
|
// This list is known as L in the literature.
|
102 |
|
|
$sorted[$page_num] = array();
|
103 |
|
|
|
104 |
|
|
// Create an empty list of dependency nodes for this page.
|
105 |
|
|
$nodes = array();
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
// Create the pageMap as a side benefit of generating the t-sort.
|
109 |
|
|
$page_map[$page_num][$cid] = $cid;
|
110 |
|
|
|
111 |
|
|
// Process component by adding it's conditional data to a component-tree-traversal order an index of:
|
112 |
|
|
// - incoming dependencies = the source components for the conditions for this target component and
|
113 |
|
|
// - outgoing dependencies = components which depend upon the target component
|
114 |
|
|
// Note: Surprisingly, 0 is a valid rgid, as well as a valid rid. Use -1 as a semaphore.
|
115 |
|
|
if (isset($cid_to_target_rgid[$cid])) {
|
116 |
|
|
// The component is the target of conditional(s)
|
117 |
|
|
foreach ($cid_to_target_rgid[$cid] as $rgid) {
|
118 |
|
|
$conditional = $conditionals[$rgid];
|
119 |
|
|
if (!isset($nodes[$cid])) {
|
120 |
|
|
$nodes[$cid] = $new_entry;
|
121 |
|
|
}
|
122 |
|
|
$nodes[$cid]['rgid'][$rgid] = $rgid;
|
123 |
|
|
foreach ($conditional['rules'] as $rule) {
|
124 |
|
|
if ($rule['source_type'] == 'component') {
|
125 |
|
|
$source_id = $rule['source'];
|
126 |
|
|
if (!isset($nodes[$source_id])) {
|
127 |
|
|
$nodes[$source_id] = $new_entry;
|
128 |
|
|
}
|
129 |
|
|
$nodes[$cid]['in'][$source_id] = $source_id;
|
130 |
|
|
$nodes[$source_id]['out'][$cid] = $cid;
|
131 |
|
|
$source_component = $components[$source_id];
|
132 |
|
|
$source_pid = $source_component['pid'];
|
133 |
|
|
if ($source_pid) {
|
134 |
|
|
if (!isset($nodes[$source_pid])) {
|
135 |
|
|
$nodes[$source_pid] = $new_entry;
|
136 |
|
|
}
|
137 |
|
|
// The rule source is within a parent fieldset. Create a dependency on the parent.
|
138 |
|
|
$nodes[$source_pid]['out'][$source_id] = $source_id;
|
139 |
|
|
$nodes[$source_id]['in'][$source_pid] = $source_pid;
|
140 |
|
|
}
|
141 |
|
|
if ($source_component['page_num'] > $page_num) {
|
142 |
|
|
$errors[$page_num][] = t('A forward reference from page @from, %from to %to was found.',
|
143 |
|
|
array(
|
144 |
|
|
'%from' => $source_component['name'],
|
145 |
|
|
'@from' => $source_component['page_num'],
|
146 |
|
|
'%to' => $component['name'],
|
147 |
|
|
));
|
148 |
|
|
}
|
149 |
|
|
elseif ($source_component['page_num'] == $page_num && $component['type'] == 'pagebreak') {
|
150 |
|
|
$errors[$page_num][] = t('The page break %to can\'t be controlled by %from on the same page.',
|
151 |
|
|
array(
|
152 |
|
|
'%from' => $source_component['name'],
|
153 |
|
|
'%to' => $component['name'],
|
154 |
|
|
));
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
// Fetch the next component, if any.
|
162 |
|
|
$component = next($components);
|
163 |
|
|
|
164 |
|
|
// Finish any previous page already processed.
|
165 |
|
|
if (!$component || $component['page_num'] > $page_num) {
|
166 |
|
|
|
167 |
|
|
// Create a set of all components which have are not dependent upon anything.
|
168 |
|
|
// This list is known as S in the literature.
|
169 |
|
|
$start_nodes = array();
|
170 |
|
|
foreach ($nodes as $id => $n) {
|
171 |
|
|
if (!$n['in']) {
|
172 |
|
|
$start_nodes[] = $id;
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
// Process the start nodes, removing each one in turn from the queue.
|
177 |
|
|
while ($start_nodes) {
|
178 |
|
|
$id = array_shift($start_nodes);
|
179 |
|
|
// If the node represents an actual conditional, it can now be added
|
180 |
|
|
// to the end of the sorted order because anything it depends upon has
|
181 |
|
|
// already been calcuated.
|
182 |
|
|
if ($nodes[$id]['rgid']) {
|
183 |
|
|
foreach ($nodes[$id]['rgid'] as $rgid) {
|
184 |
|
|
$sorted[$page_num][] = array(
|
185 |
|
|
'cid' => $id,
|
186 |
|
|
'rgid' => $rgid,
|
187 |
|
|
'name' => $components[$id]['name'],
|
188 |
|
|
);
|
189 |
|
|
|
190 |
|
|
}
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
// Any other nodes that depend upon this node may now have their dependency
|
194 |
|
|
// on this node removed, since it has now been calculated.
|
195 |
|
|
foreach ($nodes[$id]['out'] as $out_id) {
|
196 |
|
|
unset($nodes[$out_id]['in'][$id]);
|
197 |
|
|
if (!$nodes[$out_id]['in']) {
|
198 |
|
|
$start_nodes[] = $out_id;
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
|
202 |
|
|
// All out-going dependencies have been handled.
|
203 |
|
|
$nodes[$id]['out'] = array();
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
// Check for a cyclic graph (circular dependency)
|
207 |
|
|
foreach ($nodes as $id => $n) {
|
208 |
|
|
if ($n['in'] || $n['out']) {
|
209 |
|
|
$errors[$page_num][] = t('A circular reference involving %name was found.',
|
210 |
|
|
array('%name' => $components[$id]['name']));
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
} // End finshing previous page
|
215 |
|
|
|
216 |
|
|
} // End component loop
|
217 |
|
|
|
218 |
|
|
// Create an empty page map for the preview page.
|
219 |
|
|
$page_map[$page_num + 1] = array();
|
220 |
|
|
|
221 |
|
|
$this->topologicalOrder = $sorted;
|
222 |
|
|
$this->errors = $errors;
|
223 |
|
|
$this->pageMap = $page_map;
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
/**
|
227 |
|
|
* Returns the (possibly cached) topological sort order.
|
228 |
|
|
*/
|
229 |
|
|
function getOrder() {
|
230 |
|
|
if (!$this->topologicalOrder) {
|
231 |
|
|
$this->topologicalSort();
|
232 |
|
|
}
|
233 |
|
|
return $this->topologicalOrder;
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
/**
|
237 |
|
|
* Returns an index of components by page number.
|
238 |
|
|
*/
|
239 |
|
|
function getPageMap() {
|
240 |
|
|
if (!$this->pageMap) {
|
241 |
|
|
$this->topologicalSort();
|
242 |
|
|
}
|
243 |
|
|
return $this->pageMap;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
/**
|
247 |
|
|
* Displays and error messages from the previously-generated sort order.
|
248 |
|
|
*
|
249 |
|
|
* User's who can't fix the webform are shown a single, simplified message.
|
250 |
|
|
*/
|
251 |
|
|
function reportErrors() {
|
252 |
|
|
$this->getOrder();
|
253 |
|
|
if ($this->errors) {
|
254 |
|
|
if (webform_node_update_access($this->node)) {
|
255 |
|
|
foreach ($this->errors as $page_num => $page_errors) {
|
256 |
|
|
drupal_set_message(format_plural(count($page_errors),
|
257 |
|
|
'Conditional error on page @num:',
|
258 |
|
|
'Conditional errors on page @num:',
|
259 |
|
|
array('@num' => $page_num)) .
|
260 |
|
|
'<br /><ul><li>' . implode('</li><li>', $page_errors) . '</li></ul>', 'warning');
|
261 |
|
|
}
|
262 |
|
|
}
|
263 |
|
|
else {
|
264 |
|
|
drupal_set_message(t('This form is improperly configured. Contact the administrator.'), 'warning');
|
265 |
|
|
}
|
266 |
|
|
}
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
/**
|
270 |
|
|
* Creates and caches a map of the children of a each component.
|
271 |
|
|
*
|
272 |
|
|
* Called after the component tree has been made and then flattened again.
|
273 |
|
|
* Alas, the children data is removed when the tree is flattened. The
|
274 |
|
|
* components are indexecd by cid but in tree order. Because cid's are
|
275 |
|
|
* numeric, they may not appear in IDE's or debuggers in their actual order.
|
276 |
|
|
*/
|
277 |
|
|
function getChildrenMap() {
|
278 |
|
|
if (!$this->childrenMap) {
|
279 |
|
|
$map = array();
|
280 |
|
|
foreach ($this->node->webform['components'] as $cid => $component) {
|
281 |
|
|
$pid = $component['pid'];
|
282 |
|
|
if ($pid) {
|
283 |
|
|
$map[$pid][] = $cid;
|
284 |
|
|
}
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
$this->childrenMap = $map;
|
288 |
|
|
}
|
289 |
|
|
return $this->childrenMap;
|
290 |
|
|
}
|
291 |
|
|
|
292 |
|
|
/**
|
293 |
|
|
* Deletes the value of the given component, plus any descendents.
|
294 |
|
|
*/
|
295 |
|
|
protected function deleteFamily(&$input_values, $parent_id, &$page_visiblity_page) {
|
296 |
|
|
if (isset($input_values[$parent_id])) {
|
297 |
|
|
$input_values[$parent_id] = NULL;
|
298 |
|
|
}
|
299 |
|
|
if (isset($this->childrenMap[$parent_id])) {
|
300 |
|
|
foreach ($this->childrenMap[$parent_id] as $child_id) {
|
301 |
|
|
$page_visiblity_page[$child_id] = $page_visiblity_page[$parent_id];
|
302 |
|
|
$this->deleteFamily($input_values, $child_id, $page_visiblity_page);
|
303 |
|
|
}
|
304 |
|
|
}
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
/**
|
308 |
|
|
* Executes the conditionals on a submission, removing any data which should
|
309 |
|
|
* be hidden.
|
310 |
|
|
*/
|
311 |
|
|
function executeConditionals($input_values, $page_num = 0) {
|
312 |
|
|
$this->getOrder();
|
313 |
|
|
$this->getChildrenMap();
|
314 |
|
|
if (!$this->visibilityMap || $page_num == 0) {
|
315 |
|
|
// Create a new visitibily map, with all components shown.
|
316 |
|
|
$this->visibilityMap = $this->pageMap;
|
317 |
|
|
array_walk_recursive($this->visibilityMap, function (&$status) {
|
318 |
|
|
$status = WebformConditionals::componentShown;
|
319 |
|
|
});
|
320 |
|
|
// Create empty required, set, and markup maps.
|
321 |
|
|
$this->requiredMap = array_fill(1, count($this->pageMap), array());
|
322 |
|
|
$this->setMap = $this->requiredMap;
|
323 |
|
|
$this->markupMap = $this->requiredMap;
|
324 |
|
|
|
325 |
01d522a6
|
Assos Assos
|
}
|
326 |
|
|
else {
|
327 |
a45e4bc1
|
Assos Assos
|
array_walk($this->visibilityMap[$page_num], function (&$status) {
|
328 |
|
|
$status = WebformConditionals::componentShown;
|
329 |
|
|
});
|
330 |
|
|
$this->requiredMap[$page_num] = array();
|
331 |
|
|
$this->setMap[$page_num] = array();
|
332 |
|
|
$this->markupMap[$page_num] = array();
|
333 |
|
|
}
|
334 |
|
|
|
335 |
|
|
module_load_include('inc', 'webform', 'includes/webform.conditionals');
|
336 |
|
|
|
337 |
|
|
$components = $this->node->webform['components'];
|
338 |
|
|
$conditionals = $this->node->webform['conditionals'];
|
339 |
|
|
$operators = webform_conditional_operators();
|
340 |
|
|
$targetLocked = array();
|
341 |
|
|
|
342 |
|
|
$first_page = $page_num ? $page_num : 1;
|
343 |
|
|
$last_page = $page_num ? $page_num : count($this->topologicalOrder);
|
344 |
|
|
for ($page = $first_page; $page <= $last_page; $page++) {
|
345 |
|
|
foreach ($this->topologicalOrder[$page] as $conditional_spec) {
|
346 |
|
|
|
347 |
|
|
$conditional = $conditionals[$conditional_spec['rgid']];
|
348 |
|
|
$conditional_result = TRUE;
|
349 |
|
|
$source_page_nums = array();
|
350 |
|
|
|
351 |
|
|
// Execute each comparison callback.
|
352 |
|
|
$conditional_results = array();
|
353 |
|
|
foreach ($conditional['rules'] as $rule) {
|
354 |
|
|
// TODO: Support other source types besides components?
|
355 |
|
|
if ($rule['source_type'] !== 'component') {
|
356 |
|
|
continue;
|
357 |
|
|
}
|
358 |
|
|
$source_component = $components[$rule['source']];
|
359 |
|
|
$source_cid = $source_component['cid'];
|
360 |
|
|
|
361 |
|
|
$source_values = array();
|
362 |
|
|
if (isset($input_values[$source_cid])) {
|
363 |
|
|
$component_value = $input_values[$source_cid];
|
364 |
|
|
// For select_or_other components, use only the select values because $source_values must not be a nested array.
|
365 |
|
|
// During preview, the array is already flattened.
|
366 |
|
|
if ($source_component['type'] === 'select' &&
|
367 |
|
|
!empty($source_component['extra']['other_option']) &&
|
368 |
|
|
isset($component_value['select'])) {
|
369 |
|
|
$component_value = $component_value['select'];
|
370 |
|
|
}
|
371 |
|
|
$source_values = is_array($component_value) ? $component_value : array($component_value);
|
372 |
|
|
}
|
373 |
|
|
|
374 |
|
|
// Determine the operator and callback.
|
375 |
|
|
$conditional_type = webform_component_property($source_component['type'], 'conditional_type');
|
376 |
|
|
$operator_info = $operators[$conditional_type];
|
377 |
|
|
|
378 |
|
|
// Perform the comparison callback and build the results for this group.
|
379 |
|
|
$comparison_callback = $operator_info[$rule['operator']]['comparison callback'];
|
380 |
|
|
// Contrib caching, such as entitycache, may have loaded the node
|
381 |
|
|
// without building it. It is possible that the component include file
|
382 |
|
|
// hasn't been included yet. See #2529246.
|
383 |
|
|
webform_component_include($source_component['type']);
|
384 |
|
|
$conditional_results[] = $comparison_callback($source_values, $rule['value'], $source_component);
|
385 |
|
|
|
386 |
|
|
// Record page number to later determine any intra-page dependency on this source.
|
387 |
|
|
$source_page_nums[$source_component['page_num']] = $source_component['page_num'];
|
388 |
|
|
}
|
389 |
|
|
|
390 |
|
|
// Calculate the and/or result.
|
391 |
|
|
$filtered_results = array_filter($conditional_results);
|
392 |
|
|
$conditional_result = $conditional['andor'] === 'or'
|
393 |
|
|
? count($filtered_results) > 0
|
394 |
|
|
: count($filtered_results) === count($conditional_results);
|
395 |
|
|
|
396 |
|
|
foreach ($conditional['actions'] as $action) {
|
397 |
|
|
$action_result = $action['invert'] ? !$conditional_result : $conditional_result;
|
398 |
|
|
$target = $action['target'];
|
399 |
|
|
$page_num = $components[$target]['page_num'];
|
400 |
|
|
switch ($action['action']) {
|
401 |
|
|
case 'show':
|
402 |
|
|
if (!$action_result) {
|
403 |
|
|
$this->visibilityMap[$page_num][$target] = in_array($page_num, $source_page_nums) ? self::componentDependent : self::componentHidden;
|
404 |
|
|
$this->deleteFamily($input_values, $target, $this->visibilityMap[$page_num]);
|
405 |
|
|
$targetLocked[$target] = TRUE;
|
406 |
|
|
}
|
407 |
|
|
break;
|
408 |
|
|
case 'require':
|
409 |
|
|
$this->requiredMap[$page_num][$target] = $action_result;
|
410 |
|
|
break;
|
411 |
|
|
case 'set':
|
412 |
|
|
if ($components[$target]['type'] == 'markup') {
|
413 |
|
|
$this->markupMap[$page_num][$target] = FALSE;
|
414 |
|
|
}
|
415 |
|
|
if ($action_result && empty($targetLocked[$target])) {
|
416 |
|
|
if ($components[$target]['type'] == 'markup') {
|
417 |
|
|
$this->markupMap[$page_num][$target] = $action['argument'];
|
418 |
01d522a6
|
Assos Assos
|
}
|
419 |
|
|
else {
|
420 |
a45e4bc1
|
Assos Assos
|
$input_values[$target] = isset($input_values[$target]) && is_array($input_values[$target])
|
421 |
|
|
? array($action['argument'])
|
422 |
|
|
: $action['argument'];
|
423 |
|
|
$this->setMap[$page_num][$target] = TRUE;
|
424 |
|
|
}
|
425 |
|
|
}
|
426 |
|
|
break;
|
427 |
|
|
}
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
|
431 |
|
|
} // End conditinal loop
|
432 |
|
|
} // End page loop
|
433 |
|
|
|
434 |
|
|
return $input_values;
|
435 |
|
|
}
|
436 |
|
|
|
437 |
01d522a6
|
Assos Assos
|
/**
|
438 |
|
|
* Returns whether the conditionals have been executed yet.
|
439 |
|
|
*/
|
440 |
|
|
function isExecuted() {
|
441 |
|
|
return (boolean)($this->visibilityMap);
|
442 |
|
|
}
|
443 |
|
|
|
444 |
a45e4bc1
|
Assos Assos
|
/**
|
445 |
|
|
* Returns whether a given component is always hidden, always shown, or might
|
446 |
|
|
* be shown depending upon other sources on the same page.
|
447 |
|
|
*
|
448 |
|
|
* Assumes that the conditionals have already been executed on the given page.
|
449 |
|
|
*
|
450 |
|
|
* @param integer $cid
|
451 |
|
|
* The component id of the component whose visibilty is being sought.
|
452 |
|
|
* @param integer $page_num
|
453 |
|
|
* The page number that the component is on.
|
454 |
|
|
* @return integer
|
455 |
|
|
* self::componentHidden, ...Shown, or ...Dependent.
|
456 |
|
|
*/
|
457 |
|
|
function componentVisibility($cid, $page_num) {
|
458 |
|
|
if (!$this->visibilityMap) {
|
459 |
|
|
// The conditionals have not yet been executed on a submission.
|
460 |
|
|
$this->executeConditionals(array(), 0);
|
461 |
01d522a6
|
Assos Assos
|
watchdog('webform', 'WebformConditionals::componentVisibility called prior to evaluating a submission.', array(), WATCHDOG_ERROR);
|
462 |
a45e4bc1
|
Assos Assos
|
}
|
463 |
|
|
return isset($this->visibilityMap[$page_num][$cid]) ? $this->visibilityMap[$page_num][$cid] : self::componentShown;
|
464 |
|
|
}
|
465 |
|
|
|
466 |
|
|
/**
|
467 |
|
|
* Returns whether a given page should be displayed. This requires any
|
468 |
|
|
* conditional for the page itself to be shown, plus at least one component
|
469 |
|
|
* within the page must be shown too. The first and preview pages are always
|
470 |
|
|
* shown, however.
|
471 |
|
|
*
|
472 |
|
|
* @param integer $page_num
|
473 |
|
|
* The page number that the component is on.
|
474 |
|
|
* @return integer
|
475 |
|
|
* self::componentHidden or ...Shown.
|
476 |
|
|
*/
|
477 |
|
|
function pageVisibility($page_num) {
|
478 |
|
|
$result = self::componentHidden;
|
479 |
|
|
if ($page_num == 1 || empty($this->visibilityMap[$page_num])) {
|
480 |
|
|
$result = self::componentShown;
|
481 |
01d522a6
|
Assos Assos
|
}
|
482 |
|
|
elseif (($page_map = $this->pageMap[$page_num]) && $this->componentVisibility(reset($page_map), $page_num)) {
|
483 |
a45e4bc1
|
Assos Assos
|
while ($cid = next($page_map)) {
|
484 |
|
|
if ($this->componentVisibility($cid, $page_num) != self::componentHidden) {
|
485 |
|
|
$result = self::componentShown;
|
486 |
|
|
break;
|
487 |
|
|
}
|
488 |
|
|
}
|
489 |
|
|
}
|
490 |
|
|
return $result;
|
491 |
|
|
}
|
492 |
|
|
|
493 |
|
|
/**
|
494 |
|
|
* Returns whether a given component is always required, always optional, or
|
495 |
|
|
* unchanged by conditional logic.
|
496 |
|
|
*
|
497 |
|
|
* Assumes that the conditionals have already been executed on the given page.
|
498 |
|
|
*
|
499 |
|
|
* @param integer $cid
|
500 |
|
|
* The component id of the component whose required state is being sought.
|
501 |
|
|
* @param integer $page_num
|
502 |
|
|
* The page number that the component is on.
|
503 |
|
|
* @return boolean
|
504 |
|
|
* Whether the component is required based on conditionals.
|
505 |
|
|
*/
|
506 |
|
|
function componentRequired($cid, $page_num) {
|
507 |
|
|
if (!$this->requiredMap) {
|
508 |
|
|
// The conditionals have not yet been executed on a submission.
|
509 |
|
|
$this->executeConditionals(array(), 0);
|
510 |
01d522a6
|
Assos Assos
|
watchdog('webform', 'WebformConditionals::componentRequired called prior to evaluating a submission.', array(), WATCHDOG_ERROR);
|
511 |
a45e4bc1
|
Assos Assos
|
}
|
512 |
|
|
return isset($this->requiredMap[$page_num][$cid]) ? $this->requiredMap[$page_num][$cid] : NULL;
|
513 |
|
|
}
|
514 |
|
|
|
515 |
|
|
/**
|
516 |
|
|
* Returns whether a given component has been set by conditional logic.
|
517 |
|
|
*
|
518 |
|
|
* Assumes that the conditionals have already been executed on the given page.
|
519 |
|
|
*
|
520 |
|
|
* @param integer $cid
|
521 |
|
|
* The component id of the component whose set state is being sought.
|
522 |
|
|
* @param integer $page_num
|
523 |
|
|
* The page number that the component is on.
|
524 |
|
|
* @return boolean
|
525 |
|
|
* Whether the component was set based on conditionals.
|
526 |
|
|
*/
|
527 |
|
|
function componentSet($cid, $page_num) {
|
528 |
|
|
if (!$this->setMap) {
|
529 |
|
|
// The conditionals have not yet been executed on a submission.
|
530 |
|
|
$this->executeConditionals(array(), 0);
|
531 |
01d522a6
|
Assos Assos
|
watchdog('webform', 'WebformConditionals::componentSet called prior to evaluating a submission.', array(), WATCHDOG_ERROR);
|
532 |
a45e4bc1
|
Assos Assos
|
}
|
533 |
|
|
return isset($this->setMap[$page_num][$cid]) ? $this->setMap[$page_num][$cid] : NULL;
|
534 |
|
|
}
|
535 |
|
|
|
536 |
|
|
/**
|
537 |
|
|
* Returns the calculated markup as set by conditional logic.
|
538 |
|
|
*
|
539 |
|
|
* Assumes that the conditionals have already been executed on the given page.
|
540 |
|
|
*
|
541 |
|
|
* @param integer $cid
|
542 |
|
|
* The component id of the component whose set state is being sought.
|
543 |
|
|
* @param integer $page_num
|
544 |
|
|
* The page number that the component is on.
|
545 |
|
|
* @return string
|
546 |
|
|
* The conditional markup, or NULL if none.
|
547 |
|
|
*/
|
548 |
|
|
function componentMarkup($cid, $page_num) {
|
549 |
|
|
if (!$this->markupMap) {
|
550 |
|
|
// The conditionals have not yet been executed on a submission.
|
551 |
|
|
$this->executeConditionals(array(), 0);
|
552 |
01d522a6
|
Assos Assos
|
watchdog('webform', 'WebformConditionals::componentMarkup called prior to evaluating a submission.', array(), WATCHDOG_ERROR);
|
553 |
a45e4bc1
|
Assos Assos
|
}
|
554 |
|
|
return isset($this->markupMap[$page_num][$cid]) ? $this->markupMap[$page_num][$cid] : NULL;
|
555 |
|
|
}
|
556 |
|
|
|
557 |
|
|
} |