Merge pull request #6957 from jdax/CRM_13823_Admin_Status_Page
[civicrm-core.git] / CRM / Utils / Check / Message.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 */
33 class CRM_Utils_Check_Message {
34 /**
35 * @var string
36 */
37 private $name;
38
39 /**
40 * @var string
41 */
42 private $message;
43
44 /**
45 * @var string
46 */
47 private $title;
48
49 /**
50 * @var int
51 * @see Psr\Log\LogLevel
52 */
53 private $level;
54
55 /**
56 * @var string
57 * help text (to be presented separately from the message)
58 */
59 private $help;
60
61 /**
62 *
63 * @var bool
64 * This is used for Admin Status Page to determine hushed statuses.
65 */
66 private $isVisible;
67
68 /**
69 * @param string $name
70 * Symbolic name for the check.
71 * @param string $message
72 * Printable message (short or long).
73 * @param string $title
74 * Printable message (short).
75 * @param string $level
76 * The severity of the message. Use PSR-3 log levels.
77 *
78 * @see Psr\Log\LogLevel
79 */
80 public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING) {
81 $this->name = $name;
82 $this->message = $message;
83 $this->title = $title;
84 // Handle non-integer severity levels.
85 if (!CRM_Utils_Rule::integer($level)) {
86 $level = CRM_Utils_Check::severityMap($level);
87 }
88 $this->level = $level;
89 }
90
91 /**
92 * @return string
93 */
94 public function getName() {
95 return $this->name;
96 }
97
98 /**
99 * @return string
100 */
101 public function getMessage() {
102 return $this->message;
103 }
104
105 /**
106 * @return string
107 */
108 public function getTitle() {
109 return $this->title;
110 }
111
112 /**
113 * @return string
114 * @see Psr\Log\LogLevel
115 */
116 public function getLevel() {
117 return $this->level;
118 }
119
120 /**
121 * Alias for Level
122 * @return string
123 */
124 public function getSeverity() {
125 return $this->getLevel();
126 }
127
128 /**
129 * Set optional additional help text
130 * @param string $help
131 */
132 public function addHelp($help) {
133 $this->help = $help;
134 }
135
136 /**
137 * @return array
138 */
139 public function toArray() {
140 $array = array(
141 'name' => $this->name,
142 'message' => $this->message,
143 'title' => $this->title,
144 'severity' => $this->level,
145 'is_visible' => $this->isVisible,
146 );
147 if (!empty($this->help)) {
148 $array['help'] = $this->help;
149 }
150 return $array;
151 }
152
153 public function isVisible() {
154 return $this->isVisible;
155 }
156
157 public function setVisible($isVisible) {
158 $this->isVisible = $isVisible ? 1 : 0;
159 }
160
161 }