Пример #1
0
 /**
  * @DI\Observe("delete_ujm_exercise")
  *
  * @param DeleteResourceEvent $event
  */
 public function onDelete(DeleteResourceEvent $event)
 {
     $em = $this->container->get('doctrine.orm.entity_manager');
     $exercise = $event->getResource();
     $nbPapers = $em->getRepository('UJMExoBundle:Paper')->countExercisePapers($event->getResource());
     if (0 === $nbPapers) {
         $this->container->get('ujm.exo.subscription_manager')->deleteSubscriptions($exercise);
         $em->remove($exercise);
     } else {
         // If papers, the Exercise is not completely removed
         $event->enableSoftDelete();
         $em->remove($exercise->getResourceNode());
         $exercise->archiveExercise();
         $em->persist($exercise);
         $em->flush();
     }
     $event->stopPropagation();
 }