Esempio n. 1
0
 /**
  * Constructor
  * 
  * @param Librarian $librarian The librarian interface responsible for the query
  * @param DBAL\Connection $db A Doctrine Connection
  * @param int $limit The maximum number of results to return
  * @param array $orderBy An assoc. array of indexName => direction
  * @param array $indexes An assoc. array of indexName => Index
  */
 public function __construct(LibrarianInterface $librarian, DBAL\Connection $db, $limit, array $orderBy, array $indexes)
 {
     $this->librarian = $librarian;
     $this->indexes = $indexes;
     $this->db = $db;
     $this->limit = $limit;
     $this->queryBuilder = $this->db->createQueryBuilder();
     $this->queryBuilder->setMaxResults($limit);
     foreach ($this->indexes as $index) {
         $index->setQuery($this);
         $index->setQueryBuilder($this->queryBuilder);
     }
     // TODO: make this explicitly defined?
     $this->mainIndex = current($this->indexes);
     foreach (array_slice($this->indexes, 1) as $name => $index) {
         $this->queryBuilder->leftJoin($this->mainIndex->getName(), $index->getTableName(), $index->getName($quote = true), $this->mainIndex->getName() . '.id = ' . $this->db->quoteIdentifier($name) . '.id');
     }
     $this->queryBuilder->select('distinct ' . $this->mainIndex->getName() . '.id')->from($this->mainIndex->getTableName(), $this->mainIndex->getName($quote = true));
     foreach ($orderBy as $name => $direction) {
         $this->indexes[$name]->orderBy($direction);
     }
 }
Esempio n. 2
0
 public static function getSubscribedEvents()
 {
     return array_merge(parent::getSubscribedEvents(), [Events::PUT_EVENT => ['onPut', 100]]);
 }
Esempio n. 3
0
 public static function getSubscribedEvents()
 {
     return array_merge(parent::getSubscribedEvents(), [Events::GET_EVENT => ['hydrateProperty', -100], Events::PUT_EVENT => ['dehydratePropertyAndUpdateIndex', 100]]);
 }