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;
- }
-
}
*/
private $icon;
+ /**
+ * @var bool|string
+ * Date this message is hidden until
+ */
+ private $hiddenUntil;
+
/**
* Class constructor.
*
'is_visible' => (int) $this->isVisible(),
'icon' => $this->icon,
);
+ if ($this->getHiddenUntil()) {
+ $array['hidden_until'] = $this->getHiddenUntil();
+ }
if (!empty($this->help)) {
$array['help'] = $this->help;
}
}
/**
- * 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;
}
}