/** * @param Request $request * @param string $scope * @return bool */ public function collect(Request $request, $scope) { if (!$this->paginationManager->isEnabled()) { return false; } $isDataCollected = false; $gridNames = array_keys($request->query->get('grid', [])); foreach ($gridNames as $gridName) { // datagrid manager automatically extracts all required parameters from request $dataGrid = $this->datagridManager->getDatagridByRequestParams($gridName); if (!$this->paginationManager->isDatagridApplicable($dataGrid)) { continue; } $dataSource = $dataGrid->getDatasource(); $dataGrid->getAcceptor()->acceptDatasource($dataSource); $entityName = $this->getEntityName($dataSource); $stateHash = $this->generateStateHash($dataGrid); // if entities are not in storage if (!$this->storage->hasData($entityName, $stateHash, $scope)) { $entitiesLimit = $this->getEntitiesLimit(); $totalCount = $this->getTotalCount($dataSource, $scope); // if grid contains allowed number of entities if ($totalCount <= $entitiesLimit) { // collect and set entity IDs $entityIds = $this->getAllEntityIds($dataSource, $scope, $entitiesLimit); $this->storage->setData($entityName, $stateHash, $entityIds, $scope); } else { // set empty array as a sign that data is collected, but pagination itself must be disabled $this->storage->setData($entityName, $stateHash, [], $scope); } } $isDataCollected = true; } return $isDataCollected; }
/** * @param OrmResultAfter $event */ public function onResultAfter(OrmResultAfter $event) { if (!$this->paginationManager->isEnabled()) { return; } $dataGrid = $event->getDatagrid(); if (!$this->paginationManager->isDatagridApplicable($dataGrid)) { return; } // clear all data as long as we can't guarantee that storage data is valid $entityName = $this->getEntityName($dataGrid); $this->storage->clearData($entityName); }
/** * @param mixed $source * @param bool $expected * @dataProvider isEnabledDataProvider */ public function testIsEnabled($source, $expected) { $configManager = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $configManager->expects($this->once())->method('get')->with('oro_entity_pagination.enabled')->will($this->returnValue($source)); $storage = new EntityPaginationManager($configManager); $this->assertSame($expected, $storage->isEnabled()); }