protected function RedhenContactEntityController::buildQuery in RedHen CRM 7
Override buildQuery to add a join for the active Drupal user.
Overrides EntityAPIController::buildQuery
File
- modules/
redhen_contact/ lib/ redhen_contact.controller.inc, line 117 - The controller for the contact entity containing the CRUD operations.
Class
- RedhenContactEntityController
- The controller class for contacts.
Code
protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
$query = parent::buildQuery($ids, $conditions, $revision_id);
$query
->leftJoin('redhen_contact_user', 'rcu', 'rcu.contact_id = base.contact_id AND rcu.status = :status', array(
':status' => 1,
));
// If uid is a condition, ensure the join is against the right table.
if (isset($conditions['uid'])) {
$query_conditions =& $query
->conditions();
foreach ($query_conditions as $key => $condition) {
if (isset($condition['field']) && $condition['field'] == 'base.uid') {
$query_conditions[$key]['field'] = 'rcu.uid';
}
}
}
$query
->fields('rcu', array(
'uid',
));
return $query;
}