Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions assets/vue/views/sessionadmin/RegisterStudent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@
</template>

<template #title>
<h2 class="text-xl font-semibold">{{ course.title }}</h2>
<p class="text-sm text-gray-500">{{ course.code }}</p>
<h2 class="text-2xl font-semibold text-gray-90">{{ course.title }}</h2>
<p class="text-sm text-gray-50">{{ course.code }}</p>
<hr class="mt-4 border-gray-20" />
</template>

<template #content>
<p class="text-gray-700">
{{ course.description || t("No description available") }}
</p>
<div v-if="course.descriptions?.length" class="space-y-4">
<div
v-for="(item, idx) in course.descriptions"
:key="idx"
class="p-4 bg-gray-10 rounded-lg shadow-sm"
>
<h4 class="font-semibold text-gray-90 mb-2">{{ item.title }}</h4>
<div class="text-gray-50" v-html="item.content"></div>
</div>
</div>
</template>
</Card>

Expand Down Expand Up @@ -218,6 +226,7 @@ const course = ref({
title: "Loading...",
code: "",
description: "",
descriptions: [],
illustrationUrl: null,
})

Expand All @@ -237,15 +246,24 @@ const platformSessionAdminAccessAllUrls = computed(
() => platformConfigStore.getSetting("platform.session_admin_access_to_all_users_on_all_urls") === "true",
)

loadCourse()
async function loadCourse() {
try {
course.value = await courseService.findCourseForSessionAdmin(courseId)
const data = await courseService.findCourseForSessionAdmin(courseId)
course.value = {
id: data.id,
title: data.title,
code: data.code,
description: data.description,
descriptions: data.descriptions || [],
illustrationUrl: data.illustrationUrl,
}
} catch (e) {
console.error("[RegisterStudent] course load failed:", e)
}
}

loadCourse()

const form = ref({ lastname: "", firstname: "", tempId: "" })
const student = ref(null)
const searchAttempted = ref(false)
Expand Down
28 changes: 22 additions & 6 deletions src/CoreBundle/Controller/Admin/SessionAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CoreBundle\Repository\SessionRelCourseRelUserRepository;
use Chamilo\CoreBundle\Settings\SettingsManager;
use Chamilo\CourseBundle\Repository\CCourseDescriptionRepository;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
Expand All @@ -40,7 +41,8 @@
private readonly CourseRepository $courseRepository,
private readonly AccessUrlHelper $accessUrlHelper,
private readonly SettingsManager $settingsManager,
private readonly UserHelper $userHelper
private readonly UserHelper $userHelper,
private readonly CCourseDescriptionRepository $courseDescriptionRepository
) {}

#[Route('/courses', name: 'chamilo_core_admin_sessionadmin_courses', methods: ['GET'])]
Expand Down Expand Up @@ -184,7 +186,7 @@
return $courseItems;
}, $results);

$flatItems = array_merge(...$items);

Check failure on line 189 in src/CoreBundle/Controller/Admin/SessionAdminController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test on ubuntu-latest

NamedArgumentNotAllowed

src/CoreBundle/Controller/Admin/SessionAdminController.php:189:37: NamedArgumentNotAllowed: Method array_merge called with named unpacked array array<array-key, list<array{course: array{id: int|null, title: string}, session: array{endDate: null|string, id: int|null, startDate: null|string, title: string}, user: array{id: int|null, name: string}}>> (array with string keys) (see https://psalm.dev/268)

return $this->json([
'items' => $flatItems,
Expand Down Expand Up @@ -271,18 +273,32 @@
#[Route('/courses/{id}', name: 'chamilo_core_admin_sessionadmin_course_view', methods: ['GET'])]
public function getCourseForSessionAdmin(int $id): JsonResponse
{
/** @var Course $course */
$course = $this->courseRepository->find($id);

if (!$course) {
return $this->json(['error' => 'Course not found'], Response::HTTP_NOT_FOUND);
}

$qb = $this->courseDescriptionRepository->getResourcesByCourse($course);
$items = $qb->getQuery()->getResult();

$descriptions = array_map(static function($d) {
return [
'title' => $d->getTitle(),
'content' => $d->getContent(),
];
}, $items);

return $this->json([
'id' => $course->getId(),
'title' => $course->getTitle(),
'code' => $course->getCode(),
'description' => $course->getDescription(),
'illustrationUrl' => method_exists($course, 'getIllustrationUrl') ? $course->getIllustrationUrl() : null,
'id' => $course->getId(),
'title' => $course->getTitle(),
'code' => $course->getCode(),
'description' => '',
'descriptions' => $descriptions,
'illustrationUrl' => method_exists($course, 'getIllustrationUrl')
? $course->getIllustrationUrl()
: null,
]);
}

Expand Down
Loading