/**
  * Creates new questionnaire entity.
  *
  * @Route("/new", name="questionnaire_post_new")
  * @Method({"GET", "POST", "DELETE"})
  *
  * NOTE: the Method annotation is optional, but it's a recommended practice
  * to constraint the HTTP methods each controller responds to (by default
  * it responds to all methods).
  */
 public function newAction(Request $request)
 {
     $questionnaire = new Questionnaire();
     $em = $this->getDoctrine()->getManager();
     $form = $this->createForm(new QuestionnaireType($em), $questionnaire);
     $form->handleRequest($request);
     // the isSubmitted() method is completely optional because the other
     // isValid() method already checks whether the form is submitted.
     // However, we explicitly add it to improve code readability.
     // See http://symfony.com/doc/current/best_practices/forms.html#handling-form-submits
     if ($form->isSubmitted() && $form->isValid()) {
         $projects = $form["projects"]->getData();
         foreach ($projects as $project) {
             $id = $project->getId();
             $dbProject = $em->getRepository('AppBundle:Project')->find($id);
             if (!$dbProject) {
                 throw $this - createNotFoundException('No $dbProject found for id ' . $id);
             }
             $dbProject->addQuestionnaire($questionnaire);
         }
         $statements = $form["statements"]->getData();
         foreach ($statements as $statement) {
             $id = $statement->getId();
             $dbStatement = $em->getRepository('AppBundle:Statement')->find($id);
             if (!$dbStatement) {
                 throw $this - createNotFoundException('No dbStatement found for id ' . $id);
             }
             $dbStatement->addQuestionnaire($questionnaire);
         }
         $em->persist($questionnaire);
         $em->flush();
         return $this->redirectToRoute('questionnaire_post_index');
     }
     return $this->render('Questionnaire/new.html.twig', array('questionnaire' => $questionnaire, 'form' => $form->createView()));
 }
Esempio n. 2
0
 public function processAction($id, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $task = $em->getRepository('EMMUserBundle:Task')->find($id);
     if (!$task) {
         throw $this > createNotFoundException('Task not found');
     }
     $form = $this->createCustomForm($task->getId(), 'PUT', 'emm_task_process');
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $successMessage = $this->get('translator')->trans('The task has been processed.');
         $warningMessage = $this->get('translator')->trans('The task has already been processed.');
         if ($task->getStatus() == 0) {
             $task->setStatus(1);
             $em->flush();
             if ($request->isXMLHttpRequest()) {
                 return new Response(json_encode(array('processed' => 1, 'success' => $successMessage)), 200, array('Content-Type' => 'application/json'));
             }
         } else {
             if ($request->isXMLHttpRequest()) {
                 return new Response(json_encode(array('processed' => 0, 'warning' => $warningMessage)), 200, array('Content-Type' => 'application/json'));
             }
         }
     }
 }
Esempio n. 3
0
 public function editAction($id)
 {
     $em = $this->getDoctrine()->getManager();
     $receta = $em->getRepository('EMLRecetaBundle:Receta')->find($id);
     if (!$receta) {
         $messageException = $this->get('translator')->trans('Recipe not found.');
         throw createNotFoundException($messageException);
     }
     $form = $this->createEditForm($receta);
     return $this->render('EMLRecetaBundle:Receta:edit.html.twig', array('form' => $form->createView()));
 }
 /**
     /**
 * Create comment
 *
 * @param Request $request
 * @param string  $slug
 * @throws NotFoundHttpException
 * @return array
 *
 * @Route("/{slug}/create-comment")
 * @Method("POST")
 * @Template("CoreBundle:Post:show.html.twig")
 */
 public function createCommentAction(Request $request, $slug)
 {
     //        exit(\Doctrine\Common\Util\Debug::dump($slug));
     //        var_dump($request); exit;
     $post = $this->em->getRepository('ModelBundle:Post')->findOneBy(array('slug' => $slug));
     if ($post === null) {
         throw createNotFoundException('Post Was Not Found');
     }
     $comment = new Comment();
     $comment->setPost($post);
     $form = $this->createForm(new CommentType(), $comment);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->em->persist($comment);
         $this->em->flush();
         $this->get('session')->getFlashBag()->add('success', 'Your comment was submitted successfully');
         return $this->redirect($this->generateUrl('blog_core_post_show', array('slug' => $post->getSlug())));
     }
     return array('post' => $post, 'form' => $form->createView());
 }
Esempio n. 5
0
    $whiteLists = (include __DIR__ . '/whiteList.php');
    $whiteLists = $request->getMethod() == 'GET' ? $whiteLists['get'] : $whiteLists['post'];
    $inWhiteList = 0;
    foreach ($whiteLists as $whiteList) {
        $path = $request->getPathInfo();
        if (preg_match($whiteList, $request->getPathInfo())) {
            $inWhiteList = 1;
            break;
        }
    }
    $token = $request->headers->get('Auth-Token', '');
    if (!$inWhiteList && empty($token)) {
        throw createNotFoundException("AuthToken is not exist.");
    }
    $userService = ServiceKernel::instance()->createService('User.UserService');
    $token = $userService->getToken('mobile_login', $token);
    if (!$inWhiteList && empty($token['userId'])) {
        throw createAccessDeniedException("AuthToken is invalid.");
    }
    $user = $userService->getUser($token['userId']);
    // $user = $userService->getUser(1);
    if (!$inWhiteList && empty($user)) {
        throw createNotFoundException("Auth user is not found.");
    }
    setCurrentUser($user);
});
$app->error(function (\Exception $e, $code) {
    return array('code' => $code, 'message' => $e->getMessage());
});
include __DIR__ . '/config/routing.php';
$app->run();
Esempio n. 6
0
 /**
  * Gives new answers to existing Questionnaire Entity
  *
  * @Route("/new/{id}", requirements={"id" = "\d+"}, name="answer_post_new")
  * @Method({"GET", "POST", "DELETE"})
  *
  * NOTE: the Method annotation is optional, but it's a recommended practice
  * to constraint the HTTP methods each controller responds to (by default
  * it responds to all methods).
  */
 public function newAction(Questionnaire $questionnaire, Statement $statement, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     // $repository = $this->getDoctrine()->getRepository('AppBundle:Statement');
     // $statements = $repository->findAll();
     //
     // $statementCollection = new Answer;
     //
     // foreach ($statements as $statement) {
     //
     //   $statementCollection->getStatement()->add($statement);
     // }
     //
     // $collection = $this->createForm(new AnswerType, $statementCollection);
     //
     // return $this->render('Questionnaire/Answer/new.html.twig', array(
     //   'collection' => $collection->createView()
     // ));
     // $repo_statement = $this->getDoctrine()->getRepository('AppBundle:Statement');
     // $repo_questionnaire = $this->getDoctrine()->getRepository('AppBundle:Questionnaire');
     // $questionnaire = $repo_questionnaire->findOneById($id);
     //
     // if (is_null($questionnaire)) {
     //     throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
     // }
     //
     // // $statement = $repo_statement->findOneBy(
     // //     array('questionnaire'=>$questionnaire,'statement'=>$this->getStatement())
     // // );
     foreach ($questionnaire->getstatements() as $key => $statement) {
         $repo_statement = $this->getDoctrine()->getRepository('AppBundle:Statement');
         $statement = $repo_statement->findOneBy(array('questionnaire' => $questionnaire, 'statement' => $this->getStatement()));
         $answer[$key] = new Answer($key);
         $form[$key] = $this->createForm(new AnswerType(), $answer[$key])->createView();
     }
     $request = $this->getRequest();
     if ($request->getMethod() == 'POST') {
         $form->bindRequest($request);
         // the isSubmitted() method is completely optional because the other
         // isValid() method already checks whether the form is submitted.
         // However, we explicitly add it to improve code readability.
         // See http://symfony.com/doc/current/best_practices/forms.html#handling-form-submits
         if ($form->isSubmitted() && $form->isValid()) {
             $questionnaireAns = $form["questionnaireAns"]->getData();
             foreach ($questionnaireAns as $questionnaire) {
                 $id = $questionnaire->getId();
                 $dbQuestionnaire = $em->getRepository('AppBundle:Questionnaire')->find($id);
                 if (!$dbQuestionnaire) {
                     throw $this - createNotFoundException('No $dbQuestionnaire found for id ' . $id);
                 }
                 $dbQuestionnaire->addAnswer($answer);
             }
             $statements = $form["statements"]->getData();
             foreach ($statements as $statement) {
                 $id = $statement->getId();
                 $dbStatement = $em->getRepository('AppBundle:Statement')->find($id);
                 if (!$dbStatement) {
                     throw $this - createNotFoundException('No dbStatement found for id ' . $id);
                 }
                 $dbStatement->addAnswer($answer);
             }
             $em->persist($answer);
             $em->flush();
             return $this->redirectToRoute('answer');
         }
     }
     return $this->render('Questionnaire/Answer/new.html.twig', array('questionnaire' => $questionnaire, 'statement' => $statement, 'answer' => $answer, 'form' => $form->createView()));
 }