name = $name; $this->message = $message; $this->title = $title; // Handle non-integer severity levels. if (!CRM_Utils_Rule::integer($level)) { $level = CRM_Utils_Check::severityMap($level); } $this->level = $level; $this->icon = $icon; } /** * Get name. * * @return string */ public function getName() { return $this->name; } /** * Get message. * * @return string */ public function getMessage() { return $this->message; } /** * @return string */ public function getTitle() { return $this->title; } /** * Get level. * * @return string * @see Psr\Log\LogLevel */ public function getLevel() { return $this->level; } /** * Alias for Level * @return string */ public function getSeverity() { return $this->getLevel(); } /** * Set optional additional help text. * * @param string $help */ public function addHelp($help) { $this->help = $help; } /** * Convert to array. * * @return array */ public function toArray() { $array = array( 'name' => $this->name, 'message' => $this->message, 'title' => $this->title, 'severity' => CRM_Utils_Check::severityMap($this->level, TRUE), 'severity_id' => $this->level, 'is_visible' => (int) $this->isVisible(), 'icon' => $this->icon, ); if ($this->getHiddenUntil()) { $array['hidden_until'] = $this->getHiddenUntil(); } if (!empty($this->help)) { $array['help'] = $this->help; } return $array; } /** * Return message visibility. * * @return bool */ public function isVisible() { 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; } }