/** * Update the Exercise metadata. * * @param Exercise $exercise * @param \stdClass $metadata * * @throws ValidationException */ public function updateMetadata(Exercise $exercise, \stdClass $metadata) { $errors = $this->validator->validateExerciseMetadata($metadata); if (count($errors) > 0) { throw new ValidationException('Exercise metadata are not valid', $errors); } // Update ResourceNode $node = $exercise->getResourceNode(); $node->setName($metadata->title); // Update Exercise $exercise->setDescription($metadata->description); $exercise->setType($metadata->type); $exercise->setPickSteps($metadata->pick ? $metadata->pick : 0); $exercise->setShuffle($metadata->random); $exercise->setKeepSteps($metadata->keepSteps); $exercise->setMaxAttempts($metadata->maxAttempts); $exercise->setLockAttempt($metadata->lockAttempt); $exercise->setDispButtonInterrupt($metadata->dispButtonInterrupt); $exercise->setMetadataVisible($metadata->metadataVisible); $exercise->setMarkMode($metadata->markMode); $exercise->setCorrectionMode($metadata->correctionMode); $exercise->setAnonymous($metadata->anonymous); $exercise->setDuration($metadata->duration); $exercise->setStatistics($metadata->statistics ? true : false); $exercise->setMinimalCorrection($metadata->minimalCorrection ? true : false); $correctionDate = null; if (!empty($metadata->correctionDate) && CorrectionMode::AFTER_DATE === $metadata->correctionMode) { $correctionDate = \DateTime::createFromFormat('Y-m-d\\TH:i:s', $metadata->correctionDate); } $exercise->setDateCorrection($correctionDate); // Save to DB $this->om->persist($exercise); $this->om->flush(); }
public function onCopy(CopyResourceEvent $event) { $em = $this->container->get('doctrine.orm.entity_manager'); $resource = $event->getResource(); $exerciseToCopy = $em->getRepository('UJMExoBundle:Exercise')->find($resource->getId()); $listQuestionsExoToCopy = $em->getRepository('UJMExoBundle:ExerciseQuestion')->findBy(array('exercise' => $exerciseToCopy->getId())); $newExercise = new Exercise(); $newExercise->setName($resource->getName()); $newExercise->setTitle($exerciseToCopy->getTitle()); $newExercise->setDescription($exerciseToCopy->getDescription()); $newExercise->setShuffle($exerciseToCopy->getShuffle()); $newExercise->setNbQuestion($exerciseToCopy->getNbQuestion()); $newExercise->setDateCreate($exerciseToCopy->getDateCreate()); $newExercise->setDuration($exerciseToCopy->getDuration()); $newExercise->setNbQuestionPage($exerciseToCopy->getNbQuestionPage()); $newExercise->setDoprint($exerciseToCopy->getDoprint()); $newExercise->setMaxAttempts($exerciseToCopy->getMaxAttempts()); $newExercise->setCorrectionMode($exerciseToCopy->getCorrectionMode()); $newExercise->setDateCorrection($exerciseToCopy->getDateCorrection()); $newExercise->setMarkMode($exerciseToCopy->getMarkMode()); $newExercise->setStartDate($exerciseToCopy->getStartDate()); $newExercise->setUseDateEnd($exerciseToCopy->getUseDateEnd()); $newExercise->setEndDate($exerciseToCopy->getEndDate()); $newExercise->setDispButtonInterrupt($exerciseToCopy->getDispButtonInterrupt()); $newExercise->setLockAttempt($exerciseToCopy->getLockAttempt()); $newExercise->setPublished($exerciseToCopy->getPublished()); $em->persist($newExercise); $em->flush(); foreach ($listQuestionsExoToCopy as $eq) { $questionToAdd = $em->getRepository('UJMExoBundle:Question')->find($eq->getQuestion()); $exerciseQuestion = new ExerciseQuestion($newExercise, $questionToAdd); $exerciseQuestion->setOrdre($eq->getOrdre()); $em->persist($exerciseQuestion); } $user = $this->container->get('security.token_storage')->getToken()->getUser(); $subscription = new Subscription($user, $newExercise); $subscription->setAdmin(true); $subscription->setCreator(true); $em->persist($subscription); $em->flush(); $event->setCopy($newExercise); $event->stopPropagation(); }
/** * create the exercise. * * @param array $exercise properties of the exercise * @param User $user * * @return Exercise */ private function createExo(array $exercise, User $user) { $newExercise = new Exercise(); $newExercise->setDescription($exercise['description']); $newExercise->setShuffle($exercise['shuffle']); $newExercise->setPickSteps($exercise['nbQuestion']); $newExercise->setKeepSteps($exercise['keepSameQuestion']); $newExercise->setDuration($exercise['duration']); $newExercise->setDoprint($exercise['doPrint']); $newExercise->setMaxAttempts($exercise['maxAttempts']); $newExercise->setDateCorrection(new \Datetime()); $newExercise->setCorrectionMode($exercise['correctionMode']); $newExercise->setMarkMode($exercise['markMode']); $newExercise->setDispButtonInterrupt($exercise['dispButtonInterrupt']); $newExercise->setLockAttempt($exercise['lockAttempt']); $newExercise->setAnonymous($exercise['anonymous']); $newExercise->setType($exercise['type']); $this->om->persist($newExercise); $this->subscriptionManager->subscribe($newExercise, $user); $this->om->flush(); return $newExercise; }
/** * create the exercise * * @param String $title * @param Object User $user */ private function createExo($title, $user) { $newExercise = new Exercise(); $newExercise->setTitle($title); $newExercise->setDateCreate(new \Datetime()); $newExercise->setNbQuestionPage(1); $newExercise->setNbQuestion(0); $newExercise->setDuration(0); $newExercise->setMaxAttempts(0); $newExercise->setStartDate(new \Datetime()); $newExercise->setEndDate(new \Datetime()); $newExercise->setDateCorrection(new \Datetime()); $newExercise->setCorrectionMode('1'); $newExercise->setMarkMode('1'); $newExercise->setPublished(FALSE); $this->om->persist($newExercise); $this->om->flush(); $subscription = new Subscription($user, $newExercise); $subscription->setAdmin(1); $subscription->setCreator(1); $this->om->persist($subscription); $this->om->flush(); return $newExercise; }