You are here

function ca_conditions_form_update_conditions in Ubercart 6.2

Update a predicate's conditions based on the values from a conditions form.

Parameters

$pid: The ID of the predicate whose conditions should be updated.

$data: The conditions values from the form state that should be used to update the predicate; normally $form_state['values']['conditions'].

Return value

An array representing the full, updated predicate.

5 calls to ca_conditions_form_update_conditions()
ca_conditions_form_add_condition_group_submit in ca/ca.admin.inc
Submit handler for button to add a condition group.
ca_conditions_form_add_condition_submit in ca/ca.admin.inc
Submit handler for button to add a condition to a condition group.
ca_conditions_form_remove_condition_group_submit in ca/ca.admin.inc
Submit handler for button to remove a condition grou.
ca_conditions_form_remove_condition_submit in ca/ca.admin.inc
Submit handler for button to remove a condition from a condition group.
ca_conditions_form_save_changes_submit in ca/ca.admin.inc
Save changes submit handler for the conditions form.

File

ca/ca.admin.inc, line 1009
Conditional actions overview UI.

Code

function ca_conditions_form_update_conditions($pid, $data) {

  // Build the new conditions array from scratch.
  $conditions = ca_new_conditions();

  // Override the top level operator if need be.
  if (isset($data['operator'])) {
    $conditions['#operator'] = $data['operator'];
  }

  // Use a variable to track the group array key so we can "reset" the keys.
  $group = 0;

  // Loop through each second level condition group.
  foreach ($data['conditions'] as $key => $value) {

    // Save the operator setting.
    $conditions['#conditions'][$group]['#operator'] = $value['operator'];
    $conditions['#conditions'][$group]['#conditions'] = array();

    // If conditions exist...
    if (is_array($value['conditions']) && count($value['conditions']) > 0) {

      // Use a variable to track the condition array key as for groups.
      $condition = 0;

      // Loop through the conditions in this group.
      foreach ($value['conditions'] as $cond_key => $cond_value) {

        // Save the condition's settings.
        $conditions['#conditions'][$group]['#conditions'][$condition] = array(
          '#name' => $cond_value['name'],
          '#title' => $cond_value['title'],
          '#argument_map' => $cond_value['argument_map'],
          '#settings' => $cond_value['settings'],
        );
        $condition++;
      }
    }
    $group++;
  }

  // Load the predicate as it is now.
  $predicate = ca_load_predicate($pid);

  // Update the actions and save the result.
  $predicate['#conditions'] = $conditions;
  ca_save_predicate($predicate);
  return $predicate;
}