Skip to content
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

Exercise: Add pending corrections indicator to exercise list view - refs #3480 #6034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions public/main/exercise/exercise.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8792,6 +8792,13 @@ public static function exerciseGridResource(

$repo = Container::getQuizRepository();

$trackEExerciseRepo = Container::getTrackEExerciseRepository();
$pendingCorrections = $trackEExerciseRepo->getPendingCorrectionsByExercise($courseId);
$pendingAttempts = [];
foreach ($pendingCorrections as $correction) {
$pendingAttempts[$correction['exerciseId']] = $correction['pendingCount'];
}

// 2. Get query builder from repo.
$qb = $repo->getResourcesByCourse($course, $session);

Expand Down Expand Up @@ -9027,6 +9034,18 @@ public static function exerciseGridResource(
$url .= Display::div($embeddableIcon, ['class' => 'pull-right']);
}

$pendingCount = $pendingAttempts[$exerciseId] ?? 0;
if ($pendingCount > 0) {
$pendingIcon = Display::getMdiIcon(
ActionIcon::ALERT->value,
'ch-tool-icon',
null,
ICON_SIZE_SMALL,
get_lang('Pending Attempts') . ": $pendingCount"
);
$url .= " $pendingIcon";
}

$currentRow['title'] = $url.$lp_blocked;
$rowi = $exerciseEntity->getQuestions()->count();
if ($allowToEditBaseCourse || $allowToEditSession) {
Expand Down
17 changes: 17 additions & 0 deletions src/CoreBundle/Repository/TrackEExerciseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@ public function delete(TrackEExercise $track): void
$this->getEntityManager()->remove($track);
$this->getEntityManager()->flush();
}

/**
* Get exercises with pending corrections grouped by exercise ID.
*/
public function getPendingCorrectionsByExercise(int $courseId): array
{
$qb = $this->createQueryBuilder('te');

$qb->select('IDENTITY(te.quiz) AS exerciseId, COUNT(te.exeId) AS pendingCount')
->where('te.status = :status')
->andWhere('te.course = :courseId')
->setParameter('status', 'incomplete')
->setParameter('courseId', $courseId)
->groupBy('te.quiz');

return $qb->getQuery()->getResult();
}
}
Loading