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 * Has this message been suppressed?
75 * Date this message is hidden until
83 * Symbolic name for the check.
84 * @param string $message
85 * Printable message (short or long).
86 * @param string $title
87 * Printable message (short).
88 * @param string $level
89 * The severity of the message. Use PSR-3 log levels.
91 * @see Psr\Log\LogLevel
93 * @throws \CRM_Core_Exception
95 public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel
::WARNING
, $icon = NULL) {
97 $this->message
= $message;
98 $this->title
= $title;
100 $this->setLevel($level);
108 public function getName() {
117 public function getMessage() {
118 return $this->message
;
124 public function getTitle() {
129 * Get severity level number.
132 * @see Psr\Log\LogLevel
134 public function getLevel() {
139 * Get severity string.
142 * @see Psr\Log\LogLevel
144 public function getSeverity() {
145 return CRM_Utils_Check
::severityMap($this->level
, TRUE);
149 * Set optional additional help text.
151 * @param string $help
153 public function addHelp($help) {
160 * @param string|int $level
161 * @throws \CRM_Core_Exception
163 public function setLevel($level) {
164 // Convert level to integer
165 if (!CRM_Utils_Rule
::positiveInteger($level)) {
166 $level = CRM_Utils_Check
::severityMap($level);
169 // Validate numeric input - this will throw an exception if invalid
170 CRM_Utils_Check
::severityMap($level, TRUE);
172 $this->level
= $level;
173 // Clear internal caches
174 unset($this->isVisible
, $this->hiddenUntil
);
182 public function toArray() {
184 'name' => $this->name
,
185 'message' => $this->message
,
186 'title' => $this->title
,
187 'severity' => $this->getSeverity(),
188 'severity_id' => $this->level
,
189 'is_visible' => (int) $this->isVisible(),
190 'icon' => $this->icon
,
192 if ($this->getHiddenUntil()) {
193 $array['hidden_until'] = $this->getHiddenUntil();
195 if (!empty($this->help
)) {
196 $array['help'] = $this->help
;
202 * Get message visibility.
206 public function isVisible() {
207 if (!isset($this->isVisible
)) {
208 $this->isVisible
= !$this->checkStatusPreference();
210 return $this->isVisible
;
214 * Get date hidden until.
218 public function getHiddenUntil() {
219 if (!isset($this->hiddenUntil
)) {
220 $this->checkStatusPreference();
222 return $this->hiddenUntil
;
226 * Check if message is visible or has been hidden by the user.
228 * Also populates this->hiddenUntil property.
231 * TRUE means hidden, FALSE means visible.
232 * @throws \CiviCRM_API3_Exception
234 private function checkStatusPreference() {
235 $this->hiddenUntil
= FALSE;
236 $statusPreferenceParams = array(
237 'name' => $this->getName(),
238 'domain_id' => CRM_Core_Config
::domainID(),
240 // Check if there's a StatusPreference matching this name/domain.
241 $statusPreference = civicrm_api3('StatusPreference', 'get', $statusPreferenceParams);
243 if (isset($statusPreference['id'])) {
244 $spid = $statusPreference['id'];
247 // If so, compare severity to StatusPreference->severity.
248 if ($this->level
<= $statusPreference['values'][$spid]['ignore_severity']) {
249 // A hush or a snooze has been set. Find out which.
250 if (isset($statusPreference['values'][$spid]['hush_until'])) {
252 $this->hiddenUntil
= $statusPreference['values'][$spid]['hush_until'];
253 $today = new DateTime();
254 $snoozeDate = new DateTime($statusPreference['values'][$spid]['hush_until']);
255 if ($today > $snoozeDate) {
256 // Snooze is expired.