示例#1
0
 /**
  * @param mixed $queryBuilder
  * @param array $entityFieldNames
  * @return mixed
  * @throws Exception\UnsupportedTypeException
  */
 public function visit($queryBuilder, array $entityFieldNames)
 {
     /** @var $criteria Criteria */
     foreach ($this->queryFilter->getCriteria() as $criteria) {
         $this->checkCriteriaKey($criteria->getKey(), $entityFieldNames);
         /** @var CommandInterface $command */
         if (!($command = $this->commandCollection->offsetGet($criteria->getType()))) {
             throw new Exception\UnsupportedTypeException(sprintf('Tried to filter by field "%s" that is not supported', $criteria->getType()));
         }
         $command->execute($queryBuilder, $criteria);
     }
     return $queryBuilder;
 }
示例#2
0
 public function testSetQueryParametersWithAllPossibleOptions()
 {
     $data = ['$fields' => 'id,author,title', '$sort' => '-year,price', '$limit' => '5', '$page' => '1', 'year' => '$between(2014,2005)', 'price' => ['$min(20)', '$max(50)'], 'name' => ['$startswith("a")', '$endswith("z")'], 'status' => 'packaging,shipping', 'author' => '"Robert C. Marting"'];
     $this->testedObject->setQueryParameters($data);
     $resultCriteria = $this->testedObject->getCriteria();
     $this->assertCount(12, $resultCriteria);
     $this->assertNotNull($this->testedObject->getCriteria(Criteria::TYPE_SPECIAL_LIMIT));
     $this->assertNotNull($this->testedObject->getCriteria(Criteria::TYPE_SPECIAL_OFFSET));
 }
示例#3
0
 public function execute(array $query, QueryFilter $queryFilter)
 {
     if (!isset($query[$this->commandName])) {
         return false;
     }
     $value = $query[$this->commandName];
     /** @var Criteria $limitCriteria */
     if ($limitCriteria = $queryFilter->getCriteria(Criteria::TYPE_SPECIAL_LIMIT)) {
         $limitValue = $limitCriteria->getValue();
         $offsetValue = $limitValue * ((int) $value - 1);
         $queryFilter->addCriteria(new Criteria(Criteria::TYPE_SPECIAL_OFFSET, null, $offsetValue));
     }
     return true;
 }