Open Journal Systems  3.3.0
PKPDateTimeForm.inc.php
1 <?php
16 use \PKP\components\forms\FormComponent;
17 
18 define('FORM_DATE_TIME', 'dateTime');
19 
22  public $id = FORM_DATE_TIME;
23 
25  public $method = 'PUT';
26 
34  public function __construct($action, $locales, $context) {
35  $this->action = $action;
36  $this->locales = $locales;
37 
38  $localizedOptions = []; // template for localized options to be used for date and time format
39  foreach ($this->locales as $key => $localeValue) {
40  $localizedOptions[$localeValue['key']] = $key;
41  }
42 
43  $this->addGroup([
44  'id' => 'descriptions',
45  'label' => __('manager.setup.dateTime.descriptionTitle'),
46  'description' => __('manager.setup.dateTime.description'),
47  ])
48  //The default date format to use in the editorial and reader interfaces.
49  ->addField(new FieldRadioInput('dateFormatLong', [
50  'label' => __('manager.setup.dateTime.longDate'),
51  'isMultilingual' => true,
52  'options' => $this->_setDateOptions([
53  '%B %e, %Y',
54  '%B %e %Y',
55  '%e %B %Y',
56  '%Y %B %e',
57  ]),
58  'value' => $context->getDateTimeFormats('dateFormatLong'),
59  'groupId' => 'descriptions',
60  ]))
61  // A brief date format that is used when there is less space for the full date.
62  ->addField(new FieldRadioInput('dateFormatShort', [
63  'label' => __('manager.setup.dateTime.shortDate'),
64  'isMultilingual' => true,
65  'options' => $this->_setDateOptions([
66  '%Y-%m-%d',
67  '%d-%m-%Y',
68  '%m/%d/%Y',
69  '%d.%m.%Y',
70  ]),
71  'value' => $context->getDateTimeFormats('dateFormatShort'),
72  'groupId' => 'descriptions',
73 
74  ]))
75  ->addField(new FieldRadioInput('timeFormat', [
76  'label' => __('manager.setup.dateTime.time'),
77  'isMultilingual' => true,
78  'options' => $this->_setDateOptions([
79  '%H:%M',
80  '%I:%M %p',
81  '%l:%M%P',
82  ]),
83  'value' => $context->getDateTimeFormats('timeFormat'),
84  'groupId' => 'descriptions',
85  ]))
86  ->addField(new FieldRadioInput('datetimeFormatLong', [
87  'label' => __('manager.setup.dateTime.longDateTime'),
88  'isMultilingual' => true,
89  'options' => array_map(function ($value) use ($context, $localizedOptions) {
90  $locale = array_search($value, $localizedOptions);
91  $optionValue = $context->getLocalizedDateFormatLong($locale) . ' - ' . $context->getLocalizedTimeFormat($locale);
92  return [
93  [
94  'value' => $optionValue,
95  'label' => $optionValue,
96  ],
97  [
98  'isInput' => true,
99  'label' => __('manager.setup.dateTime.custom'),
100  ]
101  ];
102  }, $localizedOptions),
103  'value' => $context->getDateTimeFormats('datetimeFormatLong'),
104  'groupId' => 'descriptions',
105  ]))
106  ->addField(new FieldRadioInput('datetimeFormatShort', [
107  'label' => __('manager.setup.dateTime.shortDateTime'),
108  'isMultilingual' => true,
109  'options' => array_map(function ($value) use ($context, $localizedOptions) {
110  $locale = array_search($value, $localizedOptions);
111  $optionValue = $context->getLocalizedDateFormatShort($locale) . ' ' . $context->getLocalizedTimeFormat($locale);
112  return [
113  [
114  'value' => $optionValue,
115  'label' => $optionValue,
116  ],
117  [
118  'isInput' => true,
119  'label' => __('manager.setup.dateTime.custom'),
120  ]
121  ];
122  }, $localizedOptions),
123  'value' => $context->getDateTimeFormats('datetimeFormatShort'),
124  'groupId' => 'descriptions',
125  ]));
126  }
127 
134  private function _setDateOptions($optionValues) {
135  $options = [];
136  foreach ($this->locales as $localeValue) {
137  $locale = $localeValue['key'];
138  foreach ($optionValues as $optionValue) {
139  $options[$locale][] = [
140  'value' => $optionValue,
141  'label' => $optionValue
142  ];
143  }
144 
145  $options[$locale][] = [
146  'isInput' => true,
147  'label' => __('manager.setup.dateTime.custom'),
148  ];
149  }
150  return $options;
151  }
152 }
PKP\components\forms\FormComponent\addGroup
addGroup($args, $position=[])
Definition: FormComponent.inc.php:145
PKP\components\forms\context
Definition: PKPAnnouncementSettingsForm.inc.php:14
PKP\components\forms\FieldRadioInput
Definition: FieldRadioInput.inc.php:16
PKP\components\forms\context\PKPDateTimeForm\__construct
__construct($action, $locales, $context)
Definition: PKPDateTimeForm.inc.php:34
PKP\components\forms\FormComponent\$action
$action
Definition: FormComponent.inc.php:37
PKP\components\forms\FormComponent
Definition: FormComponent.inc.php:20
PKP\components\forms\context\PKPDateTimeForm\$id
$id
Definition: PKPDateTimeForm.inc.php:22
PKP\components\forms\context\FORM_DATE_TIME
const FORM_DATE_TIME
Definition: PKPDateTimeForm.inc.php:18
PKP\components\forms\FormComponent\$locales
$locales
Definition: FormComponent.inc.php:43
PKP\components\forms\context\PKPDateTimeForm
Definition: PKPDateTimeForm.inc.php:20
PKP\components\forms\context\PKPDateTimeForm\$method
$method
Definition: PKPDateTimeForm.inc.php:25