/** * @param string $datagridName * @param string $actionName * @param array $parameters * @param array $data * * @throws LogicException * * @return MassActionResponseInterface */ public function dispatch($datagridName, $actionName, array $parameters, array $data = []) { $inset = true; if (isset($parameters['inset'])) { $inset = $parameters['inset']; } $values = []; if (isset($parameters['values'])) { $values = $parameters['values']; } $filters = []; if (isset($parameters['filters'])) { $filters = $parameters['filters']; } if ($inset && empty($values)) { throw new LogicException(sprintf('There is nothing to do in mass action "%s"', $actionName)); } // create datagrid $datagrid = $this->manager->getDatagridByRequestParams($datagridName); // set filter data $datagrid->getParameters()->mergeKey(OrmFilterExtension::FILTER_ROOT_PARAM, $filters); // create mediator $massAction = $this->getMassActionByName($actionName, $datagrid); $identifier = $this->getIdentifierField($massAction); $qb = $this->getDatagridQuery($datagrid, $identifier, $inset, $values); //prepare query builder $qb->setMaxResults(null); $resultIterator = $this->getResultIterator($qb); $handlerArgs = new MassActionHandlerArgs($massAction, $datagrid, $resultIterator, $data); // perform mass action $handler = $this->getMassActionHandler($massAction); $result = $handler->handle($handlerArgs); return $result; }
public function testGetDatagridByRequestParamsWorksWithScope() { $gridFullName = 'test_grid:test_scope'; $gridName = 'test_grid'; $gridScope = 'test_scope'; $additionalParameters = array('foo' => 'bar'); $parameters = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\ParameterBag'); $parameters->expects($this->once())->method('add')->with($additionalParameters); $this->nameStrategy->expects($this->atLeastOnce())->method('parseGridScope')->with($gridFullName)->will($this->returnValue($gridScope)); $this->nameStrategy->expects($this->atLeastOnce())->method('parseGridName')->with($gridFullName)->will($this->returnValue($gridName)); $this->parametersFactory->expects($this->once())->method('createParameters')->with($gridFullName)->will($this->returnValue($parameters)); $configuration = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datagrid\\Common\\DatagridConfiguration')->disableOriginalConstructor()->getMock(); $configuration->expects($this->never())->method('offsetGetOr'); $configuration->expects($this->once())->method('offsetSet')->with('scope', $gridScope); $datagrid = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datagrid\\DatagridInterface'); $this->configurationProvider->expects($this->once())->method('getConfiguration')->with($gridName)->will($this->returnValue($configuration)); $this->builder->expects($this->once())->method('build')->with($configuration, $parameters)->will($this->returnValue($datagrid)); $this->assertEquals($datagrid, $this->manager->getDatagridByRequestParams($gridFullName, $additionalParameters)); }