function rules_action_data_calc
Action: Calculate a value.
Related topics
1 string reference to 'rules_action_data_calc'
- rules_data_action_info in modules/
data.rules.inc - Implements hook_rules_action_info() on behalf of the pseudo data module.
File
-
modules/
data.eval.inc, line 57
Code
function rules_action_data_calc($input1, $op, $input2, $settings, $state, $element) {
$info = $element->pluginParameterInfo();
// Make sure to apply date offsets intelligently.
if ($info['input_1']['type'] == 'date' && $info['input_2']['type'] == 'duration') {
$input2 = $op == '-' ? $input2 * -1 : $input2;
return array(
'result' => (int) RulesDateOffsetProcessor::applyOffset($input1, $input2),
);
}
switch ($op) {
case '+':
$result = $input1 + $input2;
break;
case '-':
$result = $input1 - $input2;
break;
case '*':
$result = $input1 * $input2;
break;
case '/':
$result = $input1 / $input2;
break;
case 'min':
$result = min($input1, $input2);
break;
case 'max':
$result = max($input1, $input2);
break;
}
if (isset($result)) {
// Ensure results are valid integer values if necessary.
$variables = $element->providesVariables();
$var_info = reset($variables);
if ($var_info['type'] == 'integer') {
$result = (int) $result;
}
return array(
'result' => $result,
);
}
}