3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * This class contains functions for managing Status Preferences.
20 class CRM_Core_BAO_StatusPreference
extends CRM_Core_DAO_StatusPreference
{
23 * Create or update a Status Preference entry.
25 * @param array $params
27 * @return CRM_Core_DAO_StatusPreference
28 * @throws CRM_Core_Exception
30 public static function create($params) {
31 $statusPreference = new CRM_Core_DAO_StatusPreference();
33 // Default severity level to ignore is 0 (DEBUG).
34 $params['ignore_severity'] = $params['ignore_severity'] ??
0;
36 // Severity can be either text ('critical') or an integer <= 7.
37 // It's a magic number, but based on PSR-3 standards.
38 if (!CRM_Utils_Rule
::integer($params['ignore_severity'])) {
39 $params['ignore_severity'] = CRM_Utils_Check
::severityMap($params['ignore_severity']);
41 if ($params['ignore_severity'] > 7) {
42 throw new CRM_Core_Exception(ts('You can not pass a severity level higher than 7.'));
44 // If severity is now blank, you have an invalid severity string.
45 if (is_null($params['ignore_severity'])) {
46 throw new CRM_Core_Exception(ts('Invalid string passed as severity level.'));
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();
54 // Enforce unique status pref names. Update if a duplicate name is found in the same domain.
55 if (empty($params['id']) && !empty($params['name'])) {
56 $statusPreference->domain_id
= $params['domain_id'];
57 $statusPreference->name
= $params['name'];
58 $statusPreference->find(TRUE);
61 $op = $statusPreference->id ?
'edit' : 'create';
62 CRM_Utils_Hook
::pre($op, 'StatusPreference', $statusPreference->id
, $params);
64 $statusPreference->copyValues($params);
65 $statusPreference->save();
67 CRM_Utils_Hook
::post($op, 'StatusPreference', $statusPreference->id
, $statusPreference);
69 return $statusPreference;