/** * 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); }
/** * Preprocesses a search's database query before it is executed. * * @param SelectQueryInterface $db_query * The database query to be executed for the search. Will have "item_id" and * "score" columns in its result. * @param SearchApiQueryInterface $query * The search query that is being executed. * * @see SearchApiDbService::preQuery() */ function hook_search_api_db_query_alter(SelectQueryInterface &$db_query, SearchApiQueryInterface $query) { // If the option was set on the query, add additional SQL conditions. if ($custom = $query->getOption('custom_sql_conditions')) { foreach ($custom as $condition) { $db_query->condition($condition['field'], $condition['value'], $condition['operator']); } } }
public function entityFieldQueryAlter(SelectQueryInterface $query) { // Core forces us to know about 'permanent' vs. 'temporary' files. $tables = $query->getTables(); $base_table = key($tables); $query->condition('status', FILE_STATUS_PERMANENT); // Access control to files is a very difficult business. For now, we are not // going to give it a shot. // @todo: fix this when core access control is less insane. return $query; }
public function havingCondition($field, $value = NULL, $operator = '=') { $this->query->condition($field, $value, $operator, $num_args); return $this; }
/** * Apply the operator onto the query * * @param \SelectQueryInterface $query * @param string $statement * @param string $value */ protected final function applyOperator(\SelectQueryInterface $query, $statement, $value) { // Check if $value contains an operator (i.e. if is associative array) if (is_array($value) && !Misc::isIndexed($value)) { // First key will be the operator $keys = array_keys($value); $operator = $keys[0]; $value = $value[$operator]; switch ($operator) { case '<>': if (is_array($value)) { $query->condition($statement, $value, 'NOT IN'); } else { $query->condition($statement, $value, '<>'); } break; case 'exists': $query->exists($value); break; case 'in': $query->condition($statement, $value, 'IN'); break; default: $query->condition($statement, $value, $operator); break; } } else { if (null === $value) { $query->isNull($statement); } else { $query->condition($statement, $value); } } }