You are here

function ca_load_trigger_predicates in Ubercart 6.2

Load predicates based on the specified parameters.

Parameters

$trigger: The name of the trigger for which to search when loading the predicates.

$all: FALSE by default, specifies whether we want to load all possible predicates or only those that are active (status > 0).

Return value

An array of predicates.

6 calls to ca_load_trigger_predicates()
ca_pull_trigger in ca/ca.module
Pull a trigger and evaluate any predicates associated with that trigger.
hook_calculate_tax in docs/hooks.php
Calculates tax line items for an order.
uc_checkout_pane_quotes in shipping/uc_quote/uc_quote.module
Shipping quote checkout pane callback.
uc_order_pane_quotes in shipping/uc_quote/uc_quote.module
Shipping quote order pane callback.
uc_taxes_calculate_tax in uc_taxes/uc_taxes.module
Calculates the amount and types of taxes that apply to an order.

... See full list

File

ca/ca.module, line 253
This is a demonstration module for the new conditional actions API.

Code

function ca_load_trigger_predicates($trigger, $all = FALSE) {

  // Load all the module defined predicates.
  $predicates = module_invoke_all('ca_predicate');
  drupal_alter('ca_predicate', $predicates);

  // Loop through the module defined predicates to prepare the data - unsets
  // inactive predicates if $all == FALSE and adds a default weight if need be.
  foreach ($predicates as $key => $value) {

    // Unset the predicate if it doesn't use the specified trigger.
    if ($value['#trigger'] != $trigger) {
      unset($predicates[$key]);
      continue;
    }
    if (!$all && $value['#status'] <= 0) {
      unset($predicates[$key]);
    }
    elseif (!isset($value['#weight'])) {
      $predicates[$key]['#weight'] = 0;
    }
  }

  // Load and loop through the predicates from the database for this trigger.
  $result = db_query("SELECT * FROM {ca_predicates} WHERE ca_trigger = '%s'", $trigger);
  while ($data = db_fetch_array($result)) {

    // Module defined predicates have string IDs.  When a user modifies one of
    // these, we unset the module defined predicate and reconsider adding it in.
    if (!is_numeric($data['pid'])) {
      unset($predicates[$data['pid']]);
    }

    // Add predicates from the database to our return array if $all == TRUE or
    // if the predicate is active.
    if ($all || $data['status'] > 0) {
      $predicate = ca_prepare_db_predicate($data);

      // Set the actions' weight if necessary and sort actions by their weight.
      for ($i = 0; $i < count($predicate['#actions']); $i++) {
        if (!isset($predicate['#actions'][$i]['#weight'])) {
          $predicate['#actions'][$i]['#weight'] = 0;
        }
      }
      usort($predicate['#actions'], 'ca_weight_sort');
      $predicates[$data['pid']] = $predicate;
    }
  }
  uasort($predicates, 'ca_weight_sort');
  return $predicates;
}