예제 #1
0
 public function testAddFilterArrayOfValues()
 {
     $testValues = array('testArrayOfNumbers' => array('type' => Doctrine\DBAL\Connection::PARAM_INT_ARRAY, 'parameterName' => 'numbers', 'values' => array(1, 2, 3)), 'testArrayOfStrings' => array('type' => Doctrine\DBAL\Connection::PARAM_STR_ARRAY, 'parameterName' => 'strings', 'values' => array('A', 'B', 'C')));
     $filter = array();
     foreach ($testValues as $testValue) {
         $filter[] = array('property' => $testValue['parameterName'], 'value' => $testValue['values']);
     }
     $this->querybuilder->addFilter($filter);
     /** @var $expression \Doctrine\ORM\Query\Expr\Andx */
     $expression = $this->querybuilder->getDQLPart('where');
     $parts = $expression->getParts();
     $this->assertCount(2, $parts);
     $this->assertTrue(strpos($parts[0]->getRightExpr(), '(:number') === 0);
     $this->assertTrue(strpos($parts[1]->getRightExpr(), '(:strings') === 0);
     $expectedResult = array();
     $counter = 0;
     foreach ($testValues as $testValue) {
         $expectedResult[] = new Doctrine\ORM\Query\Expr\Comparison($testValue['parameterName'], 'IN', $parts[$counter]->getRightExpr());
         $counter++;
     }
     $this->assertEquals($expectedResult, $parts);
     $params = $this->querybuilder->getParameters()->toArray();
     $expectedResult = array();
     $counter = 0;
     foreach ($testValues as $testValue) {
         $expectedResult[] = new \Doctrine\ORM\Query\Parameter(trim($parts[$counter]->getRightExpr(), '()'), $testValue['values'], $testValue['type']);
         $counter++;
     }
     $this->assertEquals($expectedResult, $params);
 }
예제 #2
0
 /**
  * Adds an ordering to the query results.
  *
  * <code>
  *      $this->addFilter($builder, array(array(
  *          'property' => 'name'
  *          'direction' => 'DESC'
  *      )));
  * </code>
  *
  * @param QueryBuilder $builder
  * @param array $orderBy
  * @return array
  */
 public function addOrderBy(QueryBuilder $builder, array $orderBy)
 {
     return $builder->addOrderBy($orderBy);
 }
예제 #3
0
 /**
  * Filters the search association query by the identifier field.
  * Used for form loading if the raw value is set to the value.
  * @param string $association
  * @param int $id
  * @param QueryBuilder $builder
  */
 private function addIdentifierCondition($association, $id, QueryBuilder $builder)
 {
     $column = $this->getReferencedColumnName($association);
     if (!isset($column)) {
         return;
     }
     $builder->where($association . '.' . $column . ' = :id')->setParameters(['id' => $id])->setFirstResult(0)->setMaxResults(1);
 }
예제 #4
0
 /**
  * @param QueryBuilder $builder
  * @param array $filter
  * @deprecated
  * @return \Shopware\Components\Model\QueryBuilder
  */
 public function addFilter(QueryBuilder $builder, array $filter)
 {
     return $builder->addFilter($filter);
 }
예제 #5
0
 /**
  * Helper function to prevent duplicate source code
  * to get the full query builder result for the current resource result mode
  * using the query paginator.
  *
  * @param QueryBuilder $builder
  * @return array
  */
 private function getFullResult(QueryBuilder $builder)
 {
     $query = $builder->getQuery();
     $query->setHydrationMode($this->getResultMode());
     $paginator = $this->getManager()->createPaginator($query);
     return $paginator->getIterator()->getArrayCopy();
 }