/** * Build an EntityFieldQuery to get referencable entities. * Almost the same as EntityReference_SelectionHandler_Generic::buildEntityFieldQuery, * but the bundles are dynamic. */ protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $this->field['settings']['target_type']); $node_types = project_node_types_by_behavior($this->field['settings']['handler_settings']['behavior']); if (!empty($node_types)) { $query->entityCondition('bundle', $node_types, 'IN'); } if (isset($match)) { $entity_info = entity_get_info($this->field['settings']['target_type']); if (isset($entity_info['entity keys']['label'])) { $query->propertyCondition($entity_info['entity keys']['label'], $match, $match_operator); } } // Add a generic entity access tag to the query. $query->addTag($this->field['settings']['target_type'] . '_access'); $query->addTag('entityreference'); $query->addMetaData('field', $this->field); $query->addMetaData('entityreference_selection_handler', $this); // Add the sort option. if (!empty($this->field['settings']['handler_settings']['sort'])) { $sort_settings = $this->field['settings']['handler_settings']['sort']; if ($sort_settings['type'] == 'property') { $query->propertyOrderBy($sort_settings['property'], $sort_settings['direction']); } elseif ($sort_settings['type'] == 'field') { list($field, $column) = explode(':', $sort_settings['field'], 2); $query->fieldOrderBy($field, $column, $sort_settings['direction']); } } return $query; }
/** * Build an EntityFieldQuery to get referencable entities. */ public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $this->field['settings']['target_type']); if (!empty($this->field['settings']['handler_settings']['target_bundles'])) { $query->entityCondition('bundle', $this->field['settings']['handler_settings']['target_bundles'], 'IN'); } if (isset($match)) { $query->propertyCondition('title', $match, $match_operator); } // Add an access tag to the query. $query->addTag('harmony_access'); $query->addTag('entityreference'); $query->addMetaData('field', $this->field); $query->addMetaData('entityreference_selection_handler', $this); // Adding the 'harmony_thread_access' tag is sadly insufficient for threads: core // requires us to also know about the concept of 'published' and // 'unpublished'. We need to do that as long as there are no access control // modules in use on the site. As long as one access control module is there, // it is supposed to handle this check. if ((!user_access('bypass harmony forum access control') || !user_access('administer forum content')) && !count(module_implements('harmony_thread_grants'))) { $query->propertyCondition('status', HARMONY_PUBLISHED); $query->propertyCondition('locked', HARMONY_NOT_LOCKED); } // Add the sort option. if (!empty($this->field['settings']['handler_settings']['sort'])) { $sort_settings = $this->field['settings']['handler_settings']['sort']; if ($sort_settings['type'] == 'property') { $query->propertyOrderBy($sort_settings['property'], $sort_settings['direction']); } elseif ($sort_settings['type'] == 'field') { list($field, $column) = explode(':', $sort_settings['field'], 2); $query->fieldOrderBy($field, $column, $sort_settings['direction']); } } return $query; }
/** * Returns the default scope for the provided server. * * Invoked by OAuth2_Scope_Drupal. * If no hook implementation returns a default scope for the current server, * then the one from $server->settings['default_scope'] is used. * * This hook runs on "authorize" and "token" requests and has access to the * client_id in $_GET (for "authorize") or via * oauth2_server_get_client_credentials() (for "token"). * Note that client_id in this case corresponds to $client->client_key. * * @return * An array of default scopes (their machine names). */ function hook_oauth2_server_default_scope($server) { // For the "test" server, grant the user any scope he has access to. if ($server->name == 'test') { $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'oauth2_server_scope'); $query->propertyCondition('server', $server->name); $query->addTag('oauth2_server_scope_access'); $query->addMetaData('oauth2_server', $server); $results = $query->execute(); if ($results) { $scope_ids = array_keys($results['oauth2_server_scope']); $scopes = entity_load('oauth2_server_scope', $scope_ids); $default_scopes = array(); foreach ($scopes as $scope) { $default_scopes[] = $scope->name; } return $default_scopes; } } }
/** * Check if the provided scope exists in storage. * * @param $scope * A space-separated string of scopes. * @param $client_id * The requesting client. * * @return * TRUE if it exists, FALSE otherwise. */ function scopeExists($scope, $client_id = null) { $scope = explode(' ', trim($scope)); // Get all scope entities that match the provided scope. // Compare the difference. $query = new \EntityFieldQuery(); $query->entityCondition('entity_type', 'oauth2_server_scope'); $query->propertyCondition('server', $this->server->name); $query->propertyCondition('name', $scope); $query->addTag('oauth2_server_scope_access'); $query->addMetaData('oauth2_server', $this->server); $results = $query->execute(); if ($results) { $scope_ids = array_keys($results['oauth2_server_scope']); $loaded_scopes = entity_load('oauth2_server_scope', $scope_ids); $found_scope = array(); foreach ($loaded_scopes as $loaded_scope) { $found_scope[] = $loaded_scope->name; } return count(array_diff($scope, $found_scope)) == 0; } }
/** * Adds query tags and metadata to the EntityFieldQuery. * * @param \EntityFieldQuery|\SelectQuery $query * The query to enhance. */ protected function addExtraInfoToQuery($query) { // Add a generic tags to the query. $query->addTag('restful'); $query->addMetaData('account', $this->getAccount()); }
/** * Build an EntityFieldQuery to get referencable entities. */ protected function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') { $query = new EntityFieldQuery(); global $user; $query->entityCondition('entity_type', 'commerce_store'); if (!user_access('add products to any store')) { $query->fieldCondition('cmp_m_store', 'target_id', $user->uid); } if (isset($match)) { $entity_info = entity_get_info('commerce_store'); if (isset($entity_info['entity keys']['label'])) { $query->propertyCondition($entity_info['entity keys']['label'], $match, $match_operator); } } // Add a generic entity access tag to the query. $query->addTag($this->field['settings']['target_type'] . '_access'); $query->addTag('entityreference'); $query->addMetaData('field', $this->field); $query->addMetaData('entityreference_selection_handler', $this); return $query; }
/** * {@inheritdoc} */ public function rebuildBatchFetch($entity, &$context) { if (!isset($context['sandbox']['info'])) { $context['sandbox']['info'] = xmlsitemap_get_link_info($entity); $context['sandbox']['progress'] = 0; $context['sandbox']['last_id'] = 0; } $info = $context['sandbox']['info']; $query = new EntityFieldQuery(); $query->entityCondition('entity_type', $entity); $query->entityCondition('entity_id', $context['sandbox']['last_id'], '>'); $query->addTag('xmlsitemap_link_bundle_access'); $query->addTag('xmlsitemap_rebuild'); $query->addMetaData('entity', $entity); $query->addMetaData('entity_info', $info); if (!isset($context['sandbox']['max'])) { $count_query = clone $query; $count_query->count(); $context['sandbox']['max'] = $count_query->execute(); if (!$context['sandbox']['max']) { // If there are no items to process, skip everything else. return; } } // PostgreSQL cannot have the ORDERED BY in the count query. $query->entityOrderBy('entity_id'); // get batch limit $limit = $this->config > get('batch_limit'); $query->range(0, $limit); $result = $query->execute(); $ids = array_keys($result[$entity]); $info['xmlsitemap']['process callback']($ids); $context['sandbox']['last_id'] = end($ids); $context['sandbox']['progress'] += count($ids); $context['message'] = t('Now processing %entity @last_id (@progress of @count).', array('%entity' => $entity, '@last_id' => $context['sandbox']['last_id'], '@progress' => $context['sandbox']['progress'], '@count' => $context['sandbox']['max'])); if ($context['sandbox']['progress'] >= $context['sandbox']['max']) { $context['finished'] = 1; } else { $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; } }