Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansenDatabay committed Sep 19, 2024
2 parents ffed431 + 99d9db6 commit ecd69c8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ilCertificateDateHelper
/**
* @param string|int $date
*/
public function formatDate($date, ?int $dateFormat = null): string
public function formatDate($date, ilObjUser $user = null, ?int $dateFormat = null): string
{
if (null === $dateFormat) {
require_once 'components/ILIAS/Calendar/classes/class.ilDateTime.php'; // Required because of global contant IL_CAL_DATE
Expand All @@ -36,6 +36,11 @@ public function formatDate($date, ?int $dateFormat = null): string
$oldDatePresentationValue = ilDatePresentation::useRelativeDates();
ilDatePresentation::setUseRelativeDates(false);

if ($user) {
ilDatePresentation::setLanguage(new ilLanguage($user->getLanguage()));
ilDatePresentation::setUser($user);
}

$date = ilDatePresentation::formatDate(new ilDate($date, $dateFormat));

ilDatePresentation::setUseRelativeDates($oldDatePresentationValue);
Expand All @@ -47,16 +52,21 @@ public function formatDate($date, ?int $dateFormat = null): string
* @param string|int $dateTime
* @throws ilDateTimeException
*/
public function formatDateTime($dateTime, ?int $dateFormat = null): string
public function formatDateTime($dateTime, ilObjuser $user = null, ?int $dateFormat = null): string
{
if (null === $dateFormat) {
require_once 'components/ILIAS/Calendar/classes/class.ilDateTime.php'; // Required because of global contant IL_CAL_DATE
require_once '../components/ILIAS/Calendar/classes/class.ilDateTime.php'; // Required because of global contant IL_CAL_DATE
$dateFormat = IL_CAL_DATETIME;
}

$oldDatePresentationValue = ilDatePresentation::useRelativeDates();
ilDatePresentation::setUseRelativeDates(false);

if ($user) {
ilDatePresentation::setLanguage(new ilLanguage($user->getLanguage()));
ilDatePresentation::setUser($user);
}

$date = ilDatePresentation::formatDate(new ilDateTime($dateTime, $dateFormat));

ilDatePresentation::setUseRelativeDates($oldDatePresentationValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function getPlaceholderValues(int $userId, int $objId): array
$birthday = '';
$dateObject = $user->getBirthday();
if (null !== $dateObject) {
$birthday = $this->dateHelper->formatDate($dateObject, $this->birthdayDateFormat);
$birthday = $this->dateHelper->formatDate($dateObject, $user, $this->birthdayDateFormat);
}

$placeholder['USER_BIRTHDAY'] = $this->utilHelper->prepareFormOutput((trim($birthday)));
Expand All @@ -156,10 +156,12 @@ public function getPlaceholderValues(int $userId, int $objId): array
$placeholder['USER_MATRICULATION'] = $this->utilHelper->prepareFormOutput((trim($user->getMatriculation())));
$placeholder['DATE'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
time(),
$user,
$this->dateFormat
))));
$placeholder['DATETIME'] = $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
time(),
$user,
$this->dateFormat
))));

Expand Down Expand Up @@ -190,6 +192,7 @@ public function getPlaceholderValuesForPreview(int $userId, int $objId): array
"USER_SALUTATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_salutation")),
"USER_BIRTHDAY" => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
time(),
null,
$this->dateFormat
)))),
"USER_INSTITUTION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_institution")),
Expand All @@ -201,18 +204,22 @@ public function getPlaceholderValuesForPreview(int $userId, int $objId): array
"USER_MATRICULATION" => $this->utilHelper->prepareFormOutput($this->language->txt("certificate_var_user_matriculation")),
'DATE' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
time(),
null,
$this->dateFormat
)))),
'DATETIME' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
time(),
null,
$this->dateFormat
)))),
'DATE_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDate(
time(),
null,
$this->dateFormat
)))),
'DATETIME_COMPLETED' => $this->utilHelper->prepareFormOutput((trim($this->dateHelper->formatDateTime(
time(),
null,
$this->dateFormat
))))
];
Expand Down
15 changes: 9 additions & 6 deletions components/ILIAS/Form/classes/class.ilUriInputGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ public function checkInput(): bool
{
$lng = $this->lng;

$uri_string = trim($this->getInput());

// check required
if ($this->getRequired() && trim($this->str($this->getPostVar())) == "") {
$this->setAlert($lng->txt("msg_input_is_required"));
return false;
if ($uri_string === "") {
if ($this->getRequired()) {
$this->setAlert($lng->txt("msg_input_is_required"));
return false;
}
return true;
}

$url = $this->getInput();

try {
new URI($url);
new URI($uri_string);
} catch (Throwable $e) {
$this->setAlert($lng->txt("form_invalid_uri"));
return false;
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5146,6 +5146,7 @@ common#:#objs_rglo#:#ECS-Glossare
common#:#objs_rgrp#:#ECS-Gruppen
common#:#objs_rlm#:#ECS-Lernmodule
common#:#objs_role#:#Rollen
common#:#objs_rolf#:#Rollenordner
common#:#objs_rtst#:#ECS-Tests
common#:#objs_rwik#:#ECS-Wikis
common#:#objs_sahs#:#SCORM-Lernmodule
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5139,6 +5139,7 @@ common#:#objs_rglo#:#ECS Glossaries
common#:#objs_rgrp#:#ECS Groups
common#:#objs_rlm#:#ECS Learning Modules
common#:#objs_role#:#Roles
common#:#objs_rolf#:#Role Folders
common#:#objs_rtst#:#ECS Tests
common#:#objs_rwik#:#ECS Wikis
common#:#objs_sahs#:#SCORM Learning Modules
Expand Down

0 comments on commit ecd69c8

Please sign in to comment.