/** * Overrides \RestfulDataProviderDbQuery::getQuery(). * * Join with the terms table. */ protected function getQuery() { $query = parent::getQuery(); // Add a node access tag. $query->addTag('node_access'); $query->innerJoin('users', 'user', 'node.uid = user.uid'); // Explicitly set the alias of the column, so it will match the public field // name. $query->addField('user', 'name', 'name'); return $query; }
/** * {@inheritdoc} */ public function getQuery() { $query = parent::getQuery(); // Add a query for meter_category. $field = field_info_field('field_group_node'); $table_name = _field_sql_storage_tablename($field); $request = $this->getRequest(); $query->leftJoin($table_name, 'gn', "message.mid = gn.entity_id AND gn.entity_type='message'"); $query->innerJoin('field_data_field_node', 'fn', "message.mid = fn.entity_id AND fn.entity_type='message'"); $query->innerJoin('node', 'node', "fn.field_node_target_id = node.nid"); // Show only publish content in active stream. $query->condition('node.status', 1); if (!empty($request['topics'])) { // Join related to Articles tables to get V&V activities with user's // topics of interest. $query->innerJoin('field_data_c4m_vocab_topic', 'crt', "node.nid = crt.entity_id AND crt.entity_type='node'"); } $query->addField('gn', 'field_group_node_target_id', 'group_node'); if (!empty($request['group'])) { if (empty($request['hide_articles'])) { $or = db_or(); $or->condition('gn.field_group_node_target_id', $request['group'], is_array($request['group']) ? 'IN' : '='); if (!empty($request['topics'])) { $and = db_and(); $and->isNull('gn.field_group_node_target_id'); $and->condition('node.type', 'article'); $and->condition('crt.c4m_vocab_topic_tid', $request['topics'], is_array($request['topics']) ? 'IN' : '='); $or->condition($and); } else { $or->isNull('gn.field_group_node_target_id'); } $query->condition($or); } else { $query->condition('gn.field_group_node_target_id', $request['group'], is_array($request['group']) ? 'IN' : '='); } } $query->addTag('activity_stream_entity_field_access'); return $query; }
/** * Override RestfulBase::parseRequestForListFilter. * * Modify the filter for meter-category to catch all the electricity * entities that belong to the given meter-category, or any of its * children. E.g., if a meter-category of educational-buildings is given, * catch all the entities that belong to schools or kindergartens as well. * * @return array * Modified filters array. */ protected function parseRequestForListFilter() { $filters = parent::parseRequestForListFilter(); // Modify meter category filter foreach ($filters as &$filter) { // Not meter-category, skip. if ($filter['public_field'] != 'meter_category') { continue; } // Modify the filter to find entities with meter-category as given // in the filter, or any of its children $term_ids = array(); foreach ($filter['value'] as $term_id) { $term = taxonomy_term_load($term_id); // Get meter category list of children. $tree = taxonomy_get_tree($term->vid, $term_id); // The category itself is not in the tree, add it manually. $term_ids[$term_id] = $term_id; // Add all terms in the tree to term-ids. foreach ($tree as $term) { $term_ids[$term->tid] = $term->tid; } } // Modify the filter to find all entities with meter-category in the set // we just found. $filter['value'] = $term_ids; $filter['operator'][0] = 'IN'; } return $filters; }