3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
33 class CRM_Utils_Check_Message
{
51 * @see Psr\Log\LogLevel
57 * help text (to be presented separately from the message)
69 * Date this message is hidden until
77 * Symbolic name for the check.
78 * @param string $message
79 * Printable message (short or long).
80 * @param string $title
81 * Printable message (short).
82 * @param string $level
83 * The severity of the message. Use PSR-3 log levels.
85 * @see Psr\Log\LogLevel
87 public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel
::WARNING
, $icon = NULL) {
89 $this->message
= $message;
90 $this->title
= $title;
91 // Handle non-integer severity levels.
92 if (!CRM_Utils_Rule
::integer($level)) {
93 $level = CRM_Utils_Check
::severityMap($level);
95 $this->level
= $level;
104 public function getName() {
113 public function getMessage() {
114 return $this->message
;
120 public function getTitle() {
128 * @see Psr\Log\LogLevel
130 public function getLevel() {
138 public function getSeverity() {
139 return $this->getLevel();
143 * Set optional additional help text.
145 * @param string $help
147 public function addHelp($help) {
156 public function toArray() {
158 'name' => $this->name
,
159 'message' => $this->message
,
160 'title' => $this->title
,
161 'severity' => CRM_Utils_Check
::severityMap($this->level
, TRUE),
162 'severity_id' => $this->level
,
163 'is_visible' => (int) $this->isVisible(),
164 'icon' => $this->icon
,
166 if ($this->getHiddenUntil()) {
167 $array['hidden_until'] = $this->getHiddenUntil();
169 if (!empty($this->help
)) {
170 $array['help'] = $this->help
;
176 * Return message visibility.
180 public function isVisible() {
181 return !$this->checkStatusPreference();
187 public function getHiddenUntil() {
188 if (!isset($this->hiddenUntil
)) {
189 $this->checkStatusPreference();
191 return $this->hiddenUntil
;
195 * Check if message is visible or has been hidden by the user.
198 * TRUE means hidden, FALSE means visible.
199 * @throws \CiviCRM_API3_Exception
201 private function checkStatusPreference() {
202 $this->hiddenUntil
= FALSE;
203 $statusPreferenceParams = array(
204 'name' => $this->getName(),
205 'domain_id' => CRM_Core_Config
::domainID(),
207 // Check if there's a StatusPreference matching this name/domain.
208 $statusPreference = civicrm_api3('StatusPreference', 'get', $statusPreferenceParams);
210 if (isset($statusPreference['id'])) {
211 $spid = $statusPreference['id'];
214 // If so, compare severity to StatusPreference->severity.
215 $severity = $this->getSeverity();
216 if ($severity <= $statusPreference['values'][$spid]['ignore_severity']) {
217 // A hush or a snooze has been set. Find out which.
218 if (isset($statusPreference['values'][$spid]['hush_until'])) {
220 $this->hiddenUntil
= $statusPreference['values'][$spid]['hush_until'];
221 $today = new DateTime();
222 $snoozeDate = new DateTime($statusPreference['values'][$spid]['hush_until']);
223 if ($today > $snoozeDate) {
224 // Snooze is expired.