function commerce_registration_registration_count_comparison in Commerce Registration 7.3
Condition callback. Compare the total number of registrations on the line item.
Related topics
File
- ./
commerce_registration.rules.inc, line 188 - Commerce Registration rules file.
Code
function commerce_registration_registration_count_comparison($line_item, $operator, $amount) {
$line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
$registrations = $line_item_wrapper->registrations
->value();
if (!is_array($registrations)) {
return FALSE;
}
$total = 0;
// Get the total registration count. There is at most a depth of 2.
foreach ($registrations as $registration) {
if (is_array($registration)) {
$total += count($registration);
}
else {
$total++;
}
}
switch ($operator) {
case '=':
return $total == $amount;
case '>=':
return $total >= $amount;
case '>':
return $total > $amount;
case '<':
return $total < $amount;
case '<=':
return $total <= $amount;
case '!=':
return $total != $amount;
}
return FALSE;
}