@@ -5593,7 +5593,7 @@ public static function getOralFileAudio(int $trackExerciseId, int $questionId, b
55935593 */
55945594 public static function getOralFeedbackAudio (int $ attemptId , int $ questionId ): string
55955595 {
5596- /** @var TrackEExercise $tExercise */
5596+ /** @var TrackEExercise|null $tExercise */
55975597 $ tExercise = Container::getTrackEExerciseRepository ()->find ($ attemptId );
55985598
55995599 if (null === $ tExercise ) {
@@ -5606,23 +5606,45 @@ public static function getOralFeedbackAudio(int $attemptId, int $questionId): st
56065606 return '' ;
56075607 }
56085608
5609- $ assetRepo = Container::getAssetRepository ();
5610- $ html = '' ;
5609+ $ feedbacks = $ qAttempt ->getAttemptFeedbacks ();
56115610
5612- // Keep only the latest audio feedback to avoid duplicated players
5613- foreach ($ qAttempt ->getAttemptFeedbacks () as $ attemptFeedback ) {
5614- $ html = Display::tag (
5615- 'audio ' ,
5616- '' ,
5617- [
5618- 'src ' => $ assetRepo ->getAssetUrl ($ attemptFeedback ->getAsset ()),
5619- 'controls ' => '' ,
5620- ]
5611+ if ($ feedbacks ->isEmpty ()) {
5612+ return '' ;
5613+ }
56215614
5622- );
5615+ $ latestFeedback = null ;
5616+
5617+ foreach ($ feedbacks as $ feedback ) {
5618+ // Skip feedbacks without asset, just in case
5619+ if (null === $ feedback ->getAsset ()) {
5620+ continue ;
5621+ }
5622+
5623+ if (null === $ latestFeedback ) {
5624+ $ latestFeedback = $ feedback ;
5625+ continue ;
5626+ }
5627+
5628+ // Choose the feedback with the latest createdAt
5629+ if ($ feedback ->getCreatedAt () > $ latestFeedback ->getCreatedAt ()) {
5630+ $ latestFeedback = $ feedback ;
5631+ }
56235632 }
56245633
5625- return $ html ;
5634+ if (null === $ latestFeedback ) {
5635+ return '' ;
5636+ }
5637+
5638+ $ assetRepo = Container::getAssetRepository ();
5639+
5640+ return Display::tag (
5641+ 'audio ' ,
5642+ '' ,
5643+ [
5644+ 'src ' => $ assetRepo ->getAssetUrl ($ latestFeedback ->getAsset ()),
5645+ 'controls ' => '' ,
5646+ ]
5647+ );
56265648 }
56275649
56285650 public static function getUploadAnswerFiles (int $ trackExerciseId , int $ questionId , bool $ returnUrls = false )
0 commit comments