From b46bfdd4921e27ed472aabfd06ab7c95f30e7e62 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 29 Dec 2008 00:35:31 +0000 Subject: Separate permanent messages out of the message helper and put them into site_status. Show site status in the header in the admin theme. --- core/helpers/graphics.php | 7 ++- core/helpers/message.php | 60 +++++--------------- core/helpers/site_status.php | 129 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 50 deletions(-) create mode 100644 core/helpers/site_status.php (limited to 'core/helpers') diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php index 62bde88a..8f0bb6a3 100644 --- a/core/helpers/graphics.php +++ b/core/helpers/graphics.php @@ -156,10 +156,11 @@ class graphics_Core { $count = self::find_dirty_images_query()->count(); if ($count) { - message::warning( + site_status::warning( sprintf(_("%d of your photos are out of date. %sClick here to fix them%s"), $count, "", ""), "graphics_dirty"); } @@ -204,7 +205,7 @@ class graphics_Core { if ($remaining == 0) { $task->done = true; $task->state = "success"; - message::clear_permanent("graphics_dirty"); + site_status::clear("graphics_dirty"); } } } diff --git a/core/helpers/message.php b/core/helpers/message.php index 25d7c150..206ba212 100644 --- a/core/helpers/message.php +++ b/core/helpers/message.php @@ -26,36 +26,32 @@ class message_Core { /** * Report a successful event. * @param string $msg a detailed message - * @param string $permanent_key make this message permanent and store it under this key */ - public static function success($msg, $permanent_key=null) { - self::add($msg, self::SUCCESS, $permanent_key); + public static function success($msg) { + self::add($msg, self::SUCCESS); } /** * Report an informational event. * @param string $msg a detailed message - * @param string $permanent_key make this message permanent and store it under this key */ - public static function info($msg, $permanent_key=null) { + public static function info($msg) { self::add($msg, self::INFO, $permanent_key); } /** * Report that something went wrong, not fatal, but worth investigation. * @param string $msg a detailed message - * @param string $permanent_key make this message permanent and store it under this key */ - public static function warning($msg, $permanent_key=null) { + public static function warning($msg) { self::add($msg, self::WARNING, $permanent_key); } /** * Report that something went wrong that should be fixed. * @param string $msg a detailed message - * @param string $permanent_key make this message permanent and store it under this key */ - public static function error($msg, $permanent_key=null) { + public static function error($msg) { self::add($msg, self::ERROR, $permanent_key); } @@ -63,36 +59,12 @@ class message_Core { * Save a message in the session for our next page load. * @param string $msg a detailed message * @param integer $severity one of the severity constants - * @param string $permanent_key make this message permanent and store it under this key */ - private function add($msg, $severity, $permanent_key=null) { - if ($permanent_key) { - $message = ORM::factory("message") - ->where("key", $permanent_key) - ->find(); - if (!$message->loaded) { - $message->key = $permanent_key; - } - $message->severity = $severity; - $message->value = $msg; - $message->save(); - } else { - $session = Session::instance(); - $status = $session->get("messages"); - $status[] = array($msg, $severity); - $session->set("messages", $status); - } - } - - /** - * Remove any permanent message by key. - * @param string $permanent_key - */ - public function clear_permanent($permanent_key) { - $message = ORM::factory("message")->where("key", $permanent_key)->find(); - if ($message->loaded) { - $message->delete(); - } + private function add($msg, $severity) { + $session = Session::instance(); + $status = $session->get("messages"); + $status[] = array($msg, $severity); + $session->set("messages", $status); } /** @@ -104,18 +76,12 @@ class message_Core { public function get() { $buf = array(); - foreach (Session::instance()->get_once("messages", array()) as $msg) { + $messages = Session::instance()->get_once("messages", array()); + foreach ($messages as $msg) { $buf[] = "
  • $msg[0]
  • "; } - - if (user::active()->admin) { - foreach (ORM::factory("message")->find_all() as $msg) { - $buf[] = "
  • severity) . "\">$msg->value
  • "; - } - } - if ($buf) { - return ""; + return ""; } } diff --git a/core/helpers/site_status.php b/core/helpers/site_status.php new file mode 100644 index 00000000..ccddd3fb --- /dev/null +++ b/core/helpers/site_status.php @@ -0,0 +1,129 @@ +where("key", $permanent_key) + ->find(); + if (!$message->loaded) { + $message->key = $permanent_key; + } + $message->severity = $severity; + $message->value = $msg; + $message->save(); + } + + /** + * Remove any permanent message by key. + * @param string $permanent_key + */ + public function clear($permanent_key) { + $message = ORM::factory("message")->where("key", $permanent_key)->find(); + if ($message->loaded) { + $message->delete(); + } + } + + /** + * Get any pending messages. There are two types of messages, transient and permanent. + * Permanent messages are used to let the admin know that there are pending administrative + * issues that need to be resolved. Transient ones are only displayed once. + * @return html text + */ + public function get() { + $buf = array(); + + foreach (ORM::factory("message")->find_all() as $msg) { + $buf[] = "
  • severity) . "\">$msg->value
  • "; + } + + if ($buf) { + return ""; + } + } + + /** + * Convert a message severity to a CSS class + * @param integer $severity + * @return string + */ + public function severity_class($severity) { + switch($severity) { + case self::SUCCESS: + return "gSuccess"; + + case self::INFO: + return "gInfo"; + + case self::WARNING: + return "gWarning"; + + case self::ERROR: + return "gError"; + } + } +} -- cgit v1.2.3