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 | /** | |
f602804e | 13 | * @package CRM |
ca5cec67 | 14 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
f602804e J |
15 | */ |
16 | ||
17 | /** | |
5720fd54 | 18 | * This class contains functions for managing Status Preferences. |
f602804e J |
19 | */ |
20 | class CRM_Core_BAO_StatusPreference extends CRM_Core_DAO_StatusPreference { | |
21 | ||
22 | /** | |
23 | * Create or update a Status Preference entry. | |
24 | * | |
25 | * @param array $params | |
26 | * | |
fcb37cd5 | 27 | * @return CRM_Core_DAO_StatusPreference |
ac15829d | 28 | * @throws CRM_Core_Exception |
f602804e J |
29 | */ |
30 | public static function create($params) { | |
fcb37cd5 | 31 | $statusPreference = new CRM_Core_DAO_StatusPreference(); |
aacaa119 | 32 | |
a24a0be0 | 33 | // Default severity level to ignore is 0 (DEBUG). |
fcb37cd5 CW |
34 | $params['ignore_severity'] = $params['ignore_severity'] ?? 0; |
35 | ||
a24a0be0 | 36 | // Severity can be either text ('critical') or an integer <= 7. |
0ef4ffda | 37 | // It's a magic number, but based on PSR-3 standards. |
a24a0be0 J |
38 | if (!CRM_Utils_Rule::integer($params['ignore_severity'])) { |
39 | $params['ignore_severity'] = CRM_Utils_Check::severityMap($params['ignore_severity']); | |
5720fd54 | 40 | } |
a24a0be0 | 41 | if ($params['ignore_severity'] > 7) { |
ac15829d | 42 | throw new CRM_Core_Exception(ts('You can not pass a severity level higher than 7.')); |
0ef4ffda J |
43 | } |
44 | // If severity is now blank, you have an invalid severity string. | |
a4bceabb | 45 | if (is_null($params['ignore_severity'])) { |
ac15829d | 46 | throw new CRM_Core_Exception(ts('Invalid string passed as severity level.')); |
5720fd54 J |
47 | } |
48 | ||
fcb37cd5 CW |
49 | // Set default domain when creating (or updating by name) |
50 | if (empty($params['id']) && empty($params['domain_id'])) { | |
51 | $params['domain_id'] = CRM_Core_Config::domainID(); | |
52 | } | |
53 | ||
54 | // Enforce unique status pref names. Update if a duplicate name is found in the same domain. | |
de6c59ca | 55 | if (empty($params['id']) && !empty($params['name'])) { |
fcb37cd5 | 56 | $statusPreference->domain_id = $params['domain_id']; |
aa96ce62 | 57 | $statusPreference->name = $params['name']; |
aacaa119 | 58 | $statusPreference->find(TRUE); |
f602804e J |
59 | } |
60 | ||
fcb37cd5 CW |
61 | $op = $statusPreference->id ? 'edit' : 'create'; |
62 | CRM_Utils_Hook::pre($op, 'StatusPreference', $statusPreference->id, $params); | |
f602804e | 63 | |
fcb37cd5 | 64 | $statusPreference->copyValues($params); |
f602804e J |
65 | $statusPreference->save(); |
66 | ||
fcb37cd5 | 67 | CRM_Utils_Hook::post($op, 'StatusPreference', $statusPreference->id, $statusPreference); |
f602804e J |
68 | |
69 | return $statusPreference; | |
70 | } | |
71 | ||
72 | } |