You are here

function merci_rro_determine_best_value in MERCI (Manage Equipment Reservations, Checkout and Inventory) 6

1 call to merci_rro_determine_best_value()
merci_rro_merci_rules_alter in modules/merci_rro/merci_rro.module
Implementation of hook_merci_rules_alter().

File

modules/merci_rro/merci_rro.module, line 182
Hooks and utility functions for MERCI Role Rule Override

Code

function merci_rro_determine_best_value($rule_type, $a, $b) {
  switch ($rule_type) {

    // Max value is best
    case 'allow_overnight':
    case 'allow_weekends':
    case 'fee_free_hours':
      return $a > $b ? $a : $b;

    // Minimum value is best
    case 'min_cancel_hours':
    case 'rate_per_hour':
    case 'late_fee_per_hour':
      return $a < $b ? $a : $b;

    // Longest hours is best
    case 'hours_mon':
    case 'hours_tue':
    case 'hours_wed':
    case 'hours_thu':
    case 'hours_fri':
    case 'hours_sat':
    case 'hours_sun':
      $a_parts = merci_hours_str_to_array($a);
      if (!$a_parts) {
        return $b;
      }
      $b_parts = merci_hours_str_to_array($b);
      if ($a_parts['open'] > $b_parts['open']) {
        return $b;
      }
      if ($a_parts['close'] < $b_parts['close']) {
        return $b;
      }
      return $a;

    // Other
    case 'max_hours_per_reservation':
      if ($a == 0) {
        return $a;
      }
      if ($b == 0) {
        return $b;
      }
      return $b > $a ? $b : $a;
    default:
      return $a;
  }

  // switch
}