From 290b7b9141e1d0012fa709ca78a00167f292d670 Mon Sep 17 00:00:00 2001 From: Christian Beeznest Date: Wed, 6 Aug 2025 21:38:59 -0500 Subject: [PATCH] Admin: Add course descriptions to Register view from dashboard - refs BT#22814 --- .../views/sessionadmin/RegisterStudent.vue | 32 +++++++++++++++---- .../Admin/SessionAdminController.php | 28 ++++++++++++---- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/assets/vue/views/sessionadmin/RegisterStudent.vue b/assets/vue/views/sessionadmin/RegisterStudent.vue index df379c9e4b0..0ee877d7d51 100644 --- a/assets/vue/views/sessionadmin/RegisterStudent.vue +++ b/assets/vue/views/sessionadmin/RegisterStudent.vue @@ -10,14 +10,22 @@ @@ -218,6 +226,7 @@ const course = ref({ title: "Loading...", code: "", description: "", + descriptions: [], illustrationUrl: null, }) @@ -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) diff --git a/src/CoreBundle/Controller/Admin/SessionAdminController.php b/src/CoreBundle/Controller/Admin/SessionAdminController.php index f26cfa64927..920c230655b 100644 --- a/src/CoreBundle/Controller/Admin/SessionAdminController.php +++ b/src/CoreBundle/Controller/Admin/SessionAdminController.php @@ -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; @@ -40,7 +41,8 @@ public function __construct( 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'])] @@ -271,18 +273,32 @@ public function extendSessionByWeek(Request $request, SessionRelCourseRelUserRep #[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, ]); }