announcements/index: Add filter and sort controls

refs #3414
This commit is contained in:
Johannes Meyer 2019-04-16 13:03:54 +02:00
parent 37df008d7f
commit 2b938442c4
2 changed files with 30 additions and 8 deletions

View File

@ -27,10 +27,26 @@ class AnnouncementsController extends Controller
) )
); );
$repo = new AnnouncementIniRepository(); $announcements = (new AnnouncementIniRepository())
$this->view->announcements = $repo ->select([
->select(array('id', 'author', 'message', 'start', 'end')) 'id',
->order('start', 'DESC'); 'author',
'message',
'start',
'end'
]);
$sortAndFilterColumns = [
'author' => $this->translate('Author'),
'message' => $this->translate('Message'),
'start' => $this->translate('Start'),
'end' => $this->translate('End')
];
$this->setupSortControl($sortAndFilterColumns, $announcements, ['start' => 'desc']);
$this->setupFilterControl($announcements, $sortAndFilterColumns, ['message']);
$this->view->announcements = $announcements->fetchAll();
} }
/** /**

View File

@ -1,6 +1,12 @@
<?php if (! $compact): ?> <?php if (! $this->compact): ?>
<div class="controls"> <div class="controls">
<?= $tabs ?> <?= $this->tabs ?>
<?= $this->paginator ?>
<div class="sort-controls-container">
<?= $this->limiter ?>
<?= $this->sortBox ?>
</div>
<?= $this->filterEditor ?>
</div> </div>
<?php endif ?> <?php endif ?>
<div class="content"> <div class="content">
@ -17,7 +23,7 @@
) )
); );
} ?> } ?>
<?php if (! $announcements->hasResult()): ?> <?php if (empty($this->announcements)): ?>
<p><?= $this->translate('No announcements found.') ?></p> <p><?= $this->translate('No announcements found.') ?></p>
</div> </div>
<?php return; endif ?> <?php return; endif ?>
@ -32,7 +38,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($announcements as $announcement): /** @var object $announcement */ ?> <?php foreach ($this->announcements as $announcement): /** @var object $announcement */ ?>
<?php if ($this->hasPermission('admin')): ?> <?php if ($this->hasPermission('admin')): ?>
<tr href="<?= $this->href('announcements/update', array('id' => $announcement->id)) ?>"> <tr href="<?= $this->href('announcements/update', array('id' => $announcement->id)) ?>">
<?php else: ?> <?php else: ?>