Example #1
0
 /**
  * Constructs a QueryFactory object.
  *
  * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
  *   The config storage used by the config entity query.
  * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value
  *   The key value factory.
  * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
  *   The configuration manager.
  */
 public function __construct(ConfigFactoryInterface $config_factory, KeyValueFactoryInterface $key_value, ConfigManagerInterface $config_manager)
 {
     $this->configFactory = $config_factory;
     $this->keyValueFactory = $key_value;
     $this->configManager = $config_manager;
     $this->namespaces = QueryBase::getNamespaces($this);
 }
 /**
  * {@inheritdoc}
  */
 public function compile($conditionContainer)
 {
     // If this is not the top level condition group then the sql query is
     // added to the $conditionContainer object by this function itself. The
     // SQL query object is only necessary to pass to Query::addField() so it
     // can join tables as necessary. On the other hand, conditions need to be
     // added to the $conditionContainer object to keep grouping.
     $sql_query = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery;
     $tables = new Tables($sql_query);
     foreach ($this->conditions as $condition) {
         if ($condition['field'] instanceof ConditionAggregateInterface) {
             $sql_condition = new SqlCondition($condition['field']->getConjunction());
             // Add the SQL query to the object before calling this method again.
             $sql_condition->sqlQuery = $sql_query;
             $condition['field']->compile($sql_condition);
             $sql_query->condition($sql_condition);
         } else {
             $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER';
             $field = $tables->addField($condition['field'], $type, $condition['langcode']);
             $condition_class = QueryBase::getClass($this->namespaces, 'Condition');
             $condition_class::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field']));
             $function = $condition['function'];
             $placeholder = ':db_placeholder_' . $conditionContainer->nextPlaceholder();
             $conditionContainer->having("{$function}({$field}) {$condition['operator']} {$placeholder}", array($placeholder => $condition['value']));
         }
     }
 }
Example #3
0
 /**
  * Overrides \Drupal\Core\Entity\Query\QueryBase::condition().
  *
  * Additional to the syntax defined in the QueryInterface you can use
  * placeholders (*) to match all keys of an subarray. Let's take the follow
  * yaml file as example:
  * @code
  *  level1:
  *    level2a:
  *      level3: 1
  *    level2b:
  *      level3: 2
  * @endcode
  * Then you can filter out via $query->condition('level1.*.level3', 1).
  */
 public function condition($property, $value = NULL, $operator = NULL, $langcode = NULL)
 {
     return parent::condition($property, $value, $operator, $langcode);
 }
Example #4
0
 /**
  * Implements the magic __clone method.
  *
  * Reset fields and GROUP BY when cloning.
  */
 public function __clone()
 {
     parent::__clone();
     $this->sqlFields = array();
     $this->sqlGroupBy = array();
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function getAggregate(EntityTypeInterface $entity_type, $conjunction)
 {
     $class = QueryBase::getClass($this->namespaces, 'QueryAggregate');
     return new $class($entity_type, $conjunction, $this->connection, $this->namespaces);
 }
Example #6
0
 /**
  * Constructs a new Query.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  * @param string $conjunction
  *   - AND: all of the conditions on the query need to match.
  *   - OR: at least one of the conditions on the query need to match.
  * @param array $namespaces
  *   List of potential namespaces of the classes belonging to this query.
  * @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
  *   The key value factory.
  */
 public function __construct(EntityTypeInterface $entity_type, $conjunction, array $namespaces, KeyValueFactoryInterface $key_value_factory)
 {
     parent::__construct($entity_type, $conjunction, $namespaces);
     $this->keyValueFactory = $key_value_factory;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function getAggregate(EntityTypeInterface $entity_type, $conjunction)
 {
     $class = QueryBase::getClass($this->namespaces, 'Query');
     return new $class($entity_type, $conjunction, $this->connection, $this->namespaces, $this->entityTypeManager, $this->graphHandler, $this->mappingHandler);
 }
Example #8
0
 /**
  * Constructs a query object.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type definition.
  * @param string $conjunction
  *   - AND: all of the conditions on the query need to match.
  *   - OR: at least one of the conditions on the query need to match.
  * @param \Drupal\rdf_entity\Database\Driver\sparql\Connection $connection
  *   The database connection to run the query against.
  * @param array $namespaces
  *   List of potential namespaces of the classes belonging to this query.
  * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
  *   The entity type manager service object.
  * @param \Drupal\rdf_entity\RdfGraphHandler $rdf_graph_handler
  *    The rdf graph handler service.
  * @param \Drupal\rdf_entity\RdfMappingHandler $rdf_mapping_handler
  *    The rdf mapping handler service.
  *
  * @throws \Exception
  *   Thrown when the storage passed is not an RdfEntitySparqlStorage.
  *
  * @todo: Is this exception check needed?
  */
 public function __construct(EntityTypeInterface $entity_type, $conjunction, Connection $connection, array $namespaces, EntityTypeManager $entity_type_manager, RdfGraphHandler $rdf_graph_handler, RdfMappingHandler $rdf_mapping_handler)
 {
     parent::__construct($entity_type, $conjunction, $namespaces);
     $this->filter = new SparqlFilter();
     $this->connection = $connection;
     $this->entityTypeManager = $entity_type_manager;
     $this->entityStorage = $this->entityTypeManager->getStorage($this->entityTypeId);
     $this->graphHandler = $rdf_graph_handler;
     $this->mappingHandler = $rdf_mapping_handler;
     if (!$this->entityStorage instanceof RdfEntitySparqlStorage) {
         throw new \Exception('Sparql storage is required for this query.');
     }
 }
Example #9
0
 /**
  * Constructs a QueryFactory object.
  */
 public function __construct()
 {
     $this->namespaces = QueryBase::getNamespaces($this);
 }
Example #10
0
 /**
  * Constructs a QueryFactory object.
  *
  * @param \Drupal\Core\Config\StorageInterface $config_storage
  *   The config storage used by the config entity query.
  * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
  *   The config storage used by the config entity query.
  */
 public function __construct(ConfigFactoryInterface $config_factory)
 {
     $this->configFactory = $config_factory;
     $this->namespaces = QueryBase::getNamespaces($this);
 }