Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function getUniqueByFetcher(Fetcher $fetcher)
 {
     $fetcher->setPage(1);
     $fetcher->setNbByPage(2);
     $ids = $this->getIdsByFetcher($fetcher);
     if (empty($ids)) {
         return null;
     }
     if (count($ids) === 2) {
         throw new NotUniqueResultException();
     }
     return $this->manager->getById(reset($ids));
 }
Esempio n. 2
0
 private function reloadResults()
 {
     if ($this->lastId !== null) {
         if ($this->filterIdOperation === null) {
             $this->filterIdOperation = $this->fetcher->filterByGreaterThanId($this->lastId);
         } else {
             $this->filterIdOperation->setValue($this->lastId);
         }
     }
     $this->results = $this->fetchable->getByFetcher($this->fetcher)->getResultSet();
     if (!$this->fetcher->hasResults()) {
         $this->ended = true;
         $this->currentKey = null;
     } else {
         if ($this->fetcher->count() !== $this->fetcher->getNbByPage()) {
             $this->ended = true;
         }
         $this->currentKey = key($this->results);
         /** @var VO $vo */
         $vo = current($this->results);
         if ($vo !== false) {
             $this->lastId = $vo->getId();
         }
     }
 }
 protected function buildOperation(Fetcher $fetcher)
 {
     $rootOperation = $fetcher->getRootOperation();
     $operations = $rootOperation->getOperations();
     //We replace the operator by the groupName value from the fetcher
     foreach ($operations as $operation) {
         if ($operation instanceof ListOperation) {
             $realFilterOperator = $fetcher->getRealFilterOperator($operation->getGroupName());
             if ($realFilterOperator != null) {
                 $operation->setOperator($realFilterOperator);
             }
         }
     }
     //We replace the operator by the main operator value from the fetcher
     $rootOperation->setOperator($fetcher->getMainOperator());
     return $this->getOperationAsArray($rootOperation);
 }
Esempio n. 4
0
 /**
  * @param Fetcher $fetcher
  * @param string  $mainTableAlias
  * @return string[]
  */
 protected function getQueryParameters(Fetcher $fetcher = null, $mainTableAlias = 'ref')
 {
     $select = '';
     $from = '';
     if ($fetcher != null) {
         $selectedColumns = array();
         $selectedJoins = array();
         $columns = $fetcher->getFilterColumns();
         foreach ($columns as $column) {
             list($selectedColumns, $selectedJoins) = $this->getSelectedColumnsJoins($column, $mainTableAlias, $selectedColumns, $selectedJoins);
         }
         $sorts = $fetcher->getSorts();
         foreach ($sorts as $column => $sortOrder) {
             list($selectedColumns, $selectedJoins) = $this->getSelectedColumnsJoins($column, $mainTableAlias, $selectedColumns, $selectedJoins);
         }
         $toUse = array();
         foreach ($selectedColumns as $key => $value) {
             if ($mainTableAlias . '.id' !== $value) {
                 $toUse[$key] = $value;
             }
         }
         if (!empty($toUse)) {
             $select = ', ' . implode(', ', $toUse);
         }
         if (!empty($selectedJoins)) {
             $joins = $this->getJoins();
             $selectedJoinsSql = array_intersect_key($joins, $selectedJoins);
             $from = implode(' ', $selectedJoinsSql);
         }
     }
     return array($select, $from);
 }