Skip to content

Attendance: Fix PDF export crash when no teacher is assigned to course or session - refs BT#22571 #6288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
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
17 changes: 14 additions & 3 deletions src/CoreBundle/Controller/AttendanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Chamilo\CoreBundle\Controller;

use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\CourseRelUser;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Repository\Node\UserRepository;
use Chamilo\CourseBundle\Entity\CAttendance;
Expand Down Expand Up @@ -167,11 +169,20 @@ public function exportToPdf(int $id, Request $request): Response

if ($sessionId) {
$session = $this->em->getRepository(Session::class)->find($sessionId);
$teacher = $session?->getCourseCoachesSubscriptions()
$rel = $session?->getCourseCoachesSubscriptions()
->filter(fn($rel) => $rel->getCourse()?->getId() === $courseId)
->first()?->getUser()?->getFullname();
->first();

$teacher = $rel instanceof SessionRelCourseRelUser
? $rel->getUser()?->getFullname()
: null;
} else {
$teacher = $course?->getTeachersSubscriptions()?->first()?->getUser()?->getFullname();
$rel = $course?->getTeachersSubscriptions()?->first();

$teacher = $rel instanceof CourseRelUser
? $rel->getUser()?->getFullname()
: null;
;
}

// Header
Expand Down
Loading