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 | |
ac15829d | 31 | * @throws CRM_Core_Exception |
f602804e J |
32 | */ |
33 | public static function create($params) { | |
06576a03 | 34 | $statusPreference = new CRM_Core_BAO_StatusPreference(); |
aacaa119 | 35 | |
a24a0be0 | 36 | // Default severity level to ignore is 0 (DEBUG). |
cef07224 | 37 | if (!isset($params['ignore_severity'])) { |
a24a0be0 | 38 | $params['ignore_severity'] = 0; |
0ef4ffda | 39 | } |
a24a0be0 | 40 | // Severity can be either text ('critical') or an integer <= 7. |
0ef4ffda | 41 | // It's a magic number, but based on PSR-3 standards. |
a24a0be0 J |
42 | if (!CRM_Utils_Rule::integer($params['ignore_severity'])) { |
43 | $params['ignore_severity'] = CRM_Utils_Check::severityMap($params['ignore_severity']); | |
5720fd54 | 44 | } |
a24a0be0 | 45 | if ($params['ignore_severity'] > 7) { |
ac15829d | 46 | throw new CRM_Core_Exception(ts('You can not pass a severity level higher than 7.')); |
0ef4ffda J |
47 | } |
48 | // If severity is now blank, you have an invalid severity string. | |
a4bceabb | 49 | if (is_null($params['ignore_severity'])) { |
ac15829d | 50 | throw new CRM_Core_Exception(ts('Invalid string passed as severity level.')); |
5720fd54 J |
51 | } |
52 | ||
53 | // Check if this StatusPreference already exists. | |
de6c59ca | 54 | if (empty($params['id']) && !empty($params['name'])) { |
aa96ce62 AH |
55 | $statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID()); |
56 | $statusPreference->name = $params['name']; | |
aacaa119 AH |
57 | |
58 | $statusPreference->find(TRUE); | |
f602804e J |
59 | } |
60 | ||
61 | $statusPreference->copyValues($params); | |
62 | ||
63d76404 | 63 | $edit = (bool) $statusPreference->id; |
f602804e J |
64 | if ($edit) { |
65 | CRM_Utils_Hook::pre('edit', 'StatusPreference', $statusPreference->id, $statusPreference); | |
66 | } | |
67 | else { | |
68 | CRM_Utils_Hook::pre('create', 'StatusPreference', NULL, $statusPreference); | |
69 | } | |
70 | ||
71 | $statusPreference->save(); | |
72 | ||
73 | if ($edit) { | |
74 | CRM_Utils_Hook::post('edit', 'StatusPreference', $statusPreference->id, $statusPreference); | |
75 | } | |
76 | else { | |
77 | CRM_Utils_Hook::post('create', 'StatusPreference', NULL, $statusPreference); | |
78 | } | |
79 | ||
80 | return $statusPreference; | |
81 | } | |
82 | ||
83 | } |