Commit d0badea8 authored by Tino Goratsch's avatar Tino Goratsch

Merge branch 'feature/results-per-page' into develop

parents a61fcd1c 31815122
......@@ -69,6 +69,10 @@ abstract class AbstractWidgetAction implements ActionInterface
* @var Response
*/
protected $response;
/**
* @var Core\Helpers\ResultsPerPage
*/
protected $resultsPerPage;
/**
* WidgetController constructor.
......@@ -90,6 +94,7 @@ abstract class AbstractWidgetAction implements ActionInterface
$this->config = $context->getConfig();
$this->appPath = $context->getAppPath();
$this->response = $context->getResponse();
$this->resultsPerPage = $context->getResultsPerPage();
}
/**
......
......@@ -58,7 +58,8 @@ class FrontendContext extends Core\Controller\Context\WidgetContext
$context->getView(),
$context->getConfig(),
$context->getAppPath(),
$context->getResponse()
$context->getResponse(),
$context->getResultsPerPage()
);
$this->assets = $assets;
......
......@@ -7,6 +7,7 @@ namespace ACP3\Core\Controller\Context;
use ACP3\Core\ACL;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Helpers\ResultsPerPage;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Modules;
......@@ -77,6 +78,10 @@ class WidgetContext
* @var \Symfony\Component\HttpFoundation\Response
*/
private $response;
/**
* @var ResultsPerPage
*/
private $resultsPerPage;
/**
* WidgetContext constructor.
......@@ -94,6 +99,7 @@ class WidgetContext
* @param \ACP3\Core\Settings\SettingsInterface $config
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param Response $response
* @param ResultsPerPage $resultsPerPage
*/
public function __construct(
ContainerInterface $container,
......@@ -108,7 +114,8 @@ class WidgetContext
View $view,
SettingsInterface $config,
ApplicationPath $appPath,
Response $response
Response $response,
ResultsPerPage $resultsPerPage
) {
$this->container = $container;
$this->eventDispatcher = $eventDispatcher;
......@@ -123,6 +130,7 @@ class WidgetContext
$this->config = $config;
$this->appPath = $appPath;
$this->response = $response;
$this->resultsPerPage = $resultsPerPage;
}
/**
......@@ -228,4 +236,12 @@ class WidgetContext
{
return $this->response;
}
/**
* @return ResultsPerPage
*/
public function getResultsPerPage()
{
return $this->resultsPerPage;
}
}
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Helpers;
use ACP3\Core\Settings\SettingsInterface;
use ACP3\Modules\ACP3\System\Installer\Schema;
class ResultsPerPage
{
/**
* @var SettingsInterface
*/
private $settings;
/**
* @var array
*/
private $resultsPerPage = [];
/**
* ResultsPerPage constructor.
* @param SettingsInterface $settings
*/
public function __construct(SettingsInterface $settings)
{
$this->settings = $settings;
}
/**
* @param string $moduleName
* @return int
*/
public function getResultsPerPage($moduleName)
{
if (!isset($this->resultsPerPage[$moduleName])) {
$moduleSettings = $this->settings->getSettings($moduleName);
if (!empty($moduleSettings['entries'])) {
$this->resultsPerPage[$moduleName] = $moduleSettings['entries'];
} else {
$moduleName = Schema::MODULE_NAME;
$this->getResultsPerPage($moduleName);
}
}
return (int)$this->resultsPerPage[$moduleName];
}
}
......@@ -6,7 +6,6 @@ use ACP3\Core\Controller\AreaEnum;
use ACP3\Core\Http\RequestInterface;
use ACP3\Core\I18n\Translator;
use ACP3\Core\Router\RouterInterface;
use ACP3\Modules\ACP3\Users\Model\UserModel;
/**
* Class Pagination
......@@ -69,15 +68,12 @@ class Pagination
/**
* Pagination constructor.
*
* @param \ACP3\Modules\ACP3\Users\Model\UserModel $user
* @param \ACP3\Core\Breadcrumb\Title $title
* @param \ACP3\Core\I18n\Translator $translator
* @param \ACP3\Core\Http\RequestInterface $request
* @param \ACP3\Core\Router\RouterInterface $router
* @param Title $title
* @param Translator $translator
* @param RequestInterface $request
* @param RouterInterface $router
*/
public function __construct(
UserModel $user,
Title $title,
Translator $translator,
RequestInterface $request,
......@@ -87,56 +83,72 @@ class Pagination
$this->translator = $translator;
$this->request = $request;
$this->router = $router;
$this->resultsPerPage = $user->getEntriesPerPage();
}
/**
* @param int $results
* @return $this
*/
public function setResultsPerPage($results)
{
$this->resultsPerPage = (int)$results;
return $this;
}
/**
* @param int $results
* @return $this
*/
public function setTotalResults($results)
{
$this->totalResults = (int)$results;
return $this;
}
/**
* @param string $fragment
* @return $this
*/
public function setUrlFragment($fragment)
{
$this->urlFragment = $fragment;
return $this;
}
/**
* @param int $pagesToDisplay
* @return $this
*/
public function setPagesToDisplay($pagesToDisplay)
{
$this->pagesToDisplay = (int)$pagesToDisplay;
return $this;
}
/**
* @param int $showFirstLast
* @return $this
*/
public function setShowFirstLast($showFirstLast)
{
$this->showFirstLast = (int)$showFirstLast;
return $this;
}
/**
* @param int $showPreviousNext
* @return $this
*/
public function setShowPreviousNext($showPreviousNext)
{
$this->showPreviousNext = (int)$showPreviousNext;
return $this;
}
/**
......
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Core\Test\Helpers;
use ACP3\Core\Helpers\ResultsPerPage;
use ACP3\Core\Settings\SettingsInterface;
class ResultsPerPageTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ResultsPerPage
*/
private $resultsPerPage;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $settingsMock;
protected function setUp()
{
$this->setUpMockObjects();
$this->resultsPerPage = new ResultsPerPage($this->settingsMock);
}
private function setUpMockObjects()
{
$this->settingsMock = $this->getMockBuilder(SettingsInterface::class)
->setMethods(['getSettings', 'saveSettings'])
->getMock();
}
public function testGetResultsPerPageWithoutFallback()
{
$this->settingsMock
->expects($this->once())
->method('getSettings')
->with('news')
->willReturn(['entries' => 10]);
$expected = 10;
$this->assertEquals($expected, $this->resultsPerPage->getResultsPerPage('news'));
}
public function testGetResultsPerPageWithFallback()
{
$this->settingsMock
->expects($this->exactly(2))
->method('getSettings')
->withConsecutive(['news'], ['system'])
->willReturnOnConsecutiveCalls([], ['entries' => 20]);
$expected = 20;
$this->assertEquals($expected, $this->resultsPerPage->getResultsPerPage('news'));
}
}
......@@ -15,6 +15,7 @@ services:
- '@core.config'
- '@core.environment.application_path'
- '@core.http.response'
- '@core.helpers.results_per_page'
public: false
core.context.admin:
......
......@@ -55,6 +55,11 @@ services:
- '@core.router'
- '@core.helpers.toc'
core.helpers.results_per_page:
class: ACP3\Core\Helpers\ResultsPerPage
arguments:
- '@core.config'
core.helpers.sort:
class: ACP3\Core\Helpers\Sort
arguments:
......
......@@ -77,7 +77,6 @@ services:
core.pagination:
class: ACP3\Core\Pagination
arguments:
- '@users.model.user_model'
- '@core.breadcrumb.title'
- '@core.lang'
- '@core.http.request'
......
......@@ -8,7 +8,7 @@ namespace ACP3\Modules\ACP3\Articles\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Articles;
use ACP3\Modules\ACP3\Menus;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -45,7 +45,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setRepository($this->dataGridRepository)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/articles/index/delete')
->setResourcePathEdit('admin/articles/index/edit');
......
......@@ -52,18 +52,24 @@ class Index extends Core\Controller\AbstractFrontendAction
$this->articleRepository = $articleRepository;
}
/**
* @return array
*/
public function execute()
{
$this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
$resultsPerPage = $this->resultsPerPage->getResultsPerPage(Articles\Installer\Schema::MODULE_NAME);
$time = $this->date->getCurrentDateTime();
$this->pagination
->setResultsPerPage($resultsPerPage)
->setTotalResults($this->articleRepository->countAll($time));
$articles = $this->articleRepository->getAll(
$time,
$this->pagination->getResultsStartOffset(),
$this->user->getEntriesPerPage()
$resultsPerPage
);
$this->pagination->setTotalResults($this->articleRepository->countAll($time));
return [
'articles' => $articles,
'pagination' => $this->pagination->render()
......
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Categories\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Categories;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -44,7 +45,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setRepository($this->dataGridRepository)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/categories/index/delete')
->setResourcePathEdit('admin/categories/index/edit');
......
......@@ -9,6 +9,7 @@ namespace ACP3\Modules\ACP3\Comments\Controller\Admin\Details;
use ACP3\Core;
use ACP3\Modules\ACP3\Comments;
use ACP3\Modules\ACP3\System;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -61,7 +62,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setResults($comments)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/comments/details/delete/id_' . $id)
->setResourcePathEdit('admin/comments/details/edit');
......
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Comments\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Comments;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -44,7 +45,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setResults($this->commentRepository->getCommentsGroupedByModule())
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/comments/index/delete')
->setResourcePathEdit('admin/comments/details/index');
......
......@@ -52,35 +52,34 @@ class Index extends AbstractFrontendAction
{
$this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
$resultsPerPage = $this->resultsPerPage->getResultsPerPage(Comments\Installer\Schema::MODULE_NAME);
$this->pagination
->setResultsPerPage($resultsPerPage)
->setTotalResults(
$this->commentRepository->countAllByModule($this->modules->getModuleId($module), $entryId)
);
$comments = $this->commentRepository->getAllByModule(
$this->modules->getModuleId($module),
$entryId,
$this->pagination->getResultsStartOffset(),
$this->user->getEntriesPerPage()
$resultsPerPage
);
$cComments = count($comments);
if ($cComments > 0) {
$this->pagination->setTotalResults(
$this->commentRepository->countAllByModule($this->modules->getModuleId($module), $entryId)
);
for ($i = 0; $i < $cComments; ++$i) {
if (empty($comments[$i]['name'])) {
$comments[$i]['name'] = $this->translator->t('users', 'deleted_user');
}
if ($this->emoticonsActive === true && $this->emoticonsHelpers) {
$comments[$i]['message'] = $this->emoticonsHelpers->emoticonsReplace($comments[$i]['message']);
}
for ($i = 0; $i < $cComments; ++$i) {
if (empty($comments[$i]['name'])) {
$comments[$i]['name'] = $this->translator->t('users', 'deleted_user');
}
if ($this->emoticonsActive === true && $this->emoticonsHelpers) {
$comments[$i]['message'] = $this->emoticonsHelpers->emoticonsReplace($comments[$i]['message']);
}
return [
'comments' => $comments,
'dateformat' => $this->commentsSettings['dateformat'],
'pagination' => $this->pagination->render()
];
}
return [];
return [
'comments' => $comments,
'dateformat' => $this->commentsSettings['dateformat'],
'pagination' => $this->pagination->render()
];
}
}
<section>
<h3 class="text-center">{lang t="comments|comments"}</h3>
{redirect_message}
{if isset($comments)}
{if !empty($comments)}
{include file="asset:System/Partials/pagination.tpl" pagination=$pagination}
{foreach $comments as $row}
<article class="dataset-box dataset-box__comments">
......
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Emoticons\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Emoticons;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -41,7 +42,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setRepository($this->dataGridRepository)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/emoticons/index/delete')
->setResourcePathEdit('admin/emoticons/index/edit');
......
......@@ -7,9 +7,8 @@
namespace ACP3\Modules\ACP3\Files\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Categories;
use ACP3\Modules\ACP3\Comments;
use ACP3\Modules\ACP3\Files;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -46,7 +45,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setRepository($this->dataGridRepository)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/files/index/delete')
->setResourcePathEdit('admin/files/index/edit');
......
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Gallery\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Gallery;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Edit
......@@ -102,7 +103,7 @@ class Edit extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setResults($pictures)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/gallery/pictures/delete/id_' . $id)
->setResourcePathEdit('admin/gallery/pictures/edit');
......
......@@ -8,6 +8,7 @@ namespace ACP3\Modules\ACP3\Gallery\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Gallery;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -44,7 +45,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setRepository($this->dataGridRepository)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/gallery/index/delete')
->setResourcePathEdit('admin/gallery/index/edit');
......
......@@ -59,15 +59,17 @@ class Index extends AbstractAction
{
$this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
$resultsPerPage = $this->resultsPerPage->getResultsPerPage(Gallery\Installer\Schema::MODULE_NAME);
$time = $this->date->getCurrentDateTime();
$this->pagination->setTotalResults($this->galleryRepository->countAll($time));
$this->pagination
->setResultsPerPage($resultsPerPage)
->setTotalResults($this->galleryRepository->countAll($time));
return [
'galleries' => $this->galleryRepository->getAll(
$time,
$this->pagination->getResultsStartOffset(),
$this->user->getEntriesPerPage()
$resultsPerPage
),
'dateformat' => $this->settings['dateformat'],
'pagination' => $this->pagination->render()
......
......@@ -7,8 +7,8 @@
namespace ACP3\Modules\ACP3\Guestbook\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Emoticons;
use ACP3\Modules\ACP3\Guestbook;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -45,7 +45,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setRepository($this->dataGridRepository)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/guestbook/index/delete')
->setResourcePathEdit('admin/guestbook/index/edit');
......
......@@ -30,8 +30,8 @@ class Index extends AbstractAction
/**
* Index constructor.
*
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Pagination $pagination
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Pagination $pagination
* @param \ACP3\Modules\ACP3\Guestbook\Model\Repository\GuestbookRepository $guestbookRepository
*/
public function __construct(
......@@ -52,20 +52,21 @@ class Index extends AbstractAction
{
$this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
$resultsPerPage = $this->resultsPerPage->getResultsPerPage(Guestbook\Installer\Schema::MODULE_NAME);
$this->pagination
->setResultsPerPage($resultsPerPage)
->setTotalResults($this->guestbookRepository->countAll($this->guestbookSettings['notify']));
$guestbook = $this->guestbookRepository->getAll(
$this->guestbookSettings['notify'],
$this->pagination->getResultsStartOffset(),
$this->user->getEntriesPerPage()
$resultsPerPage
);
$cGuestbook = count($guestbook);
if ($cGuestbook > 0) {
$this->pagination->setTotalResults($this->guestbookRepository->countAll($this->guestbookSettings['notify']));
for ($i = 0; $i < $cGuestbook; ++$i) {
if ($this->guestbookSettings['emoticons'] == 1 && $this->emoticonsHelpers) {
$guestbook[$i]['message'] = $this->emoticonsHelpers->emoticonsReplace($guestbook[$i]['message']);
}
for ($i = 0; $i < $cGuestbook; ++$i) {
if ($this->guestbookSettings['emoticons'] == 1 && $this->emoticonsHelpers) {
$guestbook[$i]['message'] = $this->emoticonsHelpers->emoticonsReplace($guestbook[$i]['message']);
}
}
......
......@@ -7,9 +7,8 @@
namespace ACP3\Modules\ACP3\News\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Modules\ACP3\Categories;
use ACP3\Modules\ACP3\Comments;
use ACP3\Modules\ACP3\News;
use ACP3\Modules\ACP3\System\Installer\Schema;
/**
* Class Index
......@@ -46,7 +45,7 @@ class Index extends Core\Controller\AbstractAdminAction
$dataGrid = $this->get('core.helpers.data_grid');
$dataGrid
->setRepository($this->dataGridRepository)
->setRecordsPerPage($this->user->getEntriesPerPage())
->setRecordsPerPage($this->resultsPerPage->getResultsPerPage(Schema::MODULE_NAME))
->setIdentifier('#acp-table')
->setResourcePathDelete('admin/news/index/delete')
->setResourcePathEdit('admin/news/index/edit');
......
......@@ -52,12 +52,12 @@ class Index extends AbstractAction
/**
* Index constructor.
*
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Helpers\StringFormatter $stringFormatter
* @param \ACP3\Core\Pagination $pagination
* @param \ACP3\Modules\ACP3\News\Model\Repository\NewsRepository $newsRepository
* @param \ACP3\Modules\ACP3\Categories\Helpers $categoriesHelpers
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Helpers\StringFormatter $stringFormatter
* @param \ACP3\Core\Pagination $pagination
* @param \ACP3\Modules\ACP3\News\Model\Repository\NewsRepository $newsRepository
* @param \ACP3\Modules\ACP3\Categories\Helpers $categoriesHelpers
* @param \ACP3\Modules\ACP3\Categories\Model\Repository\CategoryRepository $categoryRepository
*/
public