/**
  * Create an Exercise
  *
  * @access private
  *
  * @param \UJM\ExoBundle\Entity\Exercise $exercise exercise to create
  */
 private function onSuccess(Exercise $exercise)
 {
     // \ pour instancier un objet du namespace global et non pas de l'actuel
     $exercise->setDateCreate(new \Datetime());
     $exercise->setNbQuestionPage(1);
     $this->em->persist($exercise);
     $this->em->flush();
     if ($this->action == 'add') {
         $subscription = new Subscription($this->user, $exercise);
         $subscription->setAdmin(1);
         $subscription->setCreator(1);
         $this->em->persist($subscription);
         $this->em->flush();
     }
 }
 /**
  * Subscribes a Use to an Exercise.
  *
  * @param Exercise $exercise
  * @param User     $user
  * @param bool     $flush
  *
  * @return SubscriptionManager
  */
 public function subscribe(Exercise $exercise, User $user, $flush = false)
 {
     $subscription = new Subscription();
     $subscription->setUser($user);
     $subscription->setExercise($exercise);
     $subscription->setAdmin(true);
     $subscription->setCreator(true);
     $this->om->persist($subscription);
     if ($flush) {
         $this->om->flush();
     }
     return $this;
 }
 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;
 }