[icinga-checkins] icinga.org: icingaweb2/feature/announce-banner-11198: Show all users all announces as notifications

git at icinga.org git at icinga.org
Fri Oct 28 18:51:30 CEST 2016


Module: icingaweb2
Branch: feature/announce-banner-11198
Commit: d57912df9167b34ffdfc5c5fe16f5963b5c4e903
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=d57912df9167b34ffdfc5c5fe16f5963b5c4e903

Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date:   Fri Oct 28 18:51:21 2016 +0200

Show all users all announces as notifications

refs #11198

---

 library/Icinga/Application/Web.php |   33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php
index 1900ecd..96270c6 100644
--- a/library/Icinga/Application/Web.php
+++ b/library/Icinga/Application/Web.php
@@ -5,6 +5,10 @@ namespace Icinga\Application;
 
 require_once __DIR__ . '/EmbeddedWeb.php';
 
+use DateTime;
+use Icinga\Data\Filter\Filter;
+use Icinga\Data\Filter\FilterAnd;
+use Icinga\Repository\AnnounceIniRepository;
 use Zend_Controller_Action_HelperBroker;
 use Zend_Controller_Front;
 use Zend_Controller_Router_Route;
@@ -96,7 +100,8 @@ class Web extends EmbeddedWeb
             ->setupUser()
             ->setupTimezone()
             ->setupLogger()
-            ->setupInternationalization();
+            ->setupInternationalization()
+            ->showAnnounces();
     }
 
     /**
@@ -557,4 +562,30 @@ class Web extends EmbeddedWeb
         }
         return Translator::DEFAULT_LOCALE;
     }
+
+    /**
+     * Show the user all announces as notifications
+     *
+     * @return $this
+     */
+    protected function showAnnounces()
+    {
+        if (! Icinga::app()->getRequest()->isXmlHttpRequest()) {
+            $repo = new AnnounceIniRepository();
+            $now = new DateTime();
+            $query = $repo
+                ->select(array('message'))
+                ->applyFilter(new FilterAnd(array(
+                    Filter::expression('start', '<=', $now),
+                    Filter::expression('end', '>=', $now)
+                )))
+                ->order('start');
+
+            foreach ($query->fetchColumn() as $message) {
+                Notification::info($message);
+            }
+        }
+
+        return $this;
+    }
 }



More information about the icinga-checkins mailing list