/** * Null - pager data is not accessible * Array('total' => <int>, 'current' => <int>) - used to generate string "<current> of <total>" * * @param object $entity * @param string $scope * @return null|array */ public function getPager($entity, $scope) { $totalCount = $this->paginationNavigation->getTotalCount($entity, $scope); if (!$totalCount) { return null; } $currentNumber = $this->paginationNavigation->getCurrentNumber($entity, $scope); if (!$currentNumber) { return null; } return ['total' => $totalCount, 'current' => $currentNumber]; }
/** * @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 bool $isValid * @param bool $inStorage * @param array $entityIds * @param mixed $expected * * @dataProvider getTotalCountDataProvider */ public function testGetTotalCount($isValid, $inStorage, array $entityIds, $expected) { $this->assertPrepareNavigation($isValid, $inStorage, $entityIds); $result = $this->navigation->getTotalCount($this->entity); $this->assertSame($expected, $result); }