|
|
|
@ -92,32 +92,70 @@ class DatePicker extends HTML_QuickForm_text |
|
|
|
|
* |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
private function getElementJS() |
|
|
|
|
private function getElementJS(): string |
|
|
|
|
{ |
|
|
|
|
$js = null; |
|
|
|
|
$localeCode = $this->getLocaleCode(); |
|
|
|
|
$id = $this->getAttribute('id'); |
|
|
|
|
//timeFormat: 'hh:mm' |
|
|
|
|
$js .= "<script> |
|
|
|
|
$(function() { |
|
|
|
|
var config = { |
|
|
|
|
|
|
|
|
|
$localeScript = ''; |
|
|
|
|
if ($localeCode !== 'en') { |
|
|
|
|
$localeScript = '<script async="false" src="/build/flatpickr/l10n/' . $localeCode . '.js"></script>'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $localeScript . "<script> |
|
|
|
|
document.addEventListener('DOMContentLoaded', function () { |
|
|
|
|
const fp = flatpickr('#{$id}', { |
|
|
|
|
locale: '{$localeCode}', |
|
|
|
|
altInput: true, |
|
|
|
|
altFormat: '".get_lang('F d, Y')."', |
|
|
|
|
enableTime: false, |
|
|
|
|
dateFormat: 'Y-m-d', |
|
|
|
|
wrap: true, |
|
|
|
|
locale: { |
|
|
|
|
firstDayOfWeek: 1 |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
$('#{$id}').flatpickr(config); |
|
|
|
|
time_24hr: true, |
|
|
|
|
wrap: false |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if ($('label[for=\"".$id."\"]').length > 0) { |
|
|
|
|
$('label[for=\"".$id."\"]').hide(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
document.querySelector('label[for=\"' + '{$id}' + '\"]').classList.add('datepicker-label'); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
</script>"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieves the locale code based on user and course settings. |
|
|
|
|
* Extracts the ISO language code from user or course settings and checks |
|
|
|
|
* its availability in the list of supported locales. Returns 'en' if the language |
|
|
|
|
* is not available. |
|
|
|
|
* |
|
|
|
|
* @return string Locale code (e.g., 'es', 'en', 'fr'). |
|
|
|
|
*/ |
|
|
|
|
private function getLocaleCode(): string |
|
|
|
|
{ |
|
|
|
|
$locale = api_get_language_isocode(); |
|
|
|
|
$userInfo = api_get_user_info(); |
|
|
|
|
if (is_array($userInfo) && !empty($userInfo['language'])) { |
|
|
|
|
$locale = $userInfo['language']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$courseInfo = api_get_course_info(); |
|
|
|
|
if (isset($courseInfo)) { |
|
|
|
|
$locale = $courseInfo['language']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$localeCode = explode('_', $locale)[0]; |
|
|
|
|
$availableLocales = [ |
|
|
|
|
'ar', 'ar-dz', 'at', 'az', 'be', 'bg', 'bn', 'bs', 'cat', 'ckb', 'cs', 'cy', 'da', 'de', |
|
|
|
|
'eo', 'es', 'et', 'fa', 'fi', 'fo', 'fr', 'ga', 'gr', 'he', 'hi', 'hr', 'hu', 'hy', |
|
|
|
|
'id', 'is', 'it', 'ja', 'ka', 'km', 'ko', 'kz', 'lt', 'lv', 'mk', 'mn', 'ms', 'my', |
|
|
|
|
'nl', 'nn', 'no', 'pa', 'pl', 'pt', 'ro', 'ru', 'si', 'sk', 'sl', 'sq', 'sr', 'sr-cyr', |
|
|
|
|
'sv', 'th', 'tr', 'uk', 'uz', 'uz_latn', 'vn', 'zh', 'zh-tw' |
|
|
|
|
]; |
|
|
|
|
if (!in_array($localeCode, $availableLocales)) { |
|
|
|
|
$localeCode = 'en'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $js; |
|
|
|
|
return $localeCode; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|