add profile pagination

This commit is contained in:
Dennis Eichhorn 2020-02-16 19:56:02 +01:00
parent 0df5bc76a3
commit c2dc838249
3 changed files with 18 additions and 7 deletions

View File

@ -5,7 +5,7 @@
"type": 2, "type": 2,
"subtype": 1, "subtype": 1,
"name": "Profiles", "name": "Profiles",
"uri": "{/prefix}profile/list?{?}", "uri": "{/prefix}profile/list",
"target": "self", "target": "self",
"icon": null, "icon": null,
"order": 10, "order": 10,
@ -19,7 +19,7 @@
"type": 3, "type": 3,
"subtype": 1, "subtype": 1,
"name": "List", "name": "List",
"uri": "{/prefix}profile/list?{?}", "uri": "{/prefix}profile/list",
"target": "self", "target": "self",
"icon": null, "icon": null,
"order": 1, "order": 1,

View File

@ -14,13 +14,13 @@ declare(strict_types=1);
namespace Modules\Profile\Controller; namespace Modules\Profile\Controller;
use Modules\Profile\Models\Profile;
use Modules\Profile\Models\ProfileMapper; use Modules\Profile\Models\ProfileMapper;
use phpOMS\Asset\AssetType; use phpOMS\Asset\AssetType;
use phpOMS\Contract\RenderableInterface; use phpOMS\Contract\RenderableInterface;
use phpOMS\Message\RequestAbstract; use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract; use phpOMS\Message\ResponseAbstract;
use phpOMS\Views\PaginationView;
use phpOMS\Views\View; use phpOMS\Views\View;
/** /**
@ -74,7 +74,12 @@ final class BackendController extends Controller
$view = new View($this->app->l11nManager, $request, $response); $view = new View($this->app->l11nManager, $request, $response);
$view->setTemplate('/Modules/Profile/Theme/Backend/profile-list'); $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; return $view;
} }

View File

@ -12,13 +12,17 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
use phpOMS\Uri\UriFactory;
/** /**
* @var \phpOMS\Views\View $this * @var \phpOMS\Views\View $this
* @var \Modules\Profile\Models\Profile[] $accounts * @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=+';
?>
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<div class="box wf-100"> <div class="box wf-100">
@ -32,9 +36,11 @@ declare(strict_types=1);
<tfoot> <tfoot>
<tr> <tr>
<td colspan="3"> <td colspan="3">
<a class="button" href="<?= UriFactory::build($previous); ?>">Previous</a>
<a class="button" href="<?= UriFactory::build($next); ?>">Next</a>
<tbody> <tbody>
<?php $count = 0; foreach ($accounts as $key => $account) : ++$count; <?php $count = 0; foreach ($accounts as $key => $account) : ++$count;
$url = \phpOMS\Uri\UriFactory::build('{/prefix}profile/single?{?}&id=' . $account->getId()); ?> $url = UriFactory::build('{/prefix}profile/single?{?}&id=' . $account->getId()); ?>
<tr data-href="<?= $url; ?>"> <tr data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($account->getId()); ?></a> <td data-label="<?= $this->getHtml('ID', '0', '0') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($account->getId()); ?></a>
<td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($account->getAccount()->getName3() . ' ' . $account->getAccount()->getName2() . ' ' . $account->getAccount()->getName1()); ?></a> <td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($account->getAccount()->getName3() . ' ' . $account->getAccount()->getName2() . ' ' . $account->getAccount()->getName1()); ?></a>