View source
<?php
$plugin = array(
'title' => t('Addition'),
'description' => t('Add 2 values.'),
'sign' => '+',
'transparent operand1' => 0,
'transparent operand2' => 0,
'precedence' => 1,
'dimension check' => TRUE,
'evaluate callback' => 'units_operator_add_evaluate',
'dimension callback' => 'units_operator_add_dimension',
'split quantity callback' => 'units_operator_add_split_quantity',
'isolate operand callback' => 'units_operator_add_isolate_operand',
'sql evaluate fragment' => 'SET result = token1 + token2;',
'operator class' => 'UnitsMathematicalOperatorLinear',
);
function units_operator_add_evaluate($operand1, $operand2) {
return $operand1 + $operand2;
}
function units_operator_add_dimension($dimension1, $dimension2, $operator1, $operator2) {
return $dimension1;
}
function units_operator_add_split_quantity($total_quantity, $quantity1, $quantity2, $plugin) {
$greatest_quantity = max($quantity1, $quantity2);
$for_greater_quantity = floor($total_quantity / $greatest_quantity) * $greatest_quantity;
$for_fewer_quantity = $total_quantity - $for_greater_quantity;
return $quantity1 > $quantity2 ? array(
$for_greater_quantity,
$for_fewer_quantity,
) : array(
$for_fewer_quantity,
$for_greater_quantity,
);
}
function units_operator_add_isolate_operand(UnitsMathematicalExpression $operand1, UnitsMathematicalExpression $operand2, UnitsMathematicalExpression $equal_operand, $operand_to_isolate) {
if ($operand_to_isolate == 1) {
$operand_to_keep = $operand2;
}
else {
$operand_to_keep = $operand1;
}
return units_mathematical_expression_operator_construct(units_get_operator('subtract'), $equal_operand, $operand_to_keep);
}