mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Merge pull request #3068 from Icinga/feature/sort-announcements-by-date
Sort announcements by date
This commit is contained in:
commit
3fc410b8c1
@ -30,7 +30,7 @@ class AnnouncementsController extends Controller
|
|||||||
$repo = new AnnouncementIniRepository();
|
$repo = new AnnouncementIniRepository();
|
||||||
$this->view->announcements = $repo
|
$this->view->announcements = $repo
|
||||||
->select(array('id', 'author', 'message', 'start', 'end'))
|
->select(array('id', 'author', 'message', 'start', 'end'))
|
||||||
->order('start');
|
->order('start', 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,27 +16,15 @@ use Icinga\Web\Announcement;
|
|||||||
*/
|
*/
|
||||||
class AnnouncementIniRepository extends IniRepository
|
class AnnouncementIniRepository extends IniRepository
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $queryColumns = array('announcement' => array('id', 'author', 'message', 'hash', 'start', 'end'));
|
protected $queryColumns = array('announcement' => array('id', 'author', 'message', 'hash', 'start', 'end'));
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $triggers = array('announcement');
|
protected $triggers = array('announcement');
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected $configs = array('announcement' => array(
|
protected $configs = array('announcement' => array(
|
||||||
'name' => 'announcements',
|
'name' => 'announcements',
|
||||||
'keyColumn' => 'id'
|
'keyColumn' => 'id'
|
||||||
));
|
));
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
protected $conversionRules = array('announcement' => array(
|
protected $conversionRules = array('announcement' => array(
|
||||||
'start' => 'timestamp',
|
'start' => 'timestamp',
|
||||||
'end' => 'timestamp'
|
'end' => 'timestamp'
|
||||||
@ -54,8 +42,10 @@ class AnnouncementIniRepository extends IniRepository
|
|||||||
if ($timestamp !== null) {
|
if ($timestamp !== null) {
|
||||||
$dateTime = new DateTime();
|
$dateTime = new DateTime();
|
||||||
$dateTime->setTimestamp($timestamp);
|
$dateTime->setTimestamp($timestamp);
|
||||||
|
|
||||||
return $dateTime;
|
return $dateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +73,7 @@ class AnnouncementIniRepository extends IniRepository
|
|||||||
if (! isset($new->id)) {
|
if (! isset($new->id)) {
|
||||||
$new->id = uniqid();
|
$new->id = uniqid();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($new->hash)) {
|
if (! isset($new->hash)) {
|
||||||
$announcement = new Announcement($new->toArray());
|
$announcement = new Announcement($new->toArray());
|
||||||
$new->hash = $announcement->getHash();
|
$new->hash = $announcement->getHash();
|
||||||
@ -117,11 +108,14 @@ class AnnouncementIniRepository extends IniRepository
|
|||||||
public function getEtag()
|
public function getEtag()
|
||||||
{
|
{
|
||||||
$file = $this->getDataSource('announcement')->getConfigFile();
|
$file = $this->getDataSource('announcement')->getConfigFile();
|
||||||
|
|
||||||
if (@is_readable($file)) {
|
if (@is_readable($file)) {
|
||||||
$mtime = filemtime($file);
|
$mtime = filemtime($file);
|
||||||
$size = filesize($file);
|
$size = filesize($file);
|
||||||
|
|
||||||
return hash('crc32', $mtime . $size);
|
return hash('crc32', $mtime . $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +127,7 @@ class AnnouncementIniRepository extends IniRepository
|
|||||||
public function findActive()
|
public function findActive()
|
||||||
{
|
{
|
||||||
$now = new DateTime();
|
$now = new DateTime();
|
||||||
|
|
||||||
$query = $this
|
$query = $this
|
||||||
->select(array('hash', 'message'))
|
->select(array('hash', 'message'))
|
||||||
->setFilter(new FilterAnd(array(
|
->setFilter(new FilterAnd(array(
|
||||||
@ -140,6 +135,7 @@ class AnnouncementIniRepository extends IniRepository
|
|||||||
Filter::expression('end', '>=', $now)
|
Filter::expression('end', '>=', $now)
|
||||||
)))
|
)))
|
||||||
->order('start');
|
->order('start');
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,20 +147,25 @@ class AnnouncementIniRepository extends IniRepository
|
|||||||
public function findNextActive()
|
public function findNextActive()
|
||||||
{
|
{
|
||||||
$now = new DateTime();
|
$now = new DateTime();
|
||||||
|
|
||||||
$query = $this
|
$query = $this
|
||||||
->select(array('start', 'end'))
|
->select(array('start', 'end'))
|
||||||
->setFilter(Filter::matchAny(array(
|
->setFilter(Filter::matchAny(array(
|
||||||
Filter::expression('start', '>', $now), Filter::expression('end', '>', $now)
|
Filter::expression('start', '>', $now), Filter::expression('end', '>', $now)
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$refresh = null;
|
$refresh = null;
|
||||||
|
|
||||||
foreach ($query as $row) {
|
foreach ($query as $row) {
|
||||||
$min = min($row->start->getTimestamp(), $row->end->getTimestamp());
|
$min = min($row->start->getTimestamp(), $row->end->getTimestamp());
|
||||||
|
|
||||||
if ($refresh === null) {
|
if ($refresh === null) {
|
||||||
$refresh = $min;
|
$refresh = $min;
|
||||||
} else {
|
} else {
|
||||||
$refresh = min($refresh, $min);
|
$refresh = min($refresh, $min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $refresh;
|
return $refresh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user