diff --git a/application/controllers/AnnouncementsController.php b/application/controllers/AnnouncementsController.php index 513d8efe7..c72d36af1 100644 --- a/application/controllers/AnnouncementsController.php +++ b/application/controllers/AnnouncementsController.php @@ -27,10 +27,26 @@ class AnnouncementsController extends Controller ) ); - $repo = new AnnouncementIniRepository(); - $this->view->announcements = $repo - ->select(array('id', 'author', 'message', 'start', 'end')) - ->order('start', 'DESC'); + $announcements = (new AnnouncementIniRepository()) + ->select([ + 'id', + '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(); } /** diff --git a/application/forms/Announcement/AnnouncementForm.php b/application/forms/Announcement/AnnouncementForm.php index 2caaca0f4..0bc4713cb 100644 --- a/application/forms/Announcement/AnnouncementForm.php +++ b/application/forms/Announcement/AnnouncementForm.php @@ -13,6 +13,21 @@ use Icinga\Forms\RepositoryForm; */ class AnnouncementForm extends RepositoryForm { + protected function fetchEntry() + { + $entry = parent::fetchEntry(); + if ($entry !== false) { + if ($entry->start !== null) { + $entry->start = (new DateTime())->setTimestamp($entry->start); + } + if ($entry->end !== null) { + $entry->end = (new DateTime())->setTimestamp($entry->end); + } + } + + return $entry; + } + /** * {@inheritDoc} */ diff --git a/application/views/scripts/announcements/index.phtml b/application/views/scripts/announcements/index.phtml index 311cfd9da..9958a318b 100644 --- a/application/views/scripts/announcements/index.phtml +++ b/application/views/scripts/announcements/index.phtml @@ -1,6 +1,12 @@ - +compact): ?>
- + tabs ?> + paginator ?> +
+ limiter ?> + sortBox ?> +
+ filterEditor ?>
@@ -17,7 +23,7 @@ ) ); } ?> -hasResult()): ?> +announcements)): ?>

translate('No announcements found.') ?>

@@ -32,7 +38,7 @@ - + announcements as $announcement): /** @var object $announcement */ ?> hasPermission('admin')): ?> @@ -40,8 +46,8 @@ escape($announcement->author) ?> ellipsis($this->escape($announcement->message), 100) ?> - formatDateTime($announcement->start->getTimestamp()) ?> - formatDateTime($announcement->end->getTimestamp()) ?> + formatDateTime($announcement->start) ?> + formatDateTime($announcement->end) ?> hasPermission('admin')): ?> qlink( null, diff --git a/library/Icinga/Data/SimpleQuery.php b/library/Icinga/Data/SimpleQuery.php index 21f3734f3..2d0eeef6f 100644 --- a/library/Icinga/Data/SimpleQuery.php +++ b/library/Icinga/Data/SimpleQuery.php @@ -365,13 +365,11 @@ class SimpleQuery implements QueryInterface, Queryable, Iterator } $column = $this->order[$orderIndex][0]; - if (array_key_exists($column, $this->flippedColumns)) { + if (array_key_exists($column, $this->flippedColumns) && is_string($this->flippedColumns[$column])) { $column = $this->flippedColumns[$column]; } - // TODO: throw Exception if column is missing - //$res = strnatcmp(strtolower($a->$column), strtolower($b->$column)); - $result = @strcmp(strtolower($a->$column), strtolower($b->$column)); + $result = strcmp(strtolower($a->$column), strtolower($b->$column)); if ($result === 0) { return $this->compare($a, $b, ++$orderIndex); } diff --git a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php index ab49021be..12750d11b 100644 --- a/library/Icinga/Web/Announcement/AnnouncementIniRepository.php +++ b/library/Icinga/Web/Announcement/AnnouncementIniRepository.php @@ -30,25 +30,6 @@ class AnnouncementIniRepository extends IniRepository 'end' => 'timestamp' )); - /** - * Create a DateTime from a timestamp - * - * @param string $timestamp - * - * @return DateTime|null - */ - protected function retrieveTimestamp($timestamp) - { - if ($timestamp !== null) { - $dateTime = new DateTime(); - $dateTime->setTimestamp($timestamp); - - return $dateTime; - } - - return null; - } - /** * Get a DateTime's timestamp * @@ -157,7 +138,7 @@ class AnnouncementIniRepository extends IniRepository $refresh = null; foreach ($query as $row) { - $min = min($row->start->getTimestamp(), $row->end->getTimestamp()); + $min = min($row->start, $row->end); if ($refresh === null) { $refresh = $min;