public function load(ObjectManager $manager) { $resourceType = $manager->getRepository('ClarolineCoreBundle:Resource\\ResourceType')->findOneByName('ujm_exercise'); $rtid = $resourceType->getId(); //$event = $this->dispatcher->dispatch('create_' . $resourceType, 'CreateResource', array($parent, $resourceType)); $exercise = new Exercise(); $exercise->setTitle('ExoFIX Title 1'); $exercise->setNbQuestion(0); $exercise->setDateCreate(new \Datetime()); $exercise->setDuration(0); $exercise->setNbQuestionPage(1); $exercise->setMaxAttempts(0); $exercise->setCorrectionMode(4); //availability_of_correction: 1:at_the_end_of_assessment, 2: after_the_last_attempt, 3: from, 4: never $exercise->setMarkMode(1); //availability_of_score: 1:at_the_same_time_that_the_correction, 2: at_the_end_of_assessment $exercise->setStartDate(new \Datetime()); $exercise->setPublished(true); $manager->persist($exercise); $manager->flush(); $this->addReference('exercise1', $exercise); }
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 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; }