Commit | Line | Data |
---|---|---|
f602804e J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
f602804e | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
f602804e J |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
f602804e J |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
5720fd54 | 37 | * This class contains functions for managing Status Preferences. |
f602804e J |
38 | */ |
39 | class CRM_Core_BAO_StatusPreference extends CRM_Core_DAO_StatusPreference { | |
40 | ||
41 | /** | |
42 | * Create or update a Status Preference entry. | |
43 | * | |
44 | * @param array $params | |
45 | * | |
46 | * @return array | |
47 | */ | |
48 | public static function create($params) { | |
06576a03 | 49 | $statusPreference = new CRM_Core_BAO_StatusPreference(); |
aacaa119 | 50 | |
a24a0be0 | 51 | // Default severity level to ignore is 0 (DEBUG). |
cef07224 | 52 | if (!isset($params['ignore_severity'])) { |
a24a0be0 | 53 | $params['ignore_severity'] = 0; |
0ef4ffda | 54 | } |
a24a0be0 | 55 | // Severity can be either text ('critical') or an integer <= 7. |
0ef4ffda | 56 | // It's a magic number, but based on PSR-3 standards. |
a24a0be0 J |
57 | if (!CRM_Utils_Rule::integer($params['ignore_severity'])) { |
58 | $params['ignore_severity'] = CRM_Utils_Check::severityMap($params['ignore_severity']); | |
5720fd54 | 59 | } |
a24a0be0 J |
60 | if ($params['ignore_severity'] > 7) { |
61 | CRM_Core_Error::fatal(ts('You can not pass a severity level higher than 7.')); | |
0ef4ffda J |
62 | } |
63 | // If severity is now blank, you have an invalid severity string. | |
a4bceabb | 64 | if (is_null($params['ignore_severity'])) { |
0ef4ffda | 65 | CRM_Core_Error::fatal(ts('Invalid string passed as severity level.')); |
5720fd54 J |
66 | } |
67 | ||
68 | // Check if this StatusPreference already exists. | |
aacaa119 | 69 | if (empty($params['id']) && CRM_Utils_Array::value('name', $params)) { |
aa96ce62 AH |
70 | $statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID()); |
71 | $statusPreference->name = $params['name']; | |
aacaa119 AH |
72 | |
73 | $statusPreference->find(TRUE); | |
f602804e J |
74 | } |
75 | ||
76 | $statusPreference->copyValues($params); | |
77 | ||
78 | $edit = ($statusPreference->id) ? TRUE : FALSE; | |
79 | if ($edit) { | |
80 | CRM_Utils_Hook::pre('edit', 'StatusPreference', $statusPreference->id, $statusPreference); | |
81 | } | |
82 | else { | |
83 | CRM_Utils_Hook::pre('create', 'StatusPreference', NULL, $statusPreference); | |
84 | } | |
85 | ||
86 | $statusPreference->save(); | |
87 | ||
88 | if ($edit) { | |
89 | CRM_Utils_Hook::post('edit', 'StatusPreference', $statusPreference->id, $statusPreference); | |
90 | } | |
91 | else { | |
92 | CRM_Utils_Hook::post('create', 'StatusPreference', NULL, $statusPreference); | |
93 | } | |
94 | ||
95 | return $statusPreference; | |
96 | } | |
97 | ||
98 | } |