Merge pull request #5927 from christianbeeznest/ofaj-22197

Internal: Filter student count in session status update script - refs BT#22197
pull/5930/head
christianbeeznest 10 months ago committed by GitHub
commit e3f123aa95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      src/CoreBundle/Command/UpdateSessionStatusCommand.php
  2. 6
      src/CoreBundle/Repository/SessionRepository.php

@ -50,9 +50,9 @@ class UpdateSessionStatusCommand extends Command
$id = $session->getId();
$start = $session->getDisplayStartDate();
$end = $session->getDisplayEndDate();
$userCount = $this->sessionRepository->countUsersBySession($session->getId());
$studentCount = $this->sessionRepository->countUsersBySession($session->getId());
$status = $this->determineSessionStatus($start, $end, $userCount, $now);
$status = $this->determineSessionStatus($start, $end, $studentCount, $now);
if ($debug) {
$startFormatted = $start ? $start->format('Y-m-d H:i:s') : 'N/A';

@ -464,13 +464,15 @@ class SessionRepository extends ServiceEntityRepository
return array_filter($sessions, $filterSessions);
}
public function countUsersBySession(int $sessionId): int
public function countUsersBySession(int $sessionId, int $relationType = Session::STUDENT): int
{
$qb = $this->createQueryBuilder('s');
$qb->select('COUNT(sru.id)')
->innerJoin('s.users', 'sru')
->where('s.id = :sessionId')
->setParameter('sessionId', $sessionId);
->andWhere('sru.relationType = :relationType')
->setParameter('sessionId', $sessionId)
->setParameter('relationType', $relationType);
return (int) $qb->getQuery()->getSingleScalarResult();
}

Loading…
Cancel
Save