/** * Grabs the filters from the current request environment, adapats and * parses complex filters and presents them in a useful way for * processing by the handler. * * @return array */ public function getFilters() { $columnFilters = array(); $globalFilters = array(); foreach ($this->request->getFilters() as $filter) { // If the filter is an array where the key matches one of our // columns, we're filtering that column. if (is_array($filter)) { $filterValue = reset($filter); $filterColumn = key($filter); if (!$this->data instanceof Collection) { if (($index = array_search($filterColumn, $this->dataGrid->getColumns())) !== false) { if (!is_numeric($index)) { $filterColumn = $index; } } } foreach ($this->extractFilterFeatures($filterValue) as $feature) { list($featureOperator, $featureValue) = $feature; $columnFilters[] = array($filterColumn, $featureOperator, $featureValue); } } elseif (is_string($filter)) { foreach ($this->extractFilterFeatures($filter) as $feature) { list($featureOperator, $featureValue) = $feature; $globalFilters[] = array($featureOperator, $featureValue); } } } return array($columnFilters, $globalFilters); }
/** * @runInSeparateProcess */ public function testDownloadPdf() { $dataGrid = new DataGrid($env = $this->getMockEnvironment(), array(), array()); $dataGrid->setDataHandler($this->getMockHandler()); $env->shouldReceive('getRequestProvider')->andReturn($request = m::mock('Cartalyst\\DataGrid\\RequestProviders\\Provider')); $env->shouldReceive('getDataHandlerMappings')->once()->andReturn(array('Cartalyst\\DataGrid\\DataHandlers\\CollectionHandler' => function ($data) { return $data instanceof Collection or is_array($data); })); $request->shouldReceive('getSort')->twice()->andReturn(null); $request->shouldReceive('getDirection')->once()->andReturn(null); $request->shouldReceive('getDownload')->once()->andReturn('pdf'); $request->shouldReceive('getMaxResults')->once(); $request->shouldReceive('getFilters')->once()->andReturn(array()); $request->shouldReceive('downloadPdf')->once(); $dataGrid->setupDataGridContext(); }