Пример #1
1
 public function setUp()
 {
     $this->queryConfig = new QueryConfig();
     $this->queryConfig->setLimit(5)->setSelect(array('t.a', 't.b', 't.c'))->setPage(2)->setOrderBy(array('t.d' => true, 't.e' => false))->addParameter('query', '%xxx%')->getConstraints()->add('LOWER(t.a) LIKE :query')->add('LOWER(t.c) LIKE :query');
     $this->queryBuilder = new QueryBuilderMock();
     $this->queryBuilder->from('Table', 't');
     if ($this->queryConfig->getConstraints()->count() > 0) {
         $this->queryBuilder->andWhere($this->queryConfig->getConstraints());
     }
     if (count($this->queryConfig->getParameters()) > 0) {
         $this->queryBuilder->setParameters($this->queryConfig->getParameters());
     }
     $this->dataProvider = new DataProvider();
 }
Пример #2
0
 /**
  * Build and returns Query for select rows
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder
  * @param \EMC\TableBundle\Provider\QueryConfigInterface $queryConfig
  * @param array $mapping
  * @return \Doctrine\ORM\Query
  */
 private function getQueryRows(QueryBuilder $queryBuilder, QueryConfigInterface $queryConfig, array &$mapping)
 {
     $queryBuilder->resetDQLPart('select');
     $limit = $queryConfig->getLimit();
     $page = $queryConfig->getPage();
     $select = $queryConfig->getSelect();
     $orderBy = $queryConfig->getOrderBy();
     if ($limit > 0) {
         $queryBuilder->setMaxResults($limit)->setFirstResult(($page - 1) * $limit);
     }
     $mapping = array_map(function ($i) {
         return 'col' . $i;
     }, array_flip($select));
     foreach ($mapping as $column => $name) {
         $queryBuilder->addSelect($column . ' AS ' . $name);
     }
     if (count($orderBy) === 0) {
         $queryBuilder->orderBy($queryBuilder->getRootAlias() . '.id', 'ASC');
     } else {
         foreach ($orderBy as $column => $isAsc) {
             $queryBuilder->orderBy($column, $isAsc ? 'ASC' : 'DESC');
         }
     }
     return $queryBuilder->getQuery();
 }
 public function setUp()
 {
     $this->decoratorMock = $this->getMock('EMC\\TableBundle\\Table\\Type\\Decorator\\TableDecoratorInterface');
     $this->tableTypeMock = $this->getMock('EMC\\TableBundle\\Table\\Type\\TableTypeInterface');
     $this->columnTypeMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface');
     $this->columnMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\ColumnInterface');
     $this->columnMock->expects($this->any())->method('getType')->will($this->returnValue($this->columnTypeMock));
     $expectedView = array('a' => 1, 'b' => '2');
     $this->expectedView = $expectedView;
     $this->tableTypeMock->expects($this->any())->method('buildHeaderCellView')->willReturnCallback(function (&$view, $column) use($expectedView) {
         $view = $expectedView;
     });
     $this->tableTypeMock->expects($this->any())->method('buildBodyCellView')->willReturnCallback(function (&$view, $column) use($expectedView) {
         $view = $expectedView;
     });
     $this->tableMock = $this->getMock('EMC\\TableBundle\\Table\\TableInterface');
     $this->tableMock->method('getType')->will($this->returnValue($this->tableTypeMock));
     $this->queryConfig = new QueryConfig();
     $this->queryConfig->setLimit(5)->setSelect(array('t.a', 't.b', 't.c'))->setPage(2)->setOrderBy(array('t.d' => true, 't.e' => false))->addParameter('query', '%xxx%')->getConstraints()->add('LOWER(t.a) LIKE :query')->add('LOWER(t.c) LIKE :query');
 }