You are here

function party_user_party_acquisition_query_alter in Party 7

Implements hook_party_acquisition_query_alter().

Allow callers to indicate special user related behavior:

  • $context['party_user']['has_user']: TRUE or FALSE to filter on whether the party has a user. NULL will not affect behaviour.
  • $context['party_user']['values']: Optional array of values to filter on the user table.
  • $context['party_user']['values_operator']: 'AND' or 'OR' to indicate what operator to use for the above values. Defaults to 'AND'.

File

modules/party_user/party_user.party_acquisition.inc, line 43

Code

function party_user_party_acquisition_query_alter(&$query, array &$context) {
  if (isset($context['party_user']['has_user']) || !empty($context['party_user']['values'])) {

    // Add our join to the user table, assume delta 0. PartyQuery can't handle
    // this without selecting other rows as well.
    $pae_alias = $query
      ->leftJoin('party_attached_entity', 'pae_user', '%alias.pid = party.pid AND %alias.data_set = :user AND %alias.delta = :delta', array(
      ':user' => 'user',
      ':delta' => 0,
    ));
    $alias = $query
      ->leftJoin('users', 'user', "%alias.uid = {$pae_alias}.eid");
    if (isset($context['party_user']['has_user'])) {
      if ($context['party_user']['has_user']) {
        $query
          ->isNotNull("{$alias}.uid");
      }
      else {
        $query
          ->isNull("{$alias}.uid");
      }
    }
    if (!empty($context['party_user']['values'])) {

      // Add our matching conditions.
      $match = isset($context['party_user']['values_operator']) && $context['party_user']['values_operator'] == 'OR' ? db_or() : db_and();
      foreach ($context['party_user']['values'] as $property => $value) {
        $match
          ->condition("{$alias}.{$property}", $value);
      }
      $query
        ->condition($match);
    }
  }
}