public function testMapRows() { $column = new Column(); $column->setProperty('name'); $column->setCellType(new TextCell()); $column->setLabel('User name'); $columnCollection = new ArrayCollection(); $columnCollection->add($column); $user = new User(); $user->setId(1); $user->setName('some random name'); $user->setEmail('*****@*****.**'); $rowCollection = new ArrayCollection(); $rowCollection->add($user); $mapper = new DatagridMapper(); $actual = $mapper->mapRows($rowCollection, $columnCollection); $cell = new Cell(); $cell->setProperty('name'); $cell->setValue('some random name'); $cell->setExportValue('some random name'); $cell->setType('text'); $cell->setView('text'); $cell->setAttributes([]); $row = new Row(); $row->setId(1); $row->setName(1); $row->setObject($user); $row->addCell($cell); $expected = new ArrayCollection(); $expected->add($row); $this->assertEquals($actual, $expected); }
/** * Determine what rows to use, based on the view */ public function getRowQuery() { $viewBuilder = $this->container->get('opifer.crud.view_builder'); $source = $this->datagrid->getSource(); if ($filterfields = $this->getRequest()->get('filterfields')) { $qb = $viewBuilder->any($source, $filterfields); } elseif ($this->getRequest()->get('view')) { $qb = $viewBuilder->getRowQuery($this->datagrid->getView()->getConditions(), $source); } elseif (($postVars = $this->getRequest()->request->get('listview')) && $postVars['conditions'] != '') { $conditions = $this->container->get('jms_serializer')->deserialize($postVars['conditions'], 'Opifer\\RulesEngine\\Rule\\Rule', 'json'); $qb = $viewBuilder->getRowQuery($conditions, $source); } else { $sourceRepository = $this->container->get('doctrine')->getRepository(get_class($source)); $qb = $sourceRepository->createQueryBuilder('a'); } foreach ($this->mapper->getWheres() as $where) { $qb->andWhere($where); } foreach ($this->mapper->getParameters() as $parameter => $value) { $qb->setParameter($parameter, $value); } return $this->sortRows($qb); }