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