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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * This class contains functions for managing Status Preferences.
23 class CRM_Core_BAO_StatusPreference
extends CRM_Core_DAO_StatusPreference
{
26 * Create or update a Status Preference entry.
28 * @param array $params
32 public static function create($params) {
33 $statusPreference = new CRM_Core_BAO_StatusPreference();
35 // Default severity level to ignore is 0 (DEBUG).
36 if (!isset($params['ignore_severity'])) {
37 $params['ignore_severity'] = 0;
39 // Severity can be either text ('critical') or an integer <= 7.
40 // It's a magic number, but based on PSR-3 standards.
41 if (!CRM_Utils_Rule
::integer($params['ignore_severity'])) {
42 $params['ignore_severity'] = CRM_Utils_Check
::severityMap($params['ignore_severity']);
44 if ($params['ignore_severity'] > 7) {
45 CRM_Core_Error
::fatal(ts('You can not pass a severity level higher than 7.'));
47 // If severity is now blank, you have an invalid severity string.
48 if (is_null($params['ignore_severity'])) {
49 CRM_Core_Error
::fatal(ts('Invalid string passed as severity level.'));
52 // Check if this StatusPreference already exists.
53 if (empty($params['id']) && !empty($params['name'])) {
54 $statusPreference->domain_id
= CRM_Utils_Array
::value('domain_id', $params, CRM_Core_Config
::domainID());
55 $statusPreference->name
= $params['name'];
57 $statusPreference->find(TRUE);
60 $statusPreference->copyValues($params);
62 $edit = ($statusPreference->id
) ?
TRUE : FALSE;
64 CRM_Utils_Hook
::pre('edit', 'StatusPreference', $statusPreference->id
, $statusPreference);
67 CRM_Utils_Hook
::pre('create', 'StatusPreference', NULL, $statusPreference);
70 $statusPreference->save();
73 CRM_Utils_Hook
::post('edit', 'StatusPreference', $statusPreference->id
, $statusPreference);
76 CRM_Utils_Hook
::post('create', 'StatusPreference', NULL, $statusPreference);
79 return $statusPreference;