3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
37 * This class contains functions for managing Status Preferences.
39 class CRM_Core_BAO_StatusPreference
extends CRM_Core_DAO_StatusPreference
{
42 * Create or update a Status Preference entry.
44 * @param array $params
48 public static function create($params) {
49 $statusPreference = new CRM_Core_BAO_StatusPreference();
51 // Default severity level to ignore is 0 (DEBUG).
52 if (!isset($params['ignore_severity'])) {
53 $params['ignore_severity'] = 0;
55 // Severity can be either text ('critical') or an integer <= 7.
56 // It's a magic number, but based on PSR-3 standards.
57 if (!CRM_Utils_Rule
::integer($params['ignore_severity'])) {
58 $params['ignore_severity'] = CRM_Utils_Check
::severityMap($params['ignore_severity']);
60 if ($params['ignore_severity'] > 7) {
61 CRM_Core_Error
::fatal(ts('You can not pass a severity level higher than 7.'));
63 // If severity is now blank, you have an invalid severity string.
64 if (is_null($params['ignore_severity'])) {
65 CRM_Core_Error
::fatal(ts('Invalid string passed as severity level.'));
68 // Check if this StatusPreference already exists.
69 if (empty($params['id']) && CRM_Utils_Array
::value('name', $params)) {
70 $statusPreference->domain_id
= CRM_Utils_Array
::value('domain_id', $params, CRM_Core_Config
::domainID());
71 $statusPreference->name
= $params['name'];
73 $statusPreference->find(TRUE);
76 $statusPreference->copyValues($params);
78 $edit = ($statusPreference->id
) ?
TRUE : FALSE;
80 CRM_Utils_Hook
::pre('edit', 'StatusPreference', $statusPreference->id
, $statusPreference);
83 CRM_Utils_Hook
::pre('create', 'StatusPreference', NULL, $statusPreference);
86 $statusPreference->save();
89 CRM_Utils_Hook
::post('edit', 'StatusPreference', $statusPreference->id
, $statusPreference);
92 CRM_Utils_Hook
::post('create', 'StatusPreference', NULL, $statusPreference);
95 return $statusPreference;