/**
  * Sets index for search.
  *
  * This will set the table to null, if the default is an internal '_all'.
  *
  * @param   string                $documentType  The Elasticsearch type
  * @param   RepositoryQuery|null  $query         The user query
  *
  * @return  null
  */
 public function requireTable($documentType, RepositoryQuery $query = null)
 {
     if ($query !== null) {
         /** @var RestApiQuery $real_query */
         $real_query = $query->getQuery();
         $real_query->setIndices(array($this->getIndex()));
         if ($documentType !== null) {
             $real_query->setTypes(array($documentType));
         }
     }
     if ($documentType === null or $documentType === '_all') {
         return null;
     }
     return parent::requireTable($documentType, $query);
 }
Ejemplo n.º 2
0
 /**
  * Return a new query for the given columns
  *
  * @param   array   $columns    The desired columns, if null all columns will be queried
  *
  * @return  RepositoryQuery
  */
 public function select(array $columns = null)
 {
     $query = new RepositoryQuery($this);
     $query->from($this->getBaseTable(), $columns);
     return $query;
 }
Ejemplo n.º 3
0
 /**
  * Join alias or column $name into $table using $query
  *
  * Attempts to find a valid table for the given alias or column name and a method labelled join<TableName>
  * to process the actual join logic. If neither of those is found, null is returned.
  * The method is called with the same parameters but in reversed order.
  *
  * @param   string              $name       The alias or column name to join into $target
  * @param   string              $target     The table to join $name into
  * @param   RepositoryQUery     $query      The query to apply the JOIN-clause on
  *
  * @return  string|null                     The resolved alias or $name, null if no join logic is found
  */
 public function joinColumn($name, $target, RepositoryQuery $query)
 {
     if (!($tableName = $this->findTableName($name))) {
         return;
     }
     if (($column = $this->resolveQueryColumnAlias($tableName, $name)) === null) {
         $column = $name;
     }
     if (($joinIdentifier = $this->resolveTableAlias($tableName)) === null) {
         $joinIdentifier = $this->prependTablePrefix($tableName);
     }
     if ($query->getQuery()->hasJoinedTable($joinIdentifier)) {
         return $column;
     }
     $joinMethod = 'join' . StringHelper::cname($tableName);
     if (!method_exists($this, $joinMethod)) {
         throw new ProgrammingError('Unable to join table "%s" into "%s". Method "%s" not found', $tableName, $target, $joinMethod);
     }
     $this->{$joinMethod}($query, $target, $name);
     return $column;
 }
Ejemplo n.º 4
0
 /**
  * Join group_membership into group
  *
  * @param   RepositoryQuery     $query
  */
 protected function joinGroupMembership(RepositoryQuery $query)
 {
     $query->getQuery()->joinLeft($this->requireTable('group_membership'), 'g.id = gm.group_id', array());
 }
Ejemplo n.º 5
0
 /**
  * Join alias or column $name into $table using $query
  *
  * Attempts to find a valid table for the given alias or column name and a method labelled join<TableName>
  * to process the actual join logic. If neither of those is found, ProgrammingError will be thrown.
  * The method is called with the same parameters but in reversed order.
  *
  * @param   string              $name       The alias or column name to join into $target
  * @param   array|string        $target     The table to join $name into
  * @param   RepositoryQUery     $query      The query to apply the JOIN-clause on
  *
  * @return  string                          The resolved alias or $name
  *
  * @throws  ProgrammingError                In case no valid table or join<TableName>-method is found
  */
 public function joinColumn($name, $target, RepositoryQuery $query)
 {
     $tableName = $this->findTableName($name);
     if (!$tableName) {
         throw new ProgrammingError('Unable to find a valid table for column "%s" to join into "%s"', $name, $this->removeTablePrefix($this->clearTableAlias($target)));
     }
     if (($column = $this->resolveQueryColumnAlias($tableName, $name)) === null) {
         $column = $name;
     }
     $prefixedTableName = $this->prependTablePrefix($tableName);
     if ($query->getQuery()->hasJoinedTable($prefixedTableName)) {
         return $column;
     }
     $joinMethod = 'join' . String::cname($tableName);
     if (!method_exists($this, $joinMethod)) {
         throw new ProgrammingError('Unable to join table "%s" into "%s". Method "%s" not found', $tableName, $this->removeTablePrefix($this->clearTableAlias($target)), $joinMethod);
     }
     $this->{$joinMethod}($query, $target, $name);
     return $column;
 }
Ejemplo n.º 6
0
 /**
  * Validate that the requested table exists
  *
  * @param   string              $table      The table to validate
  * @param   RepositoryQuery     $query      An optional query to pass as context
  *
  * @return  string
  *
  * @throws  ProgrammingError                In case the given table does not exist
  */
 public function requireTable($table, RepositoryQuery $query = null)
 {
     if ($query !== null) {
         $query->getQuery()->setBase($this->groupBaseDn);
         if ($table === 'group' && $this->groupFilter) {
             $query->getQuery()->setNativeFilter($this->groupFilter);
         }
     }
     return parent::requireTable($table, $query);
 }
 /**
  * Validate that the requested document type exists
  *
  * @param   string|array        $documentType   The document type to validate
  * @param   RepositoryQuery     $query          An optional query to pass as context
  *
  * @return  array   The document type with its index being applied
  */
 public function requireTable($documentType, RepositoryQuery $query = null)
 {
     if ($query !== null) {
         $query->getQuery()->setIndices(array($this->getIndex()));
     }
     return parent::requireTable($this->extractDocumentType($documentType), $query);
 }
 /**
  * Applies the name filter of EventType restrictions onto a Query
  *
  * @param RepositoryQuery $query
  */
 public function filterEventTypes(RepositoryQuery $query)
 {
     $allowedTypes = $this->canEventTypes();
     if (!empty($allowedTypes)) {
         $filter = Filter::matchAny();
         foreach ($allowedTypes as $type) {
             $here = Filter::where('name', $type);
             $filter->addFilter($here);
         }
         $query->addFilter($filter);
     }
 }