From 7cf4759fdd2b3fd13e3f656b149711752ab3f87d Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 16 Nov 2015 12:54:46 -0500 Subject: [PATCH] CRM-13823 - Add hidden_until property to messages --- CRM/Utils/Check.php | 48 ------------------------- CRM/Utils/Check/Message.php | 70 +++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 50 deletions(-) diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index b0ad2a14f4..25f7e4e2cb 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -225,52 +225,4 @@ class CRM_Utils_Check { return ($max) ? $maxSeverity : $messages; } - /** - * Evaluate if a system check should be hushed/snoozed. - * - * @param CRM_Utils_Check_Message $message - * The message to evaluate. - * - * @return bool - * TRUE means hush/snooze, FALSE means display. - * @throws \CiviCRM_API3_Exception - */ - public static function checkHushSnooze($message) { - $statusPreferenceParams = array( - 'name' => $message->getName(), - 'domain_id' => CRM_Core_Config::domainID(), - ); - // Check if there's a StatusPreference matching this name/domain. - $statusPreference = civicrm_api3('StatusPreference', 'get', $statusPreferenceParams); - $spid = FALSE; - if (isset($statusPreference['id'])) { - $spid = $statusPreference['id']; - } - if ($spid) { - // If so, compare severity to StatusPreference->severity. - $severity = $message->getSeverity(); - if ($severity <= $statusPreference['values'][$spid]['ignore_severity']) { - // A hush or a snooze has been set. Find out which. - if (isset($statusPreference['values'][$spid]['hush_until'])) { - // Snooze is set. - $today = new DateTime(); - $snoozeDate = new DateTime($statusPreference['values'][$spid]['hush_until']); - if ($today > $snoozeDate) { - // Snooze is expired. - return FALSE; - } - else { - // Snooze is active. - return TRUE; - } - } - else { - // Hush. - return TRUE; - } - } - } - return FALSE; - } - } diff --git a/CRM/Utils/Check/Message.php b/CRM/Utils/Check/Message.php index ca4efbd317..1e50c4e99a 100644 --- a/CRM/Utils/Check/Message.php +++ b/CRM/Utils/Check/Message.php @@ -64,6 +64,12 @@ class CRM_Utils_Check_Message { */ private $icon; + /** + * @var bool|string + * Date this message is hidden until + */ + private $hiddenUntil; + /** * Class constructor. * @@ -156,6 +162,9 @@ class CRM_Utils_Check_Message { 'is_visible' => (int) $this->isVisible(), 'icon' => $this->icon, ); + if ($this->getHiddenUntil()) { + $array['hidden_until'] = $this->getHiddenUntil(); + } if (!empty($this->help)) { $array['help'] = $this->help; } @@ -163,12 +172,69 @@ class CRM_Utils_Check_Message { } /** - * Check if message is visible or has been hidden by the user. + * Return message visibility. * * @return bool */ public function isVisible() { - return !CRM_Utils_Check::checkHushSnooze($this); + return !$this->checkStatusPreference(); + } + + /** + * @return string + */ + public function getHiddenUntil() { + if (!isset($this->hiddenUntil)) { + $this->checkStatusPreference(); + } + return $this->hiddenUntil; + } + + /** + * Check if message is visible or has been hidden by the user. + * + * @return bool + * TRUE means hidden, FALSE means visible. + * @throws \CiviCRM_API3_Exception + */ + private function checkStatusPreference() { + $this->hiddenUntil = FALSE; + $statusPreferenceParams = array( + 'name' => $this->getName(), + 'domain_id' => CRM_Core_Config::domainID(), + ); + // Check if there's a StatusPreference matching this name/domain. + $statusPreference = civicrm_api3('StatusPreference', 'get', $statusPreferenceParams); + $spid = FALSE; + if (isset($statusPreference['id'])) { + $spid = $statusPreference['id']; + } + if ($spid) { + // If so, compare severity to StatusPreference->severity. + $severity = $this->getSeverity(); + if ($severity <= $statusPreference['values'][$spid]['ignore_severity']) { + // A hush or a snooze has been set. Find out which. + if (isset($statusPreference['values'][$spid]['hush_until'])) { + // Snooze is set. + $this->hiddenUntil = $statusPreference['values'][$spid]['hush_until']; + $today = new DateTime(); + $snoozeDate = new DateTime($statusPreference['values'][$spid]['hush_until']); + if ($today > $snoozeDate) { + // Snooze is expired. + return FALSE; + } + else { + // Snooze is active. + return TRUE; + } + } + else { + // Hush. + return TRUE; + } + } + } + return FALSE; } } -- 2.25.1