You are here

function hook_party_acquisition_query_alter in Party 7

Alter the match query being used for party acquisitions.

Some callers may specify a name context, in which case you can hook use the name specific hook, hook_party_acquisition_NAME_query_alter().

Implementers MUST NOT add additional fields or cause duplicate rows.

This function should be put in mymodule.party_acquisition.inc and will be automatically include when required.

Parameters

$query: A SelectQuery or extender with the match conditions already prepared.

array $context: An array of contextual information from the caller and the acquisition class. Values should be checked for their existence before being used.

2 functions implement hook_party_acquisition_query_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

party_hat_party_acquisition_query_alter in modules/party_hat/party_hat.party_acquisition.inc
Implements hook_party_acquisition_query_alter().
party_user_party_acquisition_query_alter in modules/party_user/party_user.party_acquisition.inc
Implements hook_party_acquisition_query_alter().

File

./party.api.php, line 416
Hooks provided by the Party module.

Code

function hook_party_acquisition_query_alter(&$query, array &$context) {

  // Example from party_hat_party_acquisition_query_alter().
  if (!empty($context['party_hat']['filter'])) {

    // Get our operator and set up our join variables.
    $operator = isset($context['party_hat']['filter_operator']) ? $context['party_hat']['filter_operator'] : 'OR';
    $type = $operator == 'AND' ? 'INNER' : 'LEFT OUTER';
    $table = 'field_data_party_hat';
    $condition = '%alias.entity_type = :entity_type AND %alias.entity_id = party.pid AND %alias.party_hat_hat_name = :hat_name';

    // If no
    if ($operator != 'AND') {
      $or = db_or();
    }

    // Add our joins. To avoid duplicates, we need one per hat. If our
    // operator is 'AND' we'll use inner joins. Otherwise we'll use left joins
    // and set up a condition for each in $or.
    foreach ($context['party_hat']['filter'] as $hat_name) {

      // Unfortunately PartyQuery can't do these non-duplicated joins yet...
      $alias = 'party_hat_' . $hat_name;
      $arguments = array(
        ':entity_type' => 'party',
        ':hat_name' => $hat_name,
      );
      $alias = $query
        ->addJoin($type, $table, $alias, $condition, $arguments);
      if ($operator != 'AND') {
        $or
          ->isNotNull("{$alias}.entity_id");
      }
    }

    // Add our condition to the query.
    if ($operator != 'AND') {
      $query
        ->condition($or);
    }
  }
}