From c2dc838249a57fb431133e5661b28d79f0456d01 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 16 Feb 2020 19:56:02 +0100 Subject: [PATCH] add profile pagination --- Admin/Install/Navigation.install.json | 4 ++-- Controller/BackendController.php | 9 +++++++-- Theme/Backend/profile-list.tpl.php | 12 +++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index 8b62ab6..baa2700 100644 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -5,7 +5,7 @@ "type": 2, "subtype": 1, "name": "Profiles", - "uri": "{/prefix}profile/list?{?}", + "uri": "{/prefix}profile/list", "target": "self", "icon": null, "order": 10, @@ -19,7 +19,7 @@ "type": 3, "subtype": 1, "name": "List", - "uri": "{/prefix}profile/list?{?}", + "uri": "{/prefix}profile/list", "target": "self", "icon": null, "order": 1, diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 1219401..de5591b 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -14,13 +14,13 @@ declare(strict_types=1); namespace Modules\Profile\Controller; -use Modules\Profile\Models\Profile; use Modules\Profile\Models\ProfileMapper; use phpOMS\Asset\AssetType; use phpOMS\Contract\RenderableInterface; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; +use phpOMS\Views\PaginationView; use phpOMS\Views\View; /** @@ -74,7 +74,12 @@ final class BackendController extends Controller $view = new View($this->app->l11nManager, $request, $response); $view->setTemplate('/Modules/Profile/Theme/Backend/profile-list'); - $view->setData('accounts', ProfileMapper::getNewest(25)); + + if ($request->getData('ptype') === '-') { + $view->setData('accounts', ProfileMapper::getBeforePivot((int) ($request->getData('id') ?? 0), null, 25)); + } else { + $view->setData('accounts', ProfileMapper::getAfterPivot((int) ($request->getData('id') ?? 0), null, 25)); + } return $view; } diff --git a/Theme/Backend/profile-list.tpl.php b/Theme/Backend/profile-list.tpl.php index 3c05df4..268d764 100644 --- a/Theme/Backend/profile-list.tpl.php +++ b/Theme/Backend/profile-list.tpl.php @@ -12,13 +12,17 @@ */ declare(strict_types=1); +use phpOMS\Uri\UriFactory; + /** * @var \phpOMS\Views\View $this * @var \Modules\Profile\Models\Profile[] $accounts */ - $accounts = $this->getData('accounts'); -?> +$accounts = $this->getData('accounts') ?? []; +$previous = empty($accounts) ? '{/prefix}profile/list' : '{/prefix}profile/list?{?}&id=' . \reset($accounts)->getId() . '&ptype=-'; +$next = empty($accounts) ? '{/prefix}profile/list' : '{/prefix}profile/list?{?}&id=' . \end($accounts)->getId() . '&ptype=+'; +?>
@@ -32,9 +36,11 @@ declare(strict_types=1); + Previous + Next $account) : ++$count; - $url = \phpOMS\Uri\UriFactory::build('{/prefix}profile/single?{?}&id=' . $account->getId()); ?> + $url = UriFactory::build('{/prefix}profile/single?{?}&id=' . $account->getId()); ?> printHtml($account->getId()); ?> printHtml($account->getAccount()->getName3() . ' ' . $account->getAccount()->getName2() . ' ' . $account->getAccount()->getName1()); ?>