| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * |
| 14 | * @package CRM |
| 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
| 16 | */ |
| 17 | class CRM_Core_BAO_PreferencesDate extends CRM_Core_DAO_PreferencesDate { |
| 18 | |
| 19 | /** |
| 20 | * Static holder for the default LT. |
| 21 | * @var string |
| 22 | */ |
| 23 | public static $_defaultPreferencesDate = NULL; |
| 24 | |
| 25 | /** |
| 26 | * Class constructor. |
| 27 | */ |
| 28 | public function __construct() { |
| 29 | parent::__construct(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Fetch object based on array of properties. |
| 34 | * |
| 35 | * @param array $params |
| 36 | * (reference ) an assoc array of name/value pairs. |
| 37 | * @param array $defaults |
| 38 | * (reference ) an assoc array to hold the flattened values. |
| 39 | * |
| 40 | * @return CRM_Core_BAO_PreferencesDate|null |
| 41 | * object on success, null otherwise |
| 42 | */ |
| 43 | public static function retrieve(&$params, &$defaults) { |
| 44 | $dao = new CRM_Core_DAO_PreferencesDate(); |
| 45 | $dao->copyValues($params); |
| 46 | if ($dao->find(TRUE)) { |
| 47 | CRM_Core_DAO::storeValues($dao, $defaults); |
| 48 | return $dao; |
| 49 | } |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Update the is_active flag in the db. |
| 55 | * |
| 56 | * @param int $id |
| 57 | * Id of the database record. |
| 58 | * @param bool $is_active |
| 59 | * Value we want to set the is_active field. |
| 60 | * @throws CRM_Core_Exception |
| 61 | */ |
| 62 | public static function setIsActive($id, $is_active) { |
| 63 | throw new CRM_Core_Exception('Cannot call setIsActive function'); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Delete preference dates. |
| 68 | * |
| 69 | * @param int $id |
| 70 | * @throws CRM_Core_Exception |
| 71 | */ |
| 72 | public static function del($id) { |
| 73 | throw new CRM_Core_Exception('Cannot call del function'); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * (Setting Callback - On Change) |
| 78 | * Respond to changes in the "timeInputFormat" setting. |
| 79 | * |
| 80 | * @param array $oldValue |
| 81 | * List of component names. |
| 82 | * @param array $newValue |
| 83 | * List of component names. |
| 84 | * @param array $metadata |
| 85 | * Specification of the setting (per *.settings.php). |
| 86 | */ |
| 87 | public static function onChangeSetting($oldValue, $newValue, $metadata) { |
| 88 | if ($oldValue == $newValue) { |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | $query = " |
| 93 | UPDATE civicrm_preferences_date |
| 94 | SET time_format = %1 |
| 95 | WHERE time_format IS NOT NULL |
| 96 | AND time_format <> '' |
| 97 | "; |
| 98 | $sqlParams = [1 => [$newValue, 'String']]; |
| 99 | CRM_Core_DAO::executeQuery($query, $sqlParams); |
| 100 | } |
| 101 | |
| 102 | } |