Commit | Line | Data |
---|---|---|
a2600a6d TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
a2600a6d | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
a2600a6d TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
a2600a6d TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
a2600a6d TO |
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 | ||
1248c859 TO |
44 | /** |
45 | * @var string | |
46 | */ | |
47 | private $title; | |
48 | ||
f0f49b45 | 49 | /** |
7d029160 | 50 | * @var int |
f0f49b45 TO |
51 | * @see Psr\Log\LogLevel |
52 | */ | |
53 | private $level; | |
54 | ||
1b366958 AH |
55 | /** |
56 | * @var string | |
57 | * help text (to be presented separately from the message) | |
58 | */ | |
59 | private $help; | |
60 | ||
46a903fb NM |
61 | /** |
62 | * | |
63 | * @var bool | |
64 | * This is used for Admin Status Page to determine hushed statuses. | |
65 | */ | |
66 | private $isVisible; | |
67 | ||
5bc392e6 | 68 | /** |
70599df6 | 69 | * Class constructor. |
70 | * | |
100fef9d | 71 | * @param string $name |
f0f49b45 TO |
72 | * Symbolic name for the check. |
73 | * @param string $message | |
74 | * Printable message (short or long). | |
75 | * @param string $title | |
76 | * Printable message (short). | |
77 | * @param string $level | |
78 | * The severity of the message. Use PSR-3 log levels. | |
79 | * | |
80 | * @see Psr\Log\LogLevel | |
5bc392e6 | 81 | */ |
f0f49b45 | 82 | public function __construct($name, $message, $title, $level = \Psr\Log\LogLevel::WARNING) { |
a2600a6d TO |
83 | $this->name = $name; |
84 | $this->message = $message; | |
1248c859 | 85 | $this->title = $title; |
70c711fe J |
86 | // Handle non-integer severity levels. |
87 | if (!CRM_Utils_Rule::integer($level)) { | |
88 | $level = CRM_Utils_Check::severityMap($level); | |
89 | } | |
f0f49b45 | 90 | $this->level = $level; |
a2600a6d TO |
91 | } |
92 | ||
93 | /** | |
70599df6 | 94 | * Get name. |
95 | * | |
a2600a6d TO |
96 | * @return string |
97 | */ | |
00be9182 | 98 | public function getName() { |
a2600a6d TO |
99 | return $this->name; |
100 | } | |
101 | ||
102 | /** | |
70599df6 | 103 | * Get message. |
104 | * | |
a2600a6d TO |
105 | * @return string |
106 | */ | |
00be9182 | 107 | public function getMessage() { |
a2600a6d TO |
108 | return $this->message; |
109 | } | |
110 | ||
1248c859 TO |
111 | /** |
112 | * @return string | |
113 | */ | |
114 | public function getTitle() { | |
115 | return $this->title; | |
116 | } | |
117 | ||
f0f49b45 | 118 | /** |
70599df6 | 119 | * Get level. |
120 | * | |
f0f49b45 TO |
121 | * @return string |
122 | * @see Psr\Log\LogLevel | |
123 | */ | |
124 | public function getLevel() { | |
125 | return $this->level; | |
126 | } | |
127 | ||
0ea9001d | 128 | /** |
129 | * Alias for Level | |
130 | * @return string | |
1b366958 | 131 | */ |
0ea9001d | 132 | public function getSeverity() { |
133 | return $this->getLevel(); | |
134 | } | |
135 | ||
1b366958 | 136 | /** |
70599df6 | 137 | * Set optional additional help text. |
138 | * | |
097c681e | 139 | * @param string $help |
1b366958 AH |
140 | */ |
141 | public function addHelp($help) { | |
142 | $this->help = $help; | |
143 | } | |
144 | ||
a2600a6d | 145 | /** |
70599df6 | 146 | * Convert to array. |
147 | * | |
a2600a6d TO |
148 | * @return array |
149 | */ | |
00be9182 | 150 | public function toArray() { |
1b366958 | 151 | $array = array( |
a2600a6d TO |
152 | 'name' => $this->name, |
153 | 'message' => $this->message, | |
1248c859 | 154 | 'title' => $this->title, |
1b366958 | 155 | 'severity' => $this->level, |
7c6fb573 | 156 | 'is_visible' => $this->isVisible, |
a2600a6d | 157 | ); |
1b366958 AH |
158 | if (!empty($this->help)) { |
159 | $array['help'] = $this->help; | |
160 | } | |
161 | return $array; | |
a2600a6d | 162 | } |
96025800 | 163 | |
70599df6 | 164 | /** |
165 | * Getter for is visible. | |
166 | * | |
167 | * @return bool | |
168 | */ | |
e918c16d | 169 | public function isVisible() { |
46a903fb NM |
170 | return $this->isVisible; |
171 | } | |
172 | ||
70599df6 | 173 | /** |
174 | * Seter for is visible. | |
175 | * | |
176 | * @param bool $isVisible | |
177 | */ | |
46a903fb | 178 | public function setVisible($isVisible) { |
890e8737 | 179 | $this->isVisible = $isVisible ? 1 : 0; |
46a903fb NM |
180 | } |
181 | ||
a2600a6d | 182 | } |