public function addOverrideJoin(\SelectQueryInterface $query, $base_alias, $base_id, $overrides_alias, $type) { $alias = $query->addJoin("LEFT OUTER", 'test_override', $overrides_alias, "{$base_alias}.{$base_id} = {$overrides_alias}.id"); $tables =& $query->getTables(); $new_tables = array(); $found_base = FALSE; foreach ($tables as $key => $table) { if ($table['alias'] == $base_alias) { $new_tables[$key] = $table; $new_tables[$alias] = $tables[$alias]; } else { if ($key == $alias) { } else { $new_tables[$key] = $table; } } } $tables = $new_tables; return $alias; }
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 entityFieldQueryAlter(SelectQueryInterface $query) { // The Taxonomy module doesn't implement any proper taxonomy term access, // and as a consequence doesn't make sure that taxonomy terms cannot be viewed // when the user doesn't have access to the vocabulary. $tables = $query->getTables(); $base_table = key($tables); $vocabulary_alias = $query->innerJoin('taxonomy_vocabulary', 'n', '%alias.vid = ' . $base_table . '.vid'); $query->addMetadata('base_table', $vocabulary_alias); // Pass the query to the taxonomy access control. $this->reAlterQuery($query, 'taxonomy_vocabulary_access', $vocabulary_alias); // Also, the taxonomy term entity exposes a bundle, but doesn't have a bundle // column in the database. We have to alter the query ourself to go fetch // the bundle. $conditions =& $query->conditions(); foreach ($conditions as $key => &$condition) { if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'vocabulary_machine_name') { $condition['field'] = $vocabulary_alias . '.machine_name'; break; } } }
/** * Check a query for tables that match our entities tables * and return the alais for everyone that was found * * @param $query \SelectQueryInterface * a SelectQuery is expected * * @return array * an array whose keys are table names and values are alias */ protected function extractAlias(\SelectQueryInterface $query) { $tables = $query->getTables(); $aliases = array(); foreach ($tables as $alias => $table) { foreach ($this->entities as $entity) { if ($table['table'] == $entity['base_table']) { $aliases[$entity['base_table']] = $alias; } if ($table['table'] == $entity['revision_table']) { $aliases[$entity['revision_table']] = $alias; } } } return $aliases; }
public function &getTables() { return $this->query->getTables(); }