3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Location Type.
21 class CRM_Admin_Form_PreferencesDate
extends CRM_Admin_Form
{
24 * Build the form object.
26 public function buildQuickForm() {
28 parent
::buildQuickForm();
30 if ($this->_action
& CRM_Core_Action
::DELETE
) {
34 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_PreferencesDate');
36 $this->applyFilter('__ALL__', 'trim');
37 $name = &$this->add('text',
45 $this->add('text', 'description', ts('Description'), $attributes['description'], FALSE);
46 $this->add('text', 'start', ts('Start Offset'), $attributes['start'], TRUE);
47 $this->add('text', 'end', ts('End Offset'), $attributes['end'], TRUE);
49 $formatType = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_PreferencesDate', $this->_id
, 'name');
51 if ($formatType == 'creditCard') {
52 $this->add('text', 'date_format', ts('Format'), $attributes['date_format'], TRUE);
55 $this->add('select', 'date_format', ts('Format'),
56 ['' => ts('- default input format -')] + CRM_Core_SelectValues
::getDatePluginInputFormats()
58 $this->add('select', 'time_format', ts('Time'),
59 ['' => ts('- none -')] + CRM_Core_SelectValues
::getTimeFormats()
62 $this->addRule('start', ts('Value must be an integer.'), 'integer');
63 $this->addRule('end', ts('Value must be an integer.'), 'integer');
66 $this->addFormRule(['CRM_Admin_Form_PreferencesDate', 'formRule']);
70 * Global validation rules for the form.
72 * @param array $fields
73 * Posted values of the form.
76 * if errors then list of errors to be posted back to the form,
79 public static function formRule($fields) {
82 if ($fields['name'] == 'activityDateTime' && !$fields['time_format']) {
83 $errors['time_format'] = ts('Time is required for this format.');
86 return empty($errors) ?
TRUE : $errors;
90 * Process the form submission.
92 public function postProcess() {
93 if (!($this->_action
& CRM_Core_Action
::UPDATE
)) {
94 CRM_Core_Session
::setStatus(ts('Preferences Date Options can only be updated'), ts('Sorry'), 'error');
98 // store the submitted values in an array
99 $params = $this->controller
->exportValues($this->_name
);
101 // action is taken depending upon the mode
102 $dao = new CRM_Core_DAO_PreferencesDate();
103 $dao->id
= $this->_id
;
104 $dao->description
= $params['description'];
105 $dao->start
= $params['start'];
106 $dao->end
= $params['end'];
107 $dao->date_format
= $params['date_format'];
108 $dao->time_format
= $params['time_format'];
112 CRM_Core_Session
::setStatus(ts("The date type '%1' has been saved.",
113 [1 => $params['name']]
114 ), ts('Saved'), 'success');