/** * Overrides OgSelectionHandler::entityFieldQueryAlter(). * * Add the user's groups along with the rest of the "public" groups. */ public function entityFieldQueryAlter(SelectQueryInterface $query) { $gids = og_get_entity_groups(); if (empty($gids['node'])) { return; } $conditions =& $query->conditions(); // Find the condition for the "field_data_field_privacy_settings" query, and // the one for the "node.nid", so we can later db_or() them. $public_condition = array(); foreach ($conditions as $key => $condition) { if ($key !== '#conjunction' && is_string($condition['field'])) { if (strpos($condition['field'], 'field_data_field_og_subscribe_settings') === 0) { $public_condition = $condition; unset($conditions[$key]); } if ($condition['field'] === 'node.nid') { unset($conditions[$key]); } } } if (!$public_condition) { return; } $or = db_or(); $or->condition($public_condition['field'], $public_condition['value'], $public_condition['operator']); $or->condition('node.nid', $gids['node'], 'IN'); $query->condition($or); }
public function entityFieldQueryAlter(SelectQueryInterface $query) { if (user_access('administer users')) { // In addition, if the user is administrator, we need to make sure to // match the anonymous user, that doesn't actually have a name in the // database. $conditions =& $query->conditions(); foreach ($conditions as $key => $condition) { if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'users.name') { // Remove the condition. unset($conditions[$key]); // Re-add the condition and a condition on uid = 0 so that we end up // with a query in the form: // WHERE (name LIKE :name) OR (:anonymous_name LIKE :name AND uid = 0) $or = db_or(); $or->condition($condition['field'], $condition['value'], $condition['operator']); // Sadly, the Database layer doesn't allow us to build a condition // in the form ':placeholder = :placeholder2', because the 'field' // part of a condition is always escaped. // As a (cheap) workaround, we separately build a condition with no // field, and concatenate the field and the condition separately. $value_part = db_and(); $value_part->condition('anonymous_name', $condition['value'], $condition['operator']); $value_part->compile(Database::getConnection(), $query); $or->condition(db_and()->where(str_replace('anonymous_name', ':anonymous_name', (string) $value_part), $value_part->arguments() + array(':anonymous_name' => format_username(user_load(0))))->condition('users.uid', 0)); $query->condition($or); } } } }
public function &conditions() { return $this->query->conditions(); }