827613da60caf47cccad1274d1e2e9a75f4b7607
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;
99 // Convert level to integer
100 if (!CRM_Utils_Rule
::positiveInteger($level)) {
101 $level = CRM_Utils_Check
::severityMap($level);
104 // Validate numeric input - this will throw an exception if invalid
105 CRM_Utils_Check
::severityMap($level, TRUE);
107 $this->level
= $level;
116 public function getName() {
125 public function getMessage() {
126 return $this->message
;
132 public function getTitle() {
137 * Get severity level number.
140 * @see Psr\Log\LogLevel
142 public function getLevel() {
147 * Get severity string.
150 * @see Psr\Log\LogLevel
152 public function getSeverity() {
153 return CRM_Utils_Check
::severityMap($this->level
, TRUE);
157 * Set optional additional help text.
159 * @param string $help
161 public function addHelp($help) {
170 public function toArray() {
172 'name' => $this->name
,
173 'message' => $this->message
,
174 'title' => $this->title
,
175 'severity' => $this->getSeverity(),
176 'severity_id' => $this->level
,
177 'is_visible' => (int) $this->isVisible(),
178 'icon' => $this->icon
,
180 if ($this->getHiddenUntil()) {
181 $array['hidden_until'] = $this->getHiddenUntil();
183 if (!empty($this->help
)) {
184 $array['help'] = $this->help
;
190 * Get message visibility.
194 public function isVisible() {
195 if (!isset($this->isVisible
)) {
196 $this->isVisible
= !$this->checkStatusPreference();
198 return $this->isVisible
;
202 * Get date hidden until.
206 public function getHiddenUntil() {
207 if (!isset($this->hiddenUntil
)) {
208 $this->checkStatusPreference();
210 return $this->hiddenUntil
;
214 * Check if message is visible or has been hidden by the user.
216 * Also populates this->hiddenUntil property.
219 * TRUE means hidden, FALSE means visible.
220 * @throws \CiviCRM_API3_Exception
222 private function checkStatusPreference() {
223 $this->hiddenUntil
= FALSE;
224 $statusPreferenceParams = array(
225 'name' => $this->getName(),
226 'domain_id' => CRM_Core_Config
::domainID(),
228 // Check if there's a StatusPreference matching this name/domain.
229 $statusPreference = civicrm_api3('StatusPreference', 'get', $statusPreferenceParams);
231 if (isset($statusPreference['id'])) {
232 $spid = $statusPreference['id'];
235 // If so, compare severity to StatusPreference->severity.
236 if ($this->level
<= $statusPreference['values'][$spid]['ignore_severity']) {
237 // A hush or a snooze has been set. Find out which.
238 if (isset($statusPreference['values'][$spid]['hush_until'])) {
240 $this->hiddenUntil
= $statusPreference['values'][$spid]['hush_until'];
241 $today = new DateTime();
242 $snoozeDate = new DateTime($statusPreference['values'][$spid]['hush_until']);
243 if ($today > $snoozeDate) {
244 // Snooze is expired.