From 630d30eca4bec7fef87b8d9843bfac0c7564e480 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 17 Aug 2015 17:41:55 -0700 Subject: [PATCH] CRM-16373 - Config - Migrate dateInputFormat, timeInputFormat --- CRM/Admin/Form/Setting.php | 12 --------- CRM/Admin/Form/Setting/Date.php | 8 ++---- CRM/Core/BAO/PreferencesDate.php | 26 ++++++++++++++++++++ settings/Localization.setting.php | 41 +++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 18 deletions(-) diff --git a/CRM/Admin/Form/Setting.php b/CRM/Admin/Form/Setting.php index 6486759e5d..0948c65b1a 100644 --- a/CRM/Admin/Form/Setting.php +++ b/CRM/Admin/Form/Setting.php @@ -234,18 +234,6 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form { ); } - // update time for date formats when global time is changed - if (!empty($params['timeInputFormat'])) { - $query = " -UPDATE civicrm_preferences_date -SET time_format = %1 -WHERE time_format IS NOT NULL -AND time_format <> '' -"; - $sqlParams = array(1 => array($params['timeInputFormat'], 'String')); - CRM_Core_DAO::executeQuery($query, $sqlParams); - } - // verify ssl peer option if (isset($params['verifySSL'])) { CRM_Core_BAO_Setting::setItem($params['verifySSL'], diff --git a/CRM/Admin/Form/Setting/Date.php b/CRM/Admin/Form/Setting/Date.php index b13958e5f9..e43136ca69 100644 --- a/CRM/Admin/Form/Setting/Date.php +++ b/CRM/Admin/Form/Setting/Date.php @@ -41,6 +41,8 @@ class CRM_Admin_Form_Setting_Date extends CRM_Admin_Form_Setting { public $_settings = array( 'weekBegins' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, + 'dateInputFormat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, + 'timeInputFormat' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME, ); /** @@ -56,12 +58,6 @@ class CRM_Admin_Form_Setting_Date extends CRM_Admin_Form_Setting { $this->addElement('text', 'dateformatPartial', ts('Month and Year')); $this->addElement('text', 'dateformatYear', ts('Year Only')); $this->addElement('text', 'dateformatTime', ts('Time Only')); - $this->add('select', 'dateInputFormat', ts('Complete Date'), - CRM_Core_SelectValues::getDatePluginInputFormats() - ); - $this->add('select', 'timeInputFormat', ts('Time'), - CRM_Core_SelectValues::getTimeFormats() - ); $this->add('date', 'fiscalYearStart', ts('Fiscal Year Start'), CRM_Core_SelectValues::date(NULL, 'M d') diff --git a/CRM/Core/BAO/PreferencesDate.php b/CRM/Core/BAO/PreferencesDate.php index 3e519d79ab..86c544b8e2 100644 --- a/CRM/Core/BAO/PreferencesDate.php +++ b/CRM/Core/BAO/PreferencesDate.php @@ -93,4 +93,30 @@ class CRM_Core_BAO_PreferencesDate extends CRM_Core_DAO_PreferencesDate { CRM_Core_Error::fatal(); } + /** + * (Setting Callback - On Change) + * Respond to changes in the "timeInputFormat" setting. + * + * @param array $oldValue + * List of component names. + * @param array $newValue + * List of component names. + * @param array $metadata + * Specification of the setting (per *.settings.php). + */ + public static function onChangeSetting($oldValue, $newValue, $metadata) { + if ($oldValue == $newValue) { + return; + } + + $query = " +UPDATE civicrm_preferences_date +SET time_format = %1 +WHERE time_format IS NOT NULL +AND time_format <> '' +"; + $sqlParams = array(1 => array($newValue, 'String')); + CRM_Core_DAO::executeQuery($query, $sqlParams); + } + } diff --git a/settings/Localization.setting.php b/settings/Localization.setting.php index dfd760bdfd..d0f96b099d 100644 --- a/settings/Localization.setting.php +++ b/settings/Localization.setting.php @@ -322,6 +322,25 @@ return array( 'title' => 'Date Format: Year Only', 'description' => '', ), + 'dateInputFormat' => array( + 'add' => '4.7', + 'prefetch' => 1, + 'help_text' => NULL, + 'is_domain' => 1, + 'is_contact' => 0, + 'group_name' => 'Localization Preferences', + 'group' => 'localization', + 'name' => 'dateInputFormat', + 'type' => 'String', + 'quick_form_type' => 'Select', + 'html_type' => 'Select', + 'pseudoconstant' => array( + 'callback' => 'CRM_Core_SelectValues::getDatePluginInputFormats', + ), + 'default' => 'mm/dd/yy', + 'title' => 'Date Input Format', + 'description' => '', + ), 'fieldSeparator' => array( 'add' => '4.7', 'prefetch' => 1, @@ -381,6 +400,28 @@ return array( 'title' => 'Legacy Encoding', 'description' => 'If import files are NOT encoded as UTF-8, specify an alternate character encoding for these files. The default of Windows-1252 will work for Excel-created .CSV files on many computers.', ), + 'timeInputFormat' => array( + 'add' => '4.7', + 'prefetch' => 1, + 'help_text' => NULL, + 'is_domain' => 1, + 'is_contact' => 0, + 'group_name' => 'Localization Preferences', + 'group' => 'localization', + 'name' => 'timeInputFormat', + 'type' => 'String', + 'quick_form_type' => 'Select', + 'html_type' => 'Select', + 'pseudoconstant' => array( + 'callback' => 'CRM_Core_SelectValues::getTimeFormats', + ), + 'default' => '1', + 'title' => 'Time Input Format', + 'description' => '', + 'on_change' => array( + 'CRM_Core_BAO_PreferencesDate::onChangeSetting', + ), + ), 'weekBegins' => array( 'group_name' => 'Localization Preferences', 'group' => 'localization', -- 2.25.1