Skip to content

Commit b1f548d

Browse files
committed
Merge branch 'master' of github.com:chamilo/chamilo-lms
2 parents bd55894 + 08fdfcc commit b1f548d

3 files changed

Lines changed: 57 additions & 8 deletions

File tree

assets/vue/components/assignments/AssignmentsForm.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ import BaseTinyEditor from "../basecomponents/BaseTinyEditor.vue"
157157
import ResourceLanguageSelector from "../resources/ResourceLanguageSelector.vue"
158158
import useVuelidate from "@vuelidate/core"
159159
import { computed, reactive, ref, watchEffect } from "vue"
160-
import { maxValue, minValue, required } from "@vuelidate/validators"
160+
import { helpers, required } from "@vuelidate/validators"
161161
import { useI18n } from "vue-i18n"
162162
import { useRoute } from "vue-router"
163163
import { RESOURCE_LINK_PUBLISHED } from "../../constants/entity/resourcelink"
@@ -301,6 +301,26 @@ watchEffect(() => {
301301
}
302302
})
303303
304+
function truncateToMinute(date) {
305+
const d = new Date(date)
306+
d.setSeconds(0, 0)
307+
return d
308+
}
309+
310+
function maxDateByMinute(max) {
311+
return helpers.withMessage(
312+
t("Expiration date must be before or equal to end date"),
313+
(value) => !value || !max || +truncateToMinute(value) <= +truncateToMinute(max),
314+
)
315+
}
316+
317+
function minDateByMinute(min) {
318+
return helpers.withMessage(
319+
t("End date must be after or equal to expiration date"),
320+
(value) => !value || !min || +truncateToMinute(value) >= +truncateToMinute(min),
321+
)
322+
}
323+
304324
const rules = computed(() => {
305325
const r = { title: { required, $autoDirty: true } }
306326
if (showAdvancedSettings.value) {
@@ -310,11 +330,11 @@ const rules = computed(() => {
310330
}
311331
if (chkExpiresOn.value) {
312332
r.expiresOn = { required, $autoDirty: true }
313-
if (chkEndsOn.value) r.expiresOn.maxValue = maxValue(assignment.endsOn)
333+
if (chkEndsOn.value) r.expiresOn.maxValue = maxDateByMinute(assignment.endsOn)
314334
}
315335
if (chkEndsOn.value) {
316336
r.endsOn = { required, $autoDirty: true }
317-
if (chkExpiresOn.value) r.endsOn.minValue = minValue(assignment.expiresOn)
337+
if (chkExpiresOn.value) r.endsOn.minValue = minDateByMinute(assignment.expiresOn)
318338
}
319339
r.allowTextAssignment = { required }
320340
}

src/CoreBundle/Controller/Admin/SessionListController.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ public function __construct(
7373
private readonly SettingsManager $settingsManager,
7474
) {}
7575

76+
private function resolvePlatformTimezone(): DateTimeZone
77+
{
78+
$tz = (string) ($this->settingsManager->getSetting('platform.timezone', false, 'timezones') ?? '');
79+
80+
try {
81+
return new DateTimeZone('' !== $tz ? $tz : 'UTC');
82+
} catch (\Throwable) {
83+
return new DateTimeZone('UTC');
84+
}
85+
}
86+
87+
private function formatSessionDate(?DateTime $date, DateTimeZone $tz): ?string
88+
{
89+
if (null === $date) {
90+
return null;
91+
}
92+
93+
return (clone $date)->setTimezone($tz)->format('Y-m-d H:i');
94+
}
95+
7696
#[Route('', name: 'admin_session_list_data', methods: ['GET'])]
7797
public function list(Request $request): JsonResponse
7898
{
@@ -180,14 +200,16 @@ public function list(Request $request): JsonResponse
180200
$tutorsMap = $this->getTutorsBySessionIds($sessionIds);
181201
}
182202

203+
$tz = $this->resolvePlatformTimezone();
204+
183205
$items = [];
184206
foreach ($rows as $row) {
185207
$item = [
186208
'id' => $row['id'],
187209
'title' => $row['title'],
188210
'categoryName' => $row['categoryName'] ?? '',
189-
'displayStartDate' => $row['displayStartDate'] ? $row['displayStartDate']->format('Y-m-d H:i') : null,
190-
'displayEndDate' => $row['displayEndDate'] ? $row['displayEndDate']->format('Y-m-d H:i') : null,
211+
'displayStartDate' => $this->formatSessionDate($row['displayStartDate'], $tz),
212+
'displayEndDate' => $this->formatSessionDate($row['displayEndDate'], $tz),
191213
'visibility' => $row['visibility'],
192214
'visibilityLabel' => self::VISIBILITY_LABELS[$row['visibility']] ?? 'Unknown',
193215
'status' => $row['status'],
@@ -492,14 +514,16 @@ private function enrichWithChildSessions(array $items, bool $showCountUsers): ar
492514
$childTutorsMap = $this->getTutorsBySessionIds($childIds);
493515
}
494516

517+
$tz = $this->resolvePlatformTimezone();
518+
495519
$childMap = [];
496520
foreach ($children as $child) {
497521
$childItem = [
498522
'id' => $child['id'],
499523
'title' => '-- '.$child['title'],
500524
'categoryName' => $child['categoryName'] ?? '',
501-
'displayStartDate' => $child['displayStartDate'] ? $child['displayStartDate']->format('Y-m-d H:i') : null,
502-
'displayEndDate' => $child['displayEndDate'] ? $child['displayEndDate']->format('Y-m-d H:i') : null,
525+
'displayStartDate' => $this->formatSessionDate($child['displayStartDate'], $tz),
526+
'displayEndDate' => $this->formatSessionDate($child['displayEndDate'], $tz),
503527
'visibility' => $child['visibility'],
504528
'visibilityLabel' => self::VISIBILITY_LABELS[$child['visibility']] ?? 'Unknown',
505529
'status' => $child['status'],

src/CourseBundle/Entity/CQuizQuestion.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,12 @@ public function getResourceIdentifier(): int|Uuid
389389

390390
public function getResourceName(): string
391391
{
392-
return $this->getQuestion();
392+
$question = $this->getQuestion();
393+
if ('' !== $question) {
394+
return $question;
395+
}
396+
397+
return 'question-'.($this->iid ?? 'unknown');
393398
}
394399

395400
public function setResourceName(string $name): self

0 commit comments

Comments
 (0)