From 6d491a10bf1f38e356957ea5a433f8ced94bd441 Mon Sep 17 00:00:00 2001 From: Elorfin Date: Wed, 11 Oct 2023 08:31:54 +0200 Subject: [PATCH] [Quiz] fixes papers delete --- .../ResourceEvaluationSubscriber.php | 14 +++++ src/plugin/exo/Entity/Exercise.php | 24 ++++----- .../Library/Model/AttemptParametersTrait.php | 29 ++--------- .../Listener/Resource/ExerciseListener.php | 8 --- .../exo/Manager/Attempt/PaperManager.php | 23 ++++---- src/plugin/exo/Manager/AttemptManager.php | 8 --- src/plugin/exo/Repository/PaperRepository.php | 47 ++++++----------- .../exo/Resources/config/services/manager.yml | 1 + .../modules/quiz/player/selectors.js | 12 ++--- .../quiz/editor/components/parameters.jsx | 52 ------------------- .../resources/quiz/editor/validation.js | 12 +---- .../resources/quiz/player/store/reducer.js | 16 ------ .../resources/quiz/player/store/selectors.js | 18 ------- .../modules/resources/quiz/prop-types.js | 2 - .../modules/resources/quiz/store/selectors.js | 4 ++ .../exo/Serializer/ExerciseSerializer.php | 14 ++--- .../Manager/Attempt/PaperManagerTest.php | 1 + 17 files changed, 72 insertions(+), 213 deletions(-) diff --git a/src/main/evaluation/Subscriber/ResourceEvaluationSubscriber.php b/src/main/evaluation/Subscriber/ResourceEvaluationSubscriber.php index 6b7c3852ae7..c05e389067b 100644 --- a/src/main/evaluation/Subscriber/ResourceEvaluationSubscriber.php +++ b/src/main/evaluation/Subscriber/ResourceEvaluationSubscriber.php @@ -4,9 +4,11 @@ use Claroline\AppBundle\API\Crud; use Claroline\AppBundle\Event\Crud\CreateEvent; +use Claroline\AppBundle\Event\Crud\DeleteEvent; use Claroline\AppBundle\Event\Crud\UpdateEvent; use Claroline\AppBundle\Persistence\ObjectManager; use Claroline\CommunityBundle\Repository\UserRepository; +use Claroline\CoreBundle\Entity\Resource\ResourceEvaluation; use Claroline\CoreBundle\Entity\Resource\ResourceNode; use Claroline\CoreBundle\Entity\User; use Claroline\CoreBundle\Event\CatalogEvents\ResourceEvents; @@ -44,6 +46,7 @@ public static function getSubscribedEvents(): array Crud::getEventName('create', 'post', ResourceNode::class) => 'createEvaluations', Crud::getEventName('update', 'post', ResourceNode::class) => 'updateEvaluations', ResourceEvents::RESOURCE_OPEN => ['open', 10], + Crud::getEventName('delete', 'pre', ResourceEvaluation::class) => 'updateNbAttempts', ]; } @@ -103,4 +106,15 @@ public function open(LoadResourceEvent $event) ); } } + + public function updateNbAttempts(DeleteEvent $event): void + { + /** @var ResourceEvaluation $resourceAttempt */ + $resourceAttempt = $event->getObject(); + + $evaluation = $resourceAttempt->getResourceUserEvaluation(); + if ($evaluation) { + $evaluation->setNbAttempts($evaluation->getNbAttempts() - 1); + } + } } diff --git a/src/plugin/exo/Entity/Exercise.php b/src/plugin/exo/Entity/Exercise.php index b2677a16c34..51ccfa79e48 100644 --- a/src/plugin/exo/Entity/Exercise.php +++ b/src/plugin/exo/Entity/Exercise.php @@ -17,6 +17,7 @@ /** * @ORM\Entity(repositoryClass="UJM\ExoBundle\Repository\ExerciseRepository") + * * @ORM\Table(name="ujm_exercise") */ class Exercise extends AbstractResource @@ -236,8 +237,10 @@ class Exercise extends AbstractResource * @ORM\Column(name="max_papers", type="integer") * * @var int + * + * @todo to remove. not implemented. */ - private $maxPapers = 0; + public $maxPapers = 0; /** * Use all papers to compute stats. @@ -289,6 +292,7 @@ class Exercise extends AbstractResource /** * @ORM\OneToMany(targetEntity="Step", mappedBy="exercise", cascade={"all"}, orphanRemoval=true) + * * @ORM\OrderBy({"order" = "ASC"}) * * @var ArrayCollection|Step[] @@ -313,7 +317,7 @@ public function getCorrectionMode(): string return $this->correctionMode; } - public function setDateCorrection(?\DateTimeInterface $dateCorrection = null): void + public function setDateCorrection(\DateTimeInterface $dateCorrection = null): void { $this->dateCorrection = $dateCorrection; } @@ -378,12 +382,12 @@ public function getIntermediateScores(): ?string return $this->intermediateScores; } - public function setIntermediateScores(?string $intermediateScores = null): void + public function setIntermediateScores(string $intermediateScores = null): void { $this->intermediateScores = $intermediateScores; } - public function setAttemptsReachedMessage(?string $attemptsReachedMessage = null): void + public function setAttemptsReachedMessage(string $attemptsReachedMessage = null): void { $this->attemptsReachedMessage = $attemptsReachedMessage; } @@ -543,7 +547,7 @@ public function setScoreRule(?string $scoreRule): void $this->scoreRule = $scoreRule; } - public function setSuccessScore(?float $successScore = null): void + public function setSuccessScore(float $successScore = null): void { $this->successScore = $successScore; } @@ -603,16 +607,6 @@ public function getPicking(): string return $this->picking; } - public function setMaxPapers(?int $maxPapers = null): void - { - $this->maxPapers = $maxPapers; - } - - public function getMaxPapers(): ?int - { - return $this->maxPapers; - } - public function isAllPapersStatistics(): bool { return $this->allPapersStatistics; diff --git a/src/plugin/exo/Library/Model/AttemptParametersTrait.php b/src/plugin/exo/Library/Model/AttemptParametersTrait.php index 7e022b4da75..03f7f737ade 100644 --- a/src/plugin/exo/Library/Model/AttemptParametersTrait.php +++ b/src/plugin/exo/Library/Model/AttemptParametersTrait.php @@ -68,8 +68,10 @@ trait AttemptParametersTrait * @ORM\Column(name="max_day_attempts", type="integer") * * @var int + * + * @todo not implemented, to remove */ - private $maxAttemptsPerDay = 0; + public $maxAttemptsPerDay = 0; /** * Sets random order. @@ -170,29 +172,4 @@ public function getMaxAttempts() { return $this->maxAttempts; } - - /** - * Sets max attempts. - * - * @param int $maxAttemptsPerDay - */ - public function setMaxAttemptsPerDay($maxAttemptsPerDay) - { - if ($maxAttemptsPerDay > $this->maxAttempts) { - //we can't try more times per day than the maximum allowed attempts defined - $this->maxAttemptsPerDay = $this->maxAttempts; - } - - $this->maxAttemptsPerDay = $maxAttemptsPerDay; - } - - /** - * Gets max attempts. - * - * @return int - */ - public function getMaxAttemptsPerDay() - { - return $this->maxAttemptsPerDay; - } } diff --git a/src/plugin/exo/Listener/Resource/ExerciseListener.php b/src/plugin/exo/Listener/Resource/ExerciseListener.php index a67a1e72a24..f8e6f1cf93c 100644 --- a/src/plugin/exo/Listener/Resource/ExerciseListener.php +++ b/src/plugin/exo/Listener/Resource/ExerciseListener.php @@ -88,14 +88,10 @@ public function onLoad(LoadResourceEvent $event) // fetch additional user data $lastAttempt = null; - $nbUserPapers = 0; - //$nbUserPapersDayCount = 0; $userEvaluation = null; if ($currentUser instanceof User) { $lastAttempt = $this->attemptManager->getLastPaper($exercise, $currentUser); - $nbUserPapers = (int) $this->paperManager->countUserFinishedPapers($exercise, $currentUser); - //$nbUserPapersDayCount = (int) $this->paperManager->countUserFinishedDayPapers($exercise, $currentUser); $userEvaluation = $this->serializer->serialize( $this->resourceEvalManager->getUserEvaluation($exercise->getResourceNode(), $currentUser), [Options::SERIALIZE_MINIMAL] @@ -104,12 +100,8 @@ public function onLoad(LoadResourceEvent $event) $event->setData([ 'quiz' => $this->serializer->serialize($exercise, $options), - //'paperCount' => (int) $this->paperManager->countExercisePapers($exercise), - // user data 'lastAttempt' => $lastAttempt ? $this->paperManager->serialize($lastAttempt) : null, - 'userPaperCount' => $nbUserPapers, - //'userPaperDayCount' => $nbUserPapersDayCount, 'userEvaluation' => $userEvaluation, ]); $event->stopPropagation(); diff --git a/src/plugin/exo/Manager/Attempt/PaperManager.php b/src/plugin/exo/Manager/Attempt/PaperManager.php index 2ff5d26641c..0f3b949f3f2 100644 --- a/src/plugin/exo/Manager/Attempt/PaperManager.php +++ b/src/plugin/exo/Manager/Attempt/PaperManager.php @@ -2,6 +2,7 @@ namespace UJM\ExoBundle\Manager\Attempt; +use Claroline\AppBundle\API\Crud; use Claroline\AppBundle\Persistence\ObjectManager; use Claroline\CoreBundle\Entity\Resource\ResourceEvaluation; use Claroline\CoreBundle\Entity\User; @@ -36,6 +37,9 @@ class PaperManager /** @var EventDispatcherInterface */ private $eventDispatcher; + /** @var Crud */ + private $crud; + /** @var PaperSerializer */ private $serializer; @@ -52,6 +56,7 @@ public function __construct( AuthorizationCheckerInterface $authorization, ObjectManager $om, EventDispatcherInterface $eventDispatcher, + Crud $crud, PaperSerializer $serializer, ItemManager $itemManager, ScoreManager $scoreManager, @@ -61,6 +66,7 @@ public function __construct( $this->om = $om; $this->repository = $om->getRepository(Paper::class); $this->eventDispatcher = $eventDispatcher; + $this->crud = $crud; $this->serializer = $serializer; $this->itemManager = $itemManager; $this->scoreManager = $scoreManager; @@ -201,7 +207,7 @@ public function calculateTotal(Paper $paper): ?float /** * Returns the papers for a given exercise, in a JSON format. */ - public function serializeExercisePapers(Exercise $exercise, ?User $user = null): array + public function serializeExercisePapers(Exercise $exercise, User $user = null): array { if (!empty($user)) { // Load papers for of a single user @@ -229,7 +235,12 @@ public function serializeExercisePapers(Exercise $exercise, ?User $user = null): public function delete(array $papers): void { foreach ($papers as $paper) { + $resourceAttempt = $this->repository->getPaperAttempt($paper); + $this->om->remove($paper); + if ($resourceAttempt) { + $this->crud->delete($resourceAttempt); + } } $this->om->flush(); @@ -243,14 +254,6 @@ public function countUserFinishedPapers(Exercise $exercise, User $user): int return $this->repository->countUserFinishedPapers($exercise, $user); } - /** - * Returns the number of finished papers already done by the user for a given exercise for the current day. - */ - public function countUserFinishedDayPapers(Exercise $exercise, User $user): int - { - return $this->repository->countUserFinishedDayPapers($exercise, $user); - } - /** * Returns the number of papers already done for a given exercise. */ @@ -358,7 +361,7 @@ public function generateResourceEvaluation(Paper $paper, bool $finished): Resour if (isset($structure['steps'])) { foreach ($structure['steps'] as $step) { $nbQuestions += count(array_filter($step['items'], function (array $item) { - /// only get answerable items + // / only get answerable items return $this->itemManager->isQuestionType($item['type']); })); } diff --git a/src/plugin/exo/Manager/AttemptManager.php b/src/plugin/exo/Manager/AttemptManager.php index 0cc65d450dd..aadbea803be 100644 --- a/src/plugin/exo/Manager/AttemptManager.php +++ b/src/plugin/exo/Manager/AttemptManager.php @@ -91,14 +91,10 @@ public function __construct( * * Based on the maximum attempt allowed and the number of already done by the user. * - * @param User $user - * * @return bool */ public function canPass(Exercise $exercise, User $user = null) { - // TODO : max attempts by day - $canPass = true; if ($user) { $max = $exercise->getMaxAttempts(); @@ -115,8 +111,6 @@ public function canPass(Exercise $exercise, User $user = null) public function getErrors(Exercise $exercise, User $user = null) { - // TODO : max attempts by day - $errors = []; if ($user) { $max = $exercise->getMaxAttempts(); @@ -140,8 +134,6 @@ public function getErrors(Exercise $exercise, User $user = null) * A user can submit to a paper only if it is its own and the paper is not closed (= no end). * ATTENTION : As is, anonymous have access to all the other anonymous Papers !!! * - * @param User $user - * * @return bool */ public function canUpdate(Paper $paper, User $user = null) diff --git a/src/plugin/exo/Repository/PaperRepository.php b/src/plugin/exo/Repository/PaperRepository.php index 8a57cf7f925..36f7a911e04 100644 --- a/src/plugin/exo/Repository/PaperRepository.php +++ b/src/plugin/exo/Repository/PaperRepository.php @@ -54,36 +54,6 @@ public function findUnfinishedPapers(Exercise $exercise, User $user) ->getResult(); } - /** - * Returns the unfinished papers of a user for a given exercise for the current day, if any. - * - * @return int - */ - public function countUserFinishedDayPapers(Exercise $exercise, User $user) - { - $today = new \DateTime(); - $today->setTime(0, 0); - $tomorrow = clone $today; - $tomorrow->add(new \DateInterval('P1D')); - - return (int) $this->getEntityManager() - ->createQuery(' - SELECT COUNT(p) - FROM UJM\ExoBundle\Entity\Attempt\Paper AS p - WHERE p.user = :user - AND p.exercise = :exercise - AND p.end >= :today - AND p.end <= :tomorrow - ') - ->setParameters([ - 'user' => $user, - 'exercise' => $exercise, - 'today' => $today, - 'tomorrow' => $tomorrow, - ]) - ->getSingleScalarResult(); - } - /** * Finds the score of a paper by summing the score of each answer. * @@ -124,6 +94,23 @@ public function isFullyEvaluated(Paper $paper) ->getSingleScalarResult(); } + /** + * Retrieve a Claroline attempt (ResourceEvaluation) from a paper. + */ + public function getPaperAttempt(Paper $paper) + { + return $this->getEntityManager() + ->createQuery(' + SELECT a + FROM Claroline\CoreBundle\Entity\Resource\ResourceEvaluation AS a + WHERE a.data LIKE :paperId + ') + ->setParameters([ + 'paperId' => '%'.$paper->getUuid().'%', + ]) + ->getOneOrNullResult(); + } + /** * Returns the number of papers for an exercise. * diff --git a/src/plugin/exo/Resources/config/services/manager.yml b/src/plugin/exo/Resources/config/services/manager.yml index 339f445a164..b8bc7352e75 100644 --- a/src/plugin/exo/Resources/config/services/manager.yml +++ b/src/plugin/exo/Resources/config/services/manager.yml @@ -13,6 +13,7 @@ services: - '@security.authorization_checker' - '@Claroline\AppBundle\Persistence\ObjectManager' - '@event_dispatcher' + - '@Claroline\AppBundle\API\Crud' - '@ujm_exo.serializer.paper' - '@UJM\ExoBundle\Manager\Item\ItemManager' - '@UJM\ExoBundle\Manager\Attempt\ScoreManager' diff --git a/src/plugin/exo/Resources/modules/quiz/player/selectors.js b/src/plugin/exo/Resources/modules/quiz/player/selectors.js index 1f89be70294..f6418991702 100644 --- a/src/plugin/exo/Resources/modules/quiz/player/selectors.js +++ b/src/plugin/exo/Resources/modules/quiz/player/selectors.js @@ -1,4 +1,5 @@ import {createSelector} from 'reselect' +import get from 'lodash/get' import uniq from 'lodash/uniq' import {selectors as securitySelectors} from '#/main/app/security/store/selectors' @@ -128,14 +129,12 @@ const maxAttempts = createSelector( [paperParameters], (parameters) => parameters.maxAttempts || 0 ) -const maxAttemptsPerDay = createSelector( - [paperParameters], - (parameters) => parameters.maxAttemptsPerDay || 0 -) const hasMoreAttempts = createSelector( - [maxAttempts, maxAttemptsPerDay, playerSelectors.userPaperCount, playerSelectors.userPaperDayCount], - (maxAttempts, maxAttemptsPerDay, userPaperCount, userPaperDayCount) => (!maxAttempts || maxAttempts > userPaperCount) && (!maxAttemptsPerDay || maxAttemptsPerDay > userPaperDayCount) + [maxAttempts, quizSelectors.evaluation], + (maxAttempts, evaluation) => { + return !evaluation || !maxAttempts || maxAttempts > get(evaluation, 'nbAttempts') + } ) const steps = createSelector( @@ -311,7 +310,6 @@ export const select = { progressionDisplayed, hasMoreAttempts, maxAttempts, - maxAttemptsPerDay, attemptsReachedMessage, items, countItems, diff --git a/src/plugin/exo/Resources/modules/resources/quiz/editor/components/parameters.jsx b/src/plugin/exo/Resources/modules/resources/quiz/editor/components/parameters.jsx index 00a6654301a..e8a15aa350c 100644 --- a/src/plugin/exo/Resources/modules/resources/quiz/editor/components/parameters.jsx +++ b/src/plugin/exo/Resources/modules/resources/quiz/editor/components/parameters.jsx @@ -715,58 +715,6 @@ const EditorParameters = props => { } } ] - }, { - name: 'parameters._maxAttemptsPerDay', - label: trans('restrict_user_attempts_per_day', {}, 'quiz'), - help: trans('restrict_user_attempts_per_day_help', {}, 'quiz'), - type: 'boolean', - displayed: false, // not implemented - calculated: (quiz) => get(quiz, 'parameters._maxAttemptsPerDay') || 0 < get(quiz, 'parameters.maxAttemptsPerDay'), - onChange: (restrict) => { - if (restrict) { - props.update('parameters.maxAttemptsPerDay', null) - } else { - props.update('parameters.maxAttemptsPerDay', 0) - } - }, - linked: [ - { - name: 'parameters.maxAttemptsPerDay', - label: trans('attempts_count', {}, 'quiz'), - type: 'number', - required: true, - displayed: (quiz) => get(quiz, 'parameters._maxAttemptsPerDay') || 0 < get(quiz, 'parameters.maxAttemptsPerDay'), - options: { - min: 0 - } - } - ] - }, { - name: 'parameters._maxPapers', - label: trans('restrict_total_attempts', {}, 'quiz'), - help: trans('restrict_total_attempts_help', {}, 'quiz'), - type: 'boolean', - displayed: false, // not implemented - calculated: (quiz) => get(quiz, 'parameters._maxPapers') || 0 < get(quiz, 'parameters.maxPapers'), - onChange: (restrict) => { - if (restrict) { - props.update('parameters.maxPapers', null) - } else { - props.update('parameters.maxPapers', 0) - } - }, - linked: [ - { - name: 'parameters.maxPapers', - label: trans('attempts_count', {}, 'quiz'), - type: 'number', - required: true, - displayed: (quiz) => get(quiz, 'parameters._maxPapers') || 0 < get(quiz, 'parameters.maxPapers'), - options: { - min: 0 - } - } - ] } ] } diff --git a/src/plugin/exo/Resources/modules/resources/quiz/editor/validation.js b/src/plugin/exo/Resources/modules/resources/quiz/editor/validation.js index 1fe37feab67..13024a738e5 100644 --- a/src/plugin/exo/Resources/modules/resources/quiz/editor/validation.js +++ b/src/plugin/exo/Resources/modules/resources/quiz/editor/validation.js @@ -2,7 +2,7 @@ import isEmpty from 'lodash/isEmpty' import merge from 'lodash/merge' import {notBlank, notEmpty, number, gteZero, gtZero, chainSync} from '#/main/app/data/types/validators' -import {trans, tval} from '#/main/app/intl/translation' +import {tval} from '#/main/app/intl/translation' import {validate as validateItem} from '#/plugin/exo/items/validation' import {constants} from '#/plugin/exo/resources/quiz/constants' @@ -53,16 +53,6 @@ function validate(quiz) { paramErrors.duration = chainSync(parameters.duration, {}, [notBlank, number, gteZero]) paramErrors.maxAttempts = chainSync(parameters.maxAttempts, {}, [notBlank, number, gteZero]) - paramErrors.maxAttemptsPerDay = chainSync(parameters.maxAttemptsPerDay, {}, [notBlank, number, gteZero, (value) => { - if (parameters.maxAttempts && value > parameters.maxAttempts) { - return trans('must_be_less_than_max_attempts', {}, 'quiz') - } - }]) - paramErrors.maxPapers = chainSync(parameters.maxPapers, {}, [notBlank, number, gteZero, (value) => { - if (parameters.maxAttempts && value < parameters.maxAttempts && value !== 0) { - return trans('must_be_more_than_max_attempts', {}, 'quiz') - } - }]) if (!isEmpty(paramErrors)) { errors.parameters = paramErrors diff --git a/src/plugin/exo/Resources/modules/resources/quiz/player/store/reducer.js b/src/plugin/exo/Resources/modules/resources/quiz/player/store/reducer.js index 07293071051..c3804fc8070 100644 --- a/src/plugin/exo/Resources/modules/resources/quiz/player/store/reducer.js +++ b/src/plugin/exo/Resources/modules/resources/quiz/player/store/reducer.js @@ -1,24 +1,8 @@ -import {makeInstanceAction} from '#/main/app/store/actions' import {makeReducer, combineReducers} from '#/main/app/store/reducer' -import {RESOURCE_LOAD} from '#/main/core/resource/store/actions' - -import {selectors as quizSelectors} from '#/plugin/exo/resources/quiz/store/selectors' import {ATTEMPT_FINISH} from '#/plugin/exo/resources/quiz/player/store/actions' const reducer = combineReducers({ - paperCount: makeReducer(0, { - [makeInstanceAction(RESOURCE_LOAD, quizSelectors.STORE_NAME)]: (state, action) => action.resourceData.paperCount || state, - [ATTEMPT_FINISH]: (state) => state + 1 - }), - userPaperCount: makeReducer(0, { - [makeInstanceAction(RESOURCE_LOAD, quizSelectors.STORE_NAME)]: (state, action) => action.resourceData.userPaperCount || state, - [ATTEMPT_FINISH]: (state) => state + 1 - }), - userPaperDayCount: makeReducer(0, { - [makeInstanceAction(RESOURCE_LOAD, quizSelectors.STORE_NAME)]: (state, action) => action.resourceData.userPaperDayCount || state, - [ATTEMPT_FINISH]: (state) => state + 1 - }), // the base evaluation attempt attempt: makeReducer(null, { [ATTEMPT_FINISH]: (state, action) => action.attempt diff --git a/src/plugin/exo/Resources/modules/resources/quiz/player/store/selectors.js b/src/plugin/exo/Resources/modules/resources/quiz/player/store/selectors.js index 447b33d003f..0687c7c9371 100644 --- a/src/plugin/exo/Resources/modules/resources/quiz/player/store/selectors.js +++ b/src/plugin/exo/Resources/modules/resources/quiz/player/store/selectors.js @@ -9,21 +9,6 @@ const player = createSelector( (resourceState) => resourceState[STORE_NAME] ) -const paperCount = createSelector( - [player], - (playerState) => playerState.paperCount -) - -const userPaperCount = createSelector( - [player], - (playerState) => playerState.userPaperCount -) - -const userPaperDayCount = createSelector( - [player], - (playerState) => playerState.userPaperDayCount -) - const attempt = createSelector( [player], (playerState) => playerState.attempt @@ -32,8 +17,5 @@ const attempt = createSelector( export const selectors = { STORE_NAME, - paperCount, - userPaperCount, - userPaperDayCount, attempt } diff --git a/src/plugin/exo/Resources/modules/resources/quiz/prop-types.js b/src/plugin/exo/Resources/modules/resources/quiz/prop-types.js index 96d5e03379f..88f77d94a22 100644 --- a/src/plugin/exo/Resources/modules/resources/quiz/prop-types.js +++ b/src/plugin/exo/Resources/modules/resources/quiz/prop-types.js @@ -67,9 +67,7 @@ const Quiz = { showMetadata: true, duration: 0, maxAttempts: 0, - maxAttemptsPerDay: 0, mandatoryQuestions: false, - maxPapers: 0, interruptible: true, showCorrectionAt: constants.QUIZ_RESULTS_AT_VALIDATION, correctionDate: '', diff --git a/src/plugin/exo/Resources/modules/resources/quiz/store/selectors.js b/src/plugin/exo/Resources/modules/resources/quiz/store/selectors.js index 0c87390a7eb..e0af2663c09 100644 --- a/src/plugin/exo/Resources/modules/resources/quiz/store/selectors.js +++ b/src/plugin/exo/Resources/modules/resources/quiz/store/selectors.js @@ -1,6 +1,7 @@ import {createSelector} from 'reselect' import {selectors as securitySelectors} from '#/main/app/security/store/selectors' +import {selectors as resourceSelectors} from '#/main/core/resource/store/selectors' const STORE_NAME = 'ujm_exercise' @@ -11,6 +12,8 @@ const STORE_NAME = 'ujm_exercise' */ const resource = (state) => state[STORE_NAME] +const evaluation = resourceSelectors.resourceEvaluation + /** * Gets the full quiz data. * @@ -104,6 +107,7 @@ export const selectors = { STORE_NAME, resource, + evaluation, quiz, id, steps, diff --git a/src/plugin/exo/Serializer/ExerciseSerializer.php b/src/plugin/exo/Serializer/ExerciseSerializer.php index c652d31822e..00bb02fb570 100644 --- a/src/plugin/exo/Serializer/ExerciseSerializer.php +++ b/src/plugin/exo/Serializer/ExerciseSerializer.php @@ -120,8 +120,6 @@ private function serializeParameters(Exercise $exercise): array $parameters = [ 'type' => $exercise->getType(), 'maxAttempts' => $exercise->getMaxAttempts(), - 'maxAttemptsPerDay' => $exercise->getMaxAttemptsPerDay(), - 'maxPapers' => $exercise->getMaxPapers(), 'showFeedback' => $exercise->getShowFeedback(), 'progressionDisplayed' => $exercise->isProgressionDisplayed(), 'timeLimited' => $exercise->isTimeLimited(), // todo : remove me @@ -199,8 +197,6 @@ private function deserializeParameters(Exercise $exercise, array $parameters) $this->sipe('showTitles', 'setShowTitles', $parameters, $exercise); $this->sipe('showQuestionTitles', 'setShowQuestionTitles', $parameters, $exercise); $this->sipe('mandatoryQuestions', 'setMandatoryQuestions', $parameters, $exercise); - $this->sipe('maxAttemptsPerDay', 'setMaxAttemptsPerDay', $parameters, $exercise); - $this->sipe('maxPapers', 'setMaxPapers', $parameters, $exercise); $this->sipe('successMessage', 'setSuccessMessage', $parameters, $exercise); $this->sipe('failureMessage', 'setFailureMessage', $parameters, $exercise); $this->sipe('showScoreAt', 'setMarkMode', $parameters, $exercise); @@ -226,10 +222,10 @@ private function deserializeParameters(Exercise $exercise, array $parameters) if (isset($parameters['showFullCorrection'])) { $exercise->setMinimalCorrection(!$parameters['showFullCorrection']); } - $success = isset($parameters['successScore']) && - '' !== $parameters['successScore'] && - 0 <= $parameters['successScore'] && - 100 >= $parameters['successScore'] ? + $success = isset($parameters['successScore']) + && '' !== $parameters['successScore'] + && 0 <= $parameters['successScore'] + && 100 >= $parameters['successScore'] ? $parameters['successScore'] : null; $exercise->setSuccessScore($success); @@ -366,8 +362,6 @@ public function getCopyOptions() * The client may send dirty data, we need to clean them before storing it in DB. * (duplicated from ItemSerializer). * - * @param $score - * * @return array */ private function sanitizeScore($score) diff --git a/src/plugin/exo/Tests/Manager/Attempt/PaperManagerTest.php b/src/plugin/exo/Tests/Manager/Attempt/PaperManagerTest.php index 09756842fb9..ac426892c46 100644 --- a/src/plugin/exo/Tests/Manager/Attempt/PaperManagerTest.php +++ b/src/plugin/exo/Tests/Manager/Attempt/PaperManagerTest.php @@ -27,6 +27,7 @@ protected function setUp(): void $this->mock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface'), $this->om, $this->mock('Symfony\Component\EventDispatcher\EventDispatcherInterface'), + $this->mock('Claroline\AppBundle\API\Crud'), $this->serializer, $this->mock('UJM\ExoBundle\Manager\Item\ItemManager'), $this->mock('UJM\ExoBundle\Manager\Attempt\ScoreManager'),