View source
<?php
$plugin = array(
'title' => t('Multiply'),
'description' => t('Multiply 2 values.'),
'sign' => '*',
'transparent operand1' => 1,
'transparent operand2' => 1,
'precedence' => 2,
'dimension check' => FALSE,
'evaluate callback' => 'units_operator_multiply_evaluate',
'dimension callback' => 'units_operator_multiply_dimension',
'split quantity callback' => 'units_operator_multiply_split_quantity',
'isolate operand callback' => 'units_operator_multiply_isolate_operand',
'sql evaluate fragment' => 'SET result = token1 * token2;',
'operator class' => 'UnitsMathematicalOperatorLinear',
);
function units_operator_multiply_evaluate($operand1, $operand2) {
return $operand1 * $operand2;
}
function units_operator_multiply_dimension($dimension1, $dimension2, $operator1, $operator2) {
return units_dimension_add($dimension1, $dimension2);
}
function units_operator_multiply_split_quantity($total_quantity, $quantity1, $quantity2, $plugin) {
return array(
$total_quantity,
$plugin['transparent operand2'],
);
}
function units_operator_multiply_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('divide'), $equal_operand, $operand_to_keep);
}