GeneralForms: remove date/timeFormat settings

They are still in use throughout the code, but the sooner we get rid
of them the better it is.

refs #6077
This commit is contained in:
Thomas Gelf 2014-06-24 21:46:19 +02:00
parent 2746b5ff9f
commit eccfb9b6bc
2 changed files with 0 additions and 195 deletions

View File

@ -32,16 +32,12 @@ namespace Icinga\Form\Config;
use \DateTimeZone;
use \Zend_Config;
use \Zend_Form_Element_Text;
use \Zend_Form_Element_Select;
use \Zend_View_Helper_DateFormat;
use \Icinga\Application\Config as IcingaConfig;
use \Icinga\Data\ResourceFactory;
use \Icinga\Web\Form;
use \Icinga\Util\Translator;
use \Icinga\Web\Form\Validator\WritablePathValidator;
use \Icinga\Web\Form\Validator\TimeFormatValidator;
use \Icinga\Web\Form\Validator\DateFormatValidator;
use \Icinga\Web\Form\Decorator\ConditionalHidden;
/**
@ -63,13 +59,6 @@ class GeneralForm extends Form
*/
private $resources;
/**
* The view helper to format date/time strings
*
* @var Zend_View_Helper_DateFormat
*/
private $dateHelper;
/**
* Set a specific configuration directory to use for configuration specific default paths
*
@ -92,29 +81,6 @@ class GeneralForm extends Form
return $this->configDir === null ? IcingaConfig::$configDir : $this->configDir;
}
/**
* Return the view helper to format date/time strings
*
* @return Zend_View_Helper_DateFormat
*/
public function getDateFormatter()
{
if ($this->dateHelper === null) {
return $this->getView()->dateFormat();
}
return $this->dateHelper;
}
/**
* Set the view helper that is used to format date/time strings (used for testing)
*
* @param Zend_View_Helper_DateFormat $dateHelper
*/
public function setDateFormatter(Zend_View_Helper_DateFormat $dateHelper)
{
$this->dateHelper = $dateHelper;
}
/**
* Set an alternative array of resources that should be used instead of the DBFactory resource set
* (used for testing)
@ -220,51 +186,6 @@ class GeneralForm extends Form
);
}
/**
* Add text fields for the date and time format used in the application
*
* @param Zend_Config $cfg The "global" section of the config.ini
*/
private function addDateFormatSettings(Zend_Config $cfg)
{
$phpUrl = '<a href="http://php.net/manual/en/function.date.php" target="_new">'
. 'the official PHP documentation</a>';
$dateFormatValue = $this->getRequest()->getParam('date_format', '');
if (empty($dateFormatValue)) {
$dateFormatValue = $cfg->get('dateFormat', 'd/m/Y');
}
$txtDefaultDateFormat = new Zend_Form_Element_Text(
array(
'name' => 'date_format',
'label' => 'Date Format',
'helptext' => 'Display dates according to this format. (See ' . $phpUrl . ' for possible values.) '
. 'Example result: ' . $this->getDateFormatter()->format(time(), $dateFormatValue),
'required' => true,
'value' => $dateFormatValue
)
);
$this->addElement($txtDefaultDateFormat);
$txtDefaultDateFormat->addValidator(new DateFormatValidator());
$timeFormatValue = $this->getRequest()->getParam('time_format', '');
if (empty($timeFormatValue)) {
$timeFormatValue = $cfg->get('timeFormat', 'g:i A');
}
$txtDefaultTimeFormat = new Zend_Form_Element_Text(
array(
'name' => 'time_format',
'label' => 'Time Format',
'required' => true,
'helptext' => 'Display times according to this format. (See ' . $phpUrl . ' for possible values.) '
. 'Example result: ' . $this->getDateFormatter()->format(time(), $timeFormatValue),
'value' => $timeFormatValue
)
);
$txtDefaultTimeFormat->addValidator(new TimeFormatValidator());
$this->addElement($txtDefaultTimeFormat);
}
/**
* Add form elements for setting the user preference storage backend
*
@ -341,7 +262,6 @@ class GeneralForm extends Form
$this->addLanguageSelection($global);
$this->addTimezoneSelection($global);
$this->addModuleSettings($global);
$this->addDateFormatSettings($global);
$this->addUserPreferencesDialog($preferences);
$this->setSubmitLabel('Save Changes');
@ -367,10 +287,6 @@ class GeneralForm extends Form
$cfg->global->language = $values['language'];
$cfg->global->timezone = $values['timezone'];
$cfg->global->modulePath = $values['module_path'];
$cfg->global->dateFormat = $values['date_format'];
$cfg->global->timeFormat = $values['time_format'];
$cfg->preferences->type = $values['preferences_type'];
if ($cfg->preferences->type === 'db') {
$cfg->preferences->resource = $values['preferences_db_resource'];

View File

@ -45,36 +45,6 @@ use \Icinga\Util\Translator;
*/
class GeneralForm extends Form
{
/**
* The view helper to format date/time strings
*
* @var Zend_View_Helper_DateFormat
*/
private $dateHelper;
/**
* Return the view helper to format date/time strings
*
* @return Zend_View_Helper_DateFormat
*/
public function getDateFormatter()
{
if ($this->dateHelper === null) {
return $this->getView()->dateFormat();
}
return $this->dateHelper;
}
/**
* Set the view helper that is used to format date/time strings (used for testing)
*
* @param Zend_View_Helper_DateFormat $dateHelper
*/
public function setDateFormatter(Zend_View_Helper_DateFormat $dateHelper)
{
$this->dateHelper = $dateHelper;
}
/**
* Add a select field for setting the user's language
*
@ -160,84 +130,6 @@ class GeneralForm extends Form
$this->enableAutoSubmit(array('default_timezone'));
}
/**
* Add text fields for the date and time format used for this user
*
* Also, a 'use default format' checkbox is added in order to allow a user to discard his overwritten setting
*
* @param Zend_Config $cfg The "global" section of the config.ini to be used as default values
*/
private function addDateFormatSettings(Zend_Config $cfg)
{
$prefs = $this->getUserPreferences();
$useGlobalDateFormat = $this->getRequest()->getParam('default_date_format', !$prefs->has('app.dateFormat'));
$useGlobalTimeFormat = $this->getRequest()->getParam('default_time_format', !$prefs->has('app.timeFormat'));
$phpUrl = '<a href="http://php.net/manual/en/function.date.php" target="_new">'
. 'the official PHP documentation</a>';
$this->addElement(
'checkbox',
'default_date_format',
array(
'label' => 'Use Default Date Format',
'value' => $useGlobalDateFormat,
'required' => true
)
);
$dateFormatValue = $this->getRequest()->getParam('date_format', '');
if (empty($dateFormatValue)) {
$dateFormatValue = $prefs->get('app.dateFormat', $cfg->get('dateFormat', 'd/m/Y'));
}
$txtDefaultDateFormat = new Zend_Form_Element_Text(
array(
'name' => 'date_format',
'label' => 'Preferred Date Format',
'helptext' => 'Display dates according to this format. (See ' . $phpUrl . ' for possible values.) '
. 'Example result: ' . $this->getDateFormatter()->format(time(), $dateFormatValue),
'required' => !$useGlobalDateFormat,
'value' => $dateFormatValue
)
);
$this->addElement($txtDefaultDateFormat);
$txtDefaultDateFormat->addValidator(new DateFormatValidator());
if ($useGlobalDateFormat) {
$txtDefaultDateFormat->setAttrib('disabled', '1');
}
$this->addElement(
'checkbox',
'default_time_format',
array(
'label' => 'Use Default Time Format',
'value' => $useGlobalTimeFormat,
'required' => !$useGlobalTimeFormat
)
);
$timeFormatValue = $this->getRequest()->getParam('time_format', '');
if (empty($timeFormatValue)) {
$timeFormatValue = $prefs->get('app.timeFormat', $cfg->get('timeFormat', 'g:i A'));
}
$txtDefaultTimeFormat = new Zend_Form_Element_Text(
array(
'name' => 'time_format',
'label' => 'Preferred Time Format',
'required' => !$useGlobalTimeFormat,
'helptext' => 'Display times according to this format. (See ' . $phpUrl . ' for possible values.) '
. 'Example result: ' . $this->getDateFormatter()->format(time(), $timeFormatValue),
'value' => $timeFormatValue
)
);
$txtDefaultTimeFormat->addValidator(new TimeFormatValidator());
$this->addElement($txtDefaultTimeFormat);
if ($useGlobalTimeFormat) {
$txtDefaultTimeFormat->setAttrib('disabled', '1');
}
$this->enableAutoSubmit(array('default_time_format', 'default_date_format'));
}
/**
* Create the general form, using the global configuration as fallback values for preferences
*
@ -255,7 +147,6 @@ class GeneralForm extends Form
$this->addLanguageSelection($global);
$this->addTimezoneSelection($global);
$this->addDateFormatSettings($global);
$this->setSubmitLabel('Save Changes');
@ -280,8 +171,6 @@ class GeneralForm extends Form
return array(
'app.language' => $values['default_language'] ? null : $values['language'],
'app.timezone' => $values['default_timezone'] ? null : $values['timezone'],
'app.dateFormat' => $values['default_date_format'] ? null : $values['date_format'],
'app.timeFormat' => $values['default_time_format'] ? null : $values['time_format'],
'app.show_benchmark' => $values['show_benchmark'] === '1' ? true : false
);
}