/** * Creates a new Comment entity. * */ public function createAction($id) { $entity = new Comment(); $request = $this->getRequest(); $form = $this->createForm(new CommentType(), $entity); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $sujet = $em->getRepository('ProjetForumBundle:Sujet')->find($id); if (!$sujet) { throw $this->createNotFoundException('Unable to find Sujet entity.'); } $sujet->addCommentaire($entity); $notif = new Notification(); $cours = $sujet->getEnseignement(); $notif->setEnseignement($cours); $user = $this->container->get('security.context')->getToken()->getUser(); $router = $this->get('router'); $uri_sujet = $router->generate('sujet_show', array('id' => $sujet->getId())); $uri_cours = $router->generate('enseignement_show', array('id' => $cours->getId())); $notif->setNom($user->getUsername() . ' a commenté le sujet : ' . '<a href="' . $uri_sujet . '">' . $sujet->getNom() . '</a> du cours : ' . '<a href="' . $uri_cours . '">' . $cours->getNom() . '</a>'); $notif->setUser($user); $entity->setUser($user); $em = $this->getDoctrine()->getEntityManager(); //$entity->setCommentaire(md5($entity->getCommentaire())); $em->persist($entity); $em->persist($notif); $em->flush(); return $this->redirect($this->generateUrl('sujet_show', array('id' => $id))); } return $this->render('ProjetForumBundle:Comment:new.html.twig', array('entity' => $entity, 'form' => $form->createView(), 'id' => $id)); }
/** * Creates a new Enseignement entity. * */ public function createAction() { $entity = new Enseignement(); $request = $this->getRequest(); $form = $this->createForm(new EnseignementType(), $entity); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $router = $this->get('router'); $user = $this->container->get('security.context')->getToken()->getUser(); $entity->setEnseignant($user); $em->persist($entity); $em->flush(); $uri_cours = $router->generate('enseignement_show', array('id' => $entity->getId())); $notif = new Notification(); $notif->setEnseignement($entity); $notif->setNom('Vous êtes attribué à un nouveau cours : ' . '<a href="' . $uri_cours . '">' . $entity->getNom() . '</a>'); $notif->setUser($user); $em->persist($notif); $em->flush(); return $this->redirect($this->generateUrl('enseignement_show', array('id' => $entity->getId()))); } return $this->render('ProjetCoursBundle:Enseignement:new.html.twig', array('entity' => $entity, 'form' => $form->createView())); }
public function addNotification(\Projet\CoursBundle\Entity\Notification $notification) { $this->notifications[] = $notification; $notification->setUser($this); }
/** * Creates a new Sujet entity. * */ public function createAction($id) { $entity = new Sujet(); $request = $this->getRequest(); $form = $this->createForm(new SujetType(), $entity); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $cours = $em->getRepository('ProjetCoursBundle:enseignement')->find($id); $cours->addSujet($entity); $router = $this->get('router'); $uri_sujet = $router->generate('sujet_show', array('id' => $entity->getId())); $uri_cours = $router->generate('enseignement_show', array('id' => $cours->getId())); $user = $this->container->get('security.context')->getToken()->getUser(); $entity->setUser($user); $em->persist($entity); $em->flush(); $notif = new Notification(); $notif->setEnseignement($cours); $notif->setNom($user->getUsername() . " a créé un nouveau sujet : " . '<a href="' . $uri_sujet . '">' . $entity->getNom() . '</a>' . ' dans le forum du cours : ' . '<a href="' . $uri_cours . '">' . $cours->getNom() . '</a>'); $notif->setUser($user); $em->persist($notif); $em->flush(); return $this->redirect($this->generateUrl('sujet_show', array('id' => $entity->getId()))); } return $this->render('ProjetForumBundle:Sujet:new.html.twig', array('entity' => $entity, 'form' => $form->createView(), 'id' => $id)); }