diff --git a/public/main/exercise/UploadAnswer.php b/public/main/exercise/UploadAnswer.php index a8a7e053b69..df80edcb60a 100644 --- a/public/main/exercise/UploadAnswer.php +++ b/public/main/exercise/UploadAnswer.php @@ -2,9 +2,9 @@ /* For licensing terms, see /license.txt */ use Chamilo\CoreBundle\Entity\AttemptFile; +use Chamilo\CoreBundle\Entity\ResourceNode; use Chamilo\CoreBundle\Entity\TrackEAttempt; use Chamilo\CoreBundle\Framework\Container; -use Symfony\Component\Uid\Uuid; /** * Question with file upload, where the file is the answer. @@ -63,9 +63,9 @@ public function return_header(Exercise $exercise, $counter = null, $score = []) } /** - * Attach uploaded Asset(s) to the question attempt as AttemptFile. + * Attach uploaded ResourceNode(s) to the question attempt as AttemptFile. */ - public static function saveAssetInQuestionAttempt(int $attemptId, array $postedAssetIds = []): void + public static function saveAssetInQuestionAttempt(int $attemptId, array $postedNodeIds = []): void { $em = Container::getEntityManager(); @@ -78,30 +78,36 @@ public static function saveAssetInQuestionAttempt(int $attemptId, array $postedA $questionId = (int) $attempt->getQuestionId(); $sessionKey = 'upload_answer_assets_'.$questionId; - $assetIds = array_values(array_filter(array_map('strval', $postedAssetIds))); - if (empty($assetIds)) { + $nodeIds = array_values(array_filter(array_map('intval', $postedNodeIds))); + + if (empty($nodeIds)) { $sessionVal = ChamiloSession::read($sessionKey); - $assetIds = is_array($sessionVal) ? $sessionVal : (empty($sessionVal) ? [] : [$sessionVal]); + $nodeIds = is_array($sessionVal) ? $sessionVal : (empty($sessionVal) ? [] : [(int) $sessionVal]); } - if (empty($assetIds)) { + + if (empty($nodeIds)) { return; } ChamiloSession::erase($sessionKey); - $repo = Container::getAssetRepository(); - foreach ($assetIds as $id) { - try { - $asset = $repo->find(Uuid::fromRfc4122($id)); - } catch (\Throwable $e) { + $resourceNodeRepo = Container::getResourceNodeRepository(); + + foreach ($nodeIds as $id) { + if (!$id) { continue; } - if (!$asset) { + + /** @var ResourceNode|null $node */ + $node = $resourceNodeRepo->find($id); + if (null === $node) { continue; } - $attemptFile = (new AttemptFile())->setAsset($asset); + $attemptFile = new AttemptFile(); + $attemptFile->setResourceNode($node); $attempt->addAttemptFile($attemptFile); + $em->persist($attemptFile); } diff --git a/public/main/exercise/exercise_show.php b/public/main/exercise/exercise_show.php index 9d41e2934f8..8f316189464 100644 --- a/public/main/exercise/exercise_show.php +++ b/public/main/exercise/exercise_show.php @@ -657,7 +657,8 @@ function getFCK(vals, marksid) { if (!empty($comnt)) { echo ExerciseLib::getFeedbackText($comnt); } - echo ExerciseLib::getOralFeedbackAudio($id, $questionId); + echo ExerciseLib::getOralFeedbackAudio($id, $questionId, false); + echo ''; echo '