/** * @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 $expected * @param bool $enabled * @param bool $shown * @dataProvider setInfoMessageShownDataProvider */ public function testSetInfoMessageShown($expected, $enabled = false, $shown = false) { $this->setEnabled($enabled); if ($enabled) { $this->setRequest(); } $this->assertSame($expected, $this->storage->setInfoMessageShown(self::ENTITY_NAME, EntityPaginationManager::VIEW_SCOPE, $shown)); $this->assertSame($shown, $this->storage->isInfoMessageShown(self::ENTITY_NAME, EntityPaginationManager::VIEW_SCOPE)); }