示例#1
0
 /**
  * @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;
 }
示例#2
0
 /**
  * @param object $entity
  * @param string $scope
  * @return string|null
  */
 public function getInfoMessage($entity, $scope = EntityPaginationManager::VIEW_SCOPE)
 {
     $entityName = ClassUtils::getClass($entity);
     // info message should be shown only once for each scope
     if (false !== $this->storage->isInfoMessageShown($entityName, $scope)) {
         return null;
     }
     $viewCount = $this->navigation->getTotalCount($entity, EntityPaginationManager::VIEW_SCOPE);
     $editCount = $this->navigation->getTotalCount($entity, EntityPaginationManager::EDIT_SCOPE);
     if (!$viewCount || !$editCount || $viewCount == $editCount) {
         return null;
     }
     $message = '';
     $count = null;
     // if scope is changing from "view" to "edit" and number of entities is decreased
     if ($scope == EntityPaginationManager::EDIT_SCOPE) {
         if ($editCount < $viewCount) {
             $message .= $this->translator->trans('oro.entity_pagination.message.stats_changed_view_to_edit') . ' ';
         }
         $count = $editCount;
     } elseif ($scope == EntityPaginationManager::VIEW_SCOPE) {
         $count = $viewCount;
     }
     if (!$count) {
         return null;
     }
     $message .= $this->translator->transChoice($this->getStatsMessage($scope), $count, ['%count%' => $count]);
     $this->storage->setInfoMessageShown($entityName, $scope);
     return $message;
 }
 /**
  * @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 object $entity
  * @param string $resultType
  * @param string $scope
  * @return int|null
  */
 protected function getProcessedIdentifier($entity, $resultType, $scope = EntityPaginationManager::VIEW_SCOPE)
 {
     $entityIds = $this->storage->getEntityIds($entity, $scope);
     $entityId = null;
     switch ($resultType) {
         case self::LAST:
             $entityId = end($entityIds);
             break;
         case self::FIRST:
             $entityId = reset($entityIds);
             break;
         case self::PREVIOUS:
             $currentPosition = $this->storage->getCurrentPosition($entity, $scope);
             if (isset($entityIds[$currentPosition - 1])) {
                 $entityId = $entityIds[$currentPosition - 1];
             }
             break;
         case self::NEXT:
             $currentPosition = $this->storage->getCurrentPosition($entity, $scope);
             if (isset($entityIds[$currentPosition + 1])) {
                 $entityId = $entityIds[$currentPosition + 1];
             }
             break;
     }
     return $entityId;
 }
 protected function setRequest()
 {
     $session = new Session(new MockArraySessionStorage());
     $request = new Request();
     $request->setSession($session);
     $this->storage->setRequest($request);
 }