Merge pull request #12006 from civicrm/5.1
[civicrm-core.git] / CRM / Core / BAO / PreferencesDate.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2018
32 */
33 class CRM_Core_BAO_PreferencesDate extends CRM_Core_DAO_PreferencesDate {
34
35 /**
36 * Static holder for the default LT.
37 */
38 static $_defaultPreferencesDate = NULL;
39
40 /**
41 * Class constructor.
42 */
43 public function __construct() {
44 parent::__construct();
45 }
46
47 /**
48 * Fetch object based on array of properties.
49 *
50 * @param array $params
51 * (reference ) an assoc array of name/value pairs.
52 * @param array $defaults
53 * (reference ) an assoc array to hold the flattened values.
54 *
55 * @return CRM_Core_BAO_PreferencesDate|null
56 * object on success, null otherwise
57 */
58 public static function retrieve(&$params, &$defaults) {
59 $dao = new CRM_Core_DAO_PreferencesDate();
60 $dao->copyValues($params);
61 if ($dao->find(TRUE)) {
62 CRM_Core_DAO::storeValues($dao, $defaults);
63 return $dao;
64 }
65 return NULL;
66 }
67
68 /**
69 * Update the is_active flag in the db.
70 *
71 * @param int $id
72 * Id of the database record.
73 * @param bool $is_active
74 * Value we want to set the is_active field.
75 */
76 public static function setIsActive($id, $is_active) {
77 CRM_Core_Error::fatal();
78 }
79
80 /**
81 * Delete preference dates.
82 *
83 * @param int $id
84 */
85 public static function del($id) {
86 CRM_Core_Error::fatal();
87 }
88
89 /**
90 * (Setting Callback - On Change)
91 * Respond to changes in the "timeInputFormat" setting.
92 *
93 * @param array $oldValue
94 * List of component names.
95 * @param array $newValue
96 * List of component names.
97 * @param array $metadata
98 * Specification of the setting (per *.settings.php).
99 */
100 public static function onChangeSetting($oldValue, $newValue, $metadata) {
101 if ($oldValue == $newValue) {
102 return;
103 }
104
105 $query = "
106 UPDATE civicrm_preferences_date
107 SET time_format = %1
108 WHERE time_format IS NOT NULL
109 AND time_format <> ''
110 ";
111 $sqlParams = array(1 => array($newValue, 'String'));
112 CRM_Core_DAO::executeQuery($query, $sqlParams);
113 }
114
115 }