You are here

function _webform_conditional_find_end in Webform 7.4

Helper. Find the matching end of a given subconditional.

Parameters

array $rules: Array of conditional rules to be searched.

int $origin_rid: The starting rule id for the search.

int $target_delta_level: The level that is sought. 0 for current left. -1 for parent.

Return value

int The rid of the found rule, or -1 if none. Note that NULL is not used as a semaphore for "not found" because it casts to 0, which is a valid rule id.

File

includes/webform.conditionals.inc, line 680
Form elements and menu callbacks to provide conditional handling in Webform.

Code

function _webform_conditional_find_end(array $rules, $origin_rid, $target_delta_level = 0) {
  $rids = array_keys($rules);
  $offset = array_search($origin_rid, $rids);
  $delta_level = 0;
  foreach (array_slice($rules, $offset, NULL, TRUE) as $rid => $conditional) {
    switch ($conditional['source_type']) {
      case 'conditional_start':
        $delta_level++;
        break;
      case 'conditional_end':
        $delta_level--;
        break;
    }
    if ($delta_level == $target_delta_level) {
      return $rid;
    }
  }

  // Mis-matched conditional_start / _end. Return -1.
  return -1;
}