Ejemplo n.º 1
0
 /**
  * @Route("/courses_new", name="new_course")
  * @Secure(roles="ROLE_USER")
  */
 public function newCourseAction()
 {
     $user = $this->container->get('security.context')->getToken()->getUser();
     $course = new Course();
     $course->setUser($user);
     $form = $this->createForm(new CourseType(), $course, array());
     if ('POST' == $this->getRequest()->getMethod()) {
         // parameter handling
         $form->bind($this->getRequest());
         if (!$this->getRequest()->request->has($form->getName())) {
             echo 'No form fields specified';
             die;
         } else {
             if ($form->isValid()) {
                 $course->setHashedUrl(md5(time() . '_' . $course->getUser()->getId() . '_' . $course->getName()));
                 $this->container->get('doctrine')->getManager()->persist($course);
                 $this->container->get('doctrine')->getManager()->flush($course);
                 return new RedirectResponse($this->container->get('router')->generate('courses'));
             }
         }
     }
     return $this->render('PixelbonusSiteBundle:Courses:new.html.twig', array('form' => $form->createView()));
 }
Ejemplo n.º 2
0
 /**
  * @Route("/qrset_new/{course}", name="new_qrset")
  * @Secure(roles="ROLE_USER")
  */
 public function newQrSetAction(Course $course)
 {
     $user = $this->container->get('security.context')->getToken()->getUser();
     if ($course->getUser() != $user) {
         throw new \Exception('User not authorized to access this course');
     }
     $qrset = new QrSet();
     $qrset->setCourse($course);
     $qrset->setQuantity(QrSet::DEFAULT_QUANTITY);
     $form = $this->createForm(new QrSetType(), $qrset, array());
     if ('POST' == $this->getRequest()->getMethod()) {
         // parameter handling
         $form->bind($this->getRequest());
         if (!$this->getRequest()->request->has($form->getName())) {
             echo 'No form fields specified';
             die;
         } else {
             if ($form->isValid()) {
                 // Set the tags
                 $qrset->getTags()->clear();
                 foreach ($qrset->tagsFromString as $curTag) {
                     $curTagEntity = $this->container->get('doctrine')->getManager()->getRepository('Pixelbonus\\SiteBundle\\Entity\\Tag')->findOneBy(array('name' => $curTag));
                     if (!isset($curTagEntity)) {
                         $curTagEntity = new Tag();
                         $curTagEntity->setName($curTag);
                         $this->container->get('doctrine')->getManager()->persist($curTagEntity);
                         $this->container->get('doctrine')->getManager()->flush($curTagEntity);
                     }
                     $qrset->getTags()->add($curTagEntity);
                 }
                 $this->container->get('doctrine')->getManager()->persist($qrset);
                 $this->container->get('doctrine')->getManager()->flush($qrset);
                 return new RedirectResponse($this->container->get('router')->generate('download_qr', array('qrset' => $qrset->getId(), 'quantity' => $qrset->getQuantity())));
             }
         }
     }
     // Get existing tags
     $existingTags = array();
     foreach ($course->getQrSets() as $curQrSet) {
         foreach ($curQrSet->getTags() as $curTag) {
             $existingTags[] = $curTag;
         }
     }
     return $this->render('PixelbonusSiteBundle:QR:new.html.twig', array('course' => $course, 'form' => $form->createView(), 'existingTags' => $existingTags));
 }