You are here

function WebformCalculationComponentsFormTree::getOperationData in Webform Calculation Components 7

Same name and namespace in other branches
  1. 7.2 WebformCalculationComponentsFormTree.php \WebformCalculationComponentsFormTree::getOperationData()

Builds up an array with the necessary data of the calculation elements.

This helper function buid up an array to store the necessary data to select the elements involved in the calculation.

Since the selectors for calculating the result via AJAX can have different paths because they are located under different parent fieldsets, we need to create the selector based on the corresponding tree path of the component. Examples of those components are the operand fields and the result field.

Parameters

array $components: The array of components in a tree shape taken from the webform node form array.

string $wb_calc_component_cid: The cid (Component Id) of the calculation component where the operands, operation, result fields etc. is stored.

Return value

array It returns the an array that contains the operand and result fields selectors (in an tree path array) and the operation to perform.

File

./WebformCalculationComponentsFormTree.php, line 134
Handles the arrays passed in the webform node.

Class

WebformCalculationComponentsFormTree
@file Handles the arrays passed in the webform node.

Code

function getOperationData(array $components, $wb_calc_component_cid) {

  // Calculation Operation Component array
  $calc_op_comp = array();
  if ($components[$wb_calc_component_cid]['type'] == 'wb_calc_number') {
    $calc_op_comp['operand_field_path'] = $this
      ->buildTreePath($components, array(
      $components[$wb_calc_component_cid]['form_key'],
    ), $components[$wb_calc_component_cid]['pid']);
  }
  if ($components[$wb_calc_component_cid]['type'] == 'wb_calc_hidden') {
    foreach ($components[$wb_calc_component_cid]['extra']['operand_field'] as $operand_field) {
      $calc_op_comp['operand_field_paths'][] = $this
        ->buildTreePath($components, array(
        $operand_field,
      ), $this
        ->getPid($components, $operand_field));
    }
    $select_field_pid = $this
      ->getPid($components, $components[$wb_calc_component_cid]['extra']['select_field']);
    $calc_op_comp['select_field_path'] = $this
      ->buildTreePath($components, array(
      $components[$wb_calc_component_cid]['extra']['select_field'],
    ), $select_field_pid);
    $calc_op_comp['cumulative_result'] = $components[$wb_calc_component_cid]['extra']['cumulative_result'];
  }
  $calc_op_comp['operation_type'] = $components[$wb_calc_component_cid]['extra']['operation_type'];
  $result_field_pid = $this
    ->getPid($components, $components[$wb_calc_component_cid]['extra']['result_field']);
  $calc_op_comp['result_field_path'] = $this
    ->buildTreePath($components, array(
    $components[$wb_calc_component_cid]['extra']['result_field'],
  ), $result_field_pid);
  return $calc_op_comp;
}