Skip to content

Commit adf4702

Browse files
Merge pull request #6288 from christianbeeznest/fide-22571-4
Attendance: Fix PDF export crash when no teacher is assigned to course or session - refs BT#22571
2 parents debb759 + dc42863 commit adf4702

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/CoreBundle/Controller/AttendanceController.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace Chamilo\CoreBundle\Controller;
66

77
use Chamilo\CoreBundle\Entity\Course;
8+
use Chamilo\CoreBundle\Entity\CourseRelUser;
89
use Chamilo\CoreBundle\Entity\Session;
10+
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
911
use Chamilo\CoreBundle\Entity\User;
1012
use Chamilo\CoreBundle\Repository\Node\UserRepository;
1113
use Chamilo\CourseBundle\Entity\CAttendance;
@@ -167,11 +169,20 @@ public function exportToPdf(int $id, Request $request): Response
167169

168170
if ($sessionId) {
169171
$session = $this->em->getRepository(Session::class)->find($sessionId);
170-
$teacher = $session?->getCourseCoachesSubscriptions()
172+
$rel = $session?->getCourseCoachesSubscriptions()
171173
->filter(fn($rel) => $rel->getCourse()?->getId() === $courseId)
172-
->first()?->getUser()?->getFullname();
174+
->first();
175+
176+
$teacher = $rel instanceof SessionRelCourseRelUser
177+
? $rel->getUser()?->getFullname()
178+
: null;
173179
} else {
174-
$teacher = $course?->getTeachersSubscriptions()?->first()?->getUser()?->getFullname();
180+
$rel = $course?->getTeachersSubscriptions()?->first();
181+
182+
$teacher = $rel instanceof CourseRelUser
183+
? $rel->getUser()?->getFullname()
184+
: null;
185+
;
175186
}
176187

177188
// Header

0 commit comments

Comments
 (0)