Commit | Line | Data |
---|---|---|
f602804e J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
f602804e | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
f602804e J |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
f602804e J |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
5720fd54 | 21 | * This class contains functions for managing Status Preferences. |
f602804e J |
22 | */ |
23 | class CRM_Core_BAO_StatusPreference extends CRM_Core_DAO_StatusPreference { | |
24 | ||
25 | /** | |
26 | * Create or update a Status Preference entry. | |
27 | * | |
28 | * @param array $params | |
29 | * | |
30 | * @return array | |
31 | */ | |
32 | public static function create($params) { | |
06576a03 | 33 | $statusPreference = new CRM_Core_BAO_StatusPreference(); |
aacaa119 | 34 | |
a24a0be0 | 35 | // Default severity level to ignore is 0 (DEBUG). |
cef07224 | 36 | if (!isset($params['ignore_severity'])) { |
a24a0be0 | 37 | $params['ignore_severity'] = 0; |
0ef4ffda | 38 | } |
a24a0be0 | 39 | // Severity can be either text ('critical') or an integer <= 7. |
0ef4ffda | 40 | // It's a magic number, but based on PSR-3 standards. |
a24a0be0 J |
41 | if (!CRM_Utils_Rule::integer($params['ignore_severity'])) { |
42 | $params['ignore_severity'] = CRM_Utils_Check::severityMap($params['ignore_severity']); | |
5720fd54 | 43 | } |
a24a0be0 J |
44 | if ($params['ignore_severity'] > 7) { |
45 | CRM_Core_Error::fatal(ts('You can not pass a severity level higher than 7.')); | |
0ef4ffda J |
46 | } |
47 | // If severity is now blank, you have an invalid severity string. | |
a4bceabb | 48 | if (is_null($params['ignore_severity'])) { |
0ef4ffda | 49 | CRM_Core_Error::fatal(ts('Invalid string passed as severity level.')); |
5720fd54 J |
50 | } |
51 | ||
52 | // Check if this StatusPreference already exists. | |
de6c59ca | 53 | if (empty($params['id']) && !empty($params['name'])) { |
aa96ce62 AH |
54 | $statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID()); |
55 | $statusPreference->name = $params['name']; | |
aacaa119 AH |
56 | |
57 | $statusPreference->find(TRUE); | |
f602804e J |
58 | } |
59 | ||
60 | $statusPreference->copyValues($params); | |
61 | ||
62 | $edit = ($statusPreference->id) ? TRUE : FALSE; | |
63 | if ($edit) { | |
64 | CRM_Utils_Hook::pre('edit', 'StatusPreference', $statusPreference->id, $statusPreference); | |
65 | } | |
66 | else { | |
67 | CRM_Utils_Hook::pre('create', 'StatusPreference', NULL, $statusPreference); | |
68 | } | |
69 | ||
70 | $statusPreference->save(); | |
71 | ||
72 | if ($edit) { | |
73 | CRM_Utils_Hook::post('edit', 'StatusPreference', $statusPreference->id, $statusPreference); | |
74 | } | |
75 | else { | |
76 | CRM_Utils_Hook::post('create', 'StatusPreference', NULL, $statusPreference); | |
77 | } | |
78 | ||
79 | return $statusPreference; | |
80 | } | |
81 | ||
82 | } |