Пример #1
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $article1 = new Article();
     $article1->setTitle('Article 1');
     $article1->setContent('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
     $answer1 = new Answer();
     $answer1->setContent('To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it?');
     $answer1->setArticle($article1);
     $answer2 = new Answer();
     $answer2->setContent('At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.');
     $answer2->setArticle($article1);
     $rate1 = new Rate();
     $rate1->setValue(1);
     $rate1->setArticle($article1);
     $rate2 = new Rate();
     $rate2->setValue(5);
     $rate2->setArticle($article1);
     $article2 = new Article();
     $article2->setTitle('Article 2');
     $article2->setContent('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
     $manager->persist($article1);
     $manager->persist($answer1);
     $manager->persist($answer2);
     $manager->persist($rate1);
     $manager->persist($rate2);
     $manager->persist($article2);
     $manager->flush();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('Are you sure you want to import symfony pack questions into the database ?', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     $output->writeln('<info>=== Importing Symfony Pack Questions ===</info>');
     $yaml = new Parser();
     $filesToParse = ['architecture', 'automated-tests', 'bundles', 'cache-http', 'command-line', 'controllers', 'dependency-injection', 'forms', 'http', 'misc', 'php', 'routing', 'security', 'standardization', 'symfony3', 'templating', 'validation'];
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     foreach ($filesToParse as $fileName) {
         $file = $yaml->parse(file_get_contents('app/Resources/symfony-pack-questions/' . $fileName . '.yml'));
         $category = new Category();
         $category->setName($file['category']);
         $em->persist($category);
         foreach ($file['questions'] as $question) {
             $questionEntity = new Question();
             $questionEntity->setCategory($category);
             $questionEntity->setStatement($question['question']);
             $em->persist($questionEntity);
             foreach ($question['answers'] as $answer) {
                 $answerEntity = new Answer();
                 $answerEntity->setStatement($answer['value']);
                 $answerEntity->setVeracity($answer['correct']);
                 $answerEntity->setQuestion($questionEntity);
                 $em->persist($answerEntity);
             }
         }
     }
     $em->flush();
     $output->writeln('<info>=== Import of Symfony Pack Questions Successful ===</info>');
 }
Пример #3
0
 public function load(ObjectManager $manager)
 {
     $answer = new Answer();
     $answer->setText('Test answer');
     $answer->setQuestion($this->getReference('test_question_1'));
     $manager->persist($answer);
     $manager->flush();
 }
Пример #4
0
 public function insertIncorrect(Question $question)
 {
     $em = $this->doctrine->getManager();
     $answer = new Answer();
     $answer->setQuestion($question);
     $answer->setCorrectly(true);
     $answer->setTextAnswer('There is no correct answer');
     $em->persist($answer);
     return;
 }
Пример #5
0
 private function createNew($slug)
 {
     $em = $this->getDoctrine()->getManager();
     $article = $em->getRepository('AppBundle:Article')->findOneBySlug($slug);
     if (!$article) {
         throw $this->createNotFoundException('Unable to find Article.');
     }
     $entity = new Answer();
     $entity->setArticle($article);
     return $entity;
 }
Пример #6
0
 /**
  * @Route("/question/{id}/reponse/ajouter", name="answer_add")
  */
 public function addAction(Request $request, Question $question)
 {
     $answer = new Answer();
     $answer->setQuestion($question);
     $form = $this->createForm(new AnswerType(), $answer);
     $form->handleRequest($request);
     if ($form->isValid() && $form->isSubmitted()) {
         $em = $this->getDoctrine()->getEntityManager();
         $em->persist($answer);
         $em->flush();
         return $this->redirect($this->generateUrl('question_show', ['id' => $question->getId()]));
     }
     return $this->render(':answer:add.html.twig', ['form' => $form->createView(), 'answer' => $answer]);
 }
Пример #7
0
 private function handleRequest(Answer $entity, Request $request)
 {
     $data = $request->getContent();
     if (isset($data['question'])) {
         $entity->setQuestion($this->findQuestion($data['question']));
     }
     if (isset($data['title'])) {
         $entity->setTitle($data['title']);
     }
     if (isset($data['content'])) {
         $entity->setContent($data['content']);
     }
     if (isset($data['created_by'])) {
         $entity->setCreatedBy($data['created_by']);
     }
 }
Пример #8
0
 /**
  * @param Request $request
  * @return JsonResponse
  */
 public function submitAnswerAction(Request $request)
 {
     $answer = $request->get('answer');
     $questionId = $request->get('questionId');
     $type = $request->get('type');
     if (empty($answer)) {
         $answer = 'Keine Antwort';
     }
     if (!empty($questionId)) {
         $repository = $this->getDoctrine()->getRepository('AppBundle:Question');
         $question = $repository->findOneBy(array('id' => $questionId));
         $repository = $this->getDoctrine()->getRepository('AppBundle:User');
         $user = $repository->findOneBy(array('id' => 1));
         $questionAnswer = new Answer();
         $questionAnswer->setAnswer($answer);
         $questionAnswer->setCreatedAt(new \DateTime());
         $questionAnswer->setQuestion($question);
         $questionAnswer->setUser($user);
         $em = $this->getDoctrine()->getManager();
         $em->persist($questionAnswer);
         $em->flush();
         return new JsonResponse(array('success' => 1, 'message' => 'answer saved'));
     }
     return new JsonResponse(array('success' => 0, 'message' => 'some data is missing'));
 }
Пример #9
0
 /**
  * Return the list of the most viewed answers for a given user.
  *
  * @ApiDoc(
  *  description="Return the list of the most viewed answers for a given user.",
  *  section="Answer",
  *  statusCodes = {
  *    200 = "List of answers",
  *    403 = "Forbidden",
  *    404 = "No answers stored",
  *    500 = "Server error"
  *  },
  * )
  * @Route("/show/{slug}", name="aalto_api_answer_show", methods={"GET"})
  * @ParamConverter("answer", class="AppBundle:Answer", options={"slug" = "slug"})
  *
  * @param Request $request
  * @param Answer  $answer
  *
  * @return JsonResponse
  */
 public function showAction(Request $request, Answer $answer)
 {
     $params = ['title' => $answer->getTitle(), 'description' => $answer->getDescription(), 'createdBy' => $answer->getUser()->__toString(), 'createdAt' => $answer->getCreated(), 'files' => [], 'comments' => []];
     $comments = $answer->getComments()->toArray();
     foreach ($comments as $comment) {
         /** @var Comment $comment */
         $params['comments'][] = ['text' => $comment->getContent(), 'createdBy' => $comment->getUser()->__toString(), 'createdAt' => $comment->getCreated(), 'files' => []];
     }
     return new JsonResponse($params, Response::HTTP_OK);
 }
 public function load(ObjectManager $manager)
 {
     $questionary = new Questionary();
     $questionary->setName("Тестовый опросник");
     $questionary->setDescription("Это описание тестового опросника");
     $questionary->setCreated(new \DateTime());
     $manager->persist($questionary);
     $manager->flush();
     //$this->addReference('test-questionary', $questionary);
     $questionaryQuestion1 = new QuestionaryQuestion();
     $questionaryQuestion1->setQuestionaryid($questionary->getId());
     $questionaryQuestion1->setText("Что делать?");
     $questionaryQuestion1->setOrdernumber(1);
     $manager->persist($questionaryQuestion1);
     $questionaryQuestion2 = new QuestionaryQuestion();
     $questionaryQuestion2->setQuestionaryid($questionary->getId());
     $questionaryQuestion2->setText("Кто виноват?");
     $questionaryQuestion2->setOrdernumber(2);
     $manager->persist($questionaryQuestion2);
     $questionaryQuestion3 = new QuestionaryQuestion();
     $questionaryQuestion3->setQuestionaryid($questionary->getId());
     $questionaryQuestion3->setText("Как дела?");
     $questionaryQuestion3->setOrdernumber(3);
     $manager->persist($questionaryQuestion3);
     $manager->flush();
     $answer1 = new Answer();
     $answer1->setText("Да");
     $manager->persist($answer1);
     $manager->flush();
     $answer2 = new Answer();
     $answer2->setText("Нет");
     $manager->persist($answer2);
     $manager->flush();
     $answer3 = new Answer();
     $answer3->setText("Затрудняюсь ответить");
     $manager->persist($answer3);
     $manager->flush();
     $questionaryQuestionOption11 = new QuestionaryQuestionOption();
     $questionaryQuestionOption11->setQuestionid($questionaryQuestion1->getId());
     $questionaryQuestionOption11->setText($answer1->getText());
     $questionaryQuestionOption11->setAnswerid($answer1->getId());
     $questionaryQuestionOption11->setOrdernumber(1);
     $manager->persist($questionaryQuestionOption11);
     $questionaryQuestionOption12 = new QuestionaryQuestionOption();
     $questionaryQuestionOption12->setQuestionid($questionaryQuestion1->getId());
     $questionaryQuestionOption12->setText($answer2->getText());
     $questionaryQuestionOption12->setAnswerid($answer2->getId());
     $questionaryQuestionOption12->setOrdernumber(2);
     $manager->persist($questionaryQuestionOption12);
     $questionaryQuestionOption13 = new QuestionaryQuestionOption();
     $questionaryQuestionOption13->setQuestionid($questionaryQuestion1->getId());
     $questionaryQuestionOption13->setText($answer3->getText());
     $questionaryQuestionOption13->setAnswerid($answer3->getId());
     $questionaryQuestionOption13->setOrdernumber(3);
     $manager->persist($questionaryQuestionOption13);
     $questionaryQuestionOption21 = new QuestionaryQuestionOption();
     $questionaryQuestionOption21->setQuestionid($questionaryQuestion2->getId());
     $questionaryQuestionOption21->setText($answer1->getText());
     $questionaryQuestionOption21->setAnswerid($answer1->getId());
     $questionaryQuestionOption21->setOrdernumber(3);
     $manager->persist($questionaryQuestionOption21);
     $questionaryQuestionOption22 = new QuestionaryQuestionOption();
     $questionaryQuestionOption22->setQuestionid($questionaryQuestion2->getId());
     $questionaryQuestionOption22->setText($answer2->getText());
     $questionaryQuestionOption22->setAnswerid($answer2->getId());
     $questionaryQuestionOption22->setOrdernumber(2);
     $manager->persist($questionaryQuestionOption22);
     $questionaryQuestionOption23 = new QuestionaryQuestionOption();
     $questionaryQuestionOption23->setQuestionid($questionaryQuestion2->getId());
     $questionaryQuestionOption23->setText($answer3->getText());
     $questionaryQuestionOption23->setAnswerid($answer3->getId());
     $questionaryQuestionOption23->setOrdernumber(1);
     $manager->persist($questionaryQuestionOption23);
     $questionaryQuestionOption31 = new QuestionaryQuestionOption();
     $questionaryQuestionOption31->setQuestionid($questionaryQuestion3->getId());
     $questionaryQuestionOption31->setText($answer1->getText());
     $questionaryQuestionOption31->setAnswerid($answer1->getId());
     $questionaryQuestionOption31->setOrdernumber(1);
     $manager->persist($questionaryQuestionOption31);
     $questionaryQuestionOption32 = new QuestionaryQuestionOption();
     $questionaryQuestionOption32->setQuestionid($questionaryQuestion3->getId());
     $questionaryQuestionOption32->setText($answer2->getText());
     $questionaryQuestionOption32->setAnswerid($answer2->getId());
     $questionaryQuestionOption32->setOrdernumber(2);
     $manager->persist($questionaryQuestionOption32);
     $questionaryQuestionOption33 = new QuestionaryQuestionOption();
     $questionaryQuestionOption33->setQuestionid($questionaryQuestion3->getId());
     $questionaryQuestionOption33->setText($answer3->getText());
     $questionaryQuestionOption33->setAnswerid($answer3->getId());
     $questionaryQuestionOption33->setOrdernumber(3);
     $manager->persist($questionaryQuestionOption33);
     $manager->flush();
 }
 /**
  * Create an empty question object and persist it.
  *
  * @param $questionnaire - questionnaire to which to add the question to.
  * @return Question newly created and persisted question.
  */
 private function createEmptyQuestion($questionnaire)
 {
     // Create a new question.
     $question = new Question();
     $question->setType('SINGLE');
     $question->setQuestionnaire($questionnaire);
     // Get the entity manager.
     $em = $this->getDoctrine()->getManager();
     // Create a empty answer and persist it.
     $answer = new Answer();
     $answer->setQuestion($question);
     $em->persist($answer);
     // Assign the empty answer.
     $question->addAnswer($answer);
     // Persist the question.
     $em->persist($question);
     $em->flush();
     return $question;
 }
Пример #12
0
 /**
  * @Security("has_role('ROLE_SUPER_ADMIN')")
  * @Route("/testid{testId}/test/question{id}", name="editQuestion")
  */
 public function editQuestionAction(Request $request, $testId, $id)
 {
     $test = $this->getDoctrine()->getRepository('AppBundle:Test')->find($testId);
     $question = $this->getDoctrine()->getRepository('AppBundle:Question')->find($id);
     $image = new Image();
     $form = $this->createFormBuilder($image)->add('file', 'file', array('label' => 'Новое изображение:', 'required' => false))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $question->setContent($request->get('_description'));
         $ans = $request->get('_answer');
         $questionAns = $question->getAnswers()->toArray();
         $counter = 0;
         foreach ($questionAns as $answer) {
             if (!empty($ans[$counter]['content'])) {
                 $answer->setContent($ans[$counter]['content']);
                 $answer->setRating($ans[$counter]['rating']);
                 $em->persist($answer);
                 $counter++;
             } else {
                 continue;
             }
         }
         if (count($ans) > count($questionAns)) {
             for ($i = $counter; $i < count($ans); $i++) {
                 if (!empty($ans[$i]['content'])) {
                     $answer = new Answer();
                     $answer->setContent($ans[$i]['content']);
                     $answer->setRating($ans[$i]['rating']);
                     $answer->setQuestion($question);
                     $question->addAnswer($answer);
                 } else {
                     continue;
                 }
             }
         }
         if (!$form->get('file')->isEmpty()) {
             $question->removeImages();
             $question->setImage($image);
             $em->persist($test);
             $em->flush();
             $image->upload($test->getId() . '/' . $question->getId());
             $image->setPath($test->getId() . '/' . $question->getId() . '/' . $form->get('file')->getData()->getClientOriginalName());
             $em->persist($image);
             $em->flush();
             $minRating = $this->get('calculate')->calculateMinRating($test);
             $maxRating = $this->get('calculate')->calculateMaxRating($test);
             return $this->redirectToRoute('testpage', array('id' => $testId));
         }
         $em->flush();
         return $this->redirectToRoute('testpage', array('id' => $testId));
     }
     $minRating = $this->get('calculate')->calculateMinRating($test);
     $maxRating = $this->get('calculate')->calculateMaxRating($test);
     return $this->render('tests/test.html.twig', array('test' => $test, 'uploadForm' => $form->createView(), 'maxRating' => $maxRating, 'minRating' => $minRating, 'questionEdit' => $question));
 }
Пример #13
0
 /**
  * @param Answer $answer
  *
  * @return Question
  */
 public function addAnswer(Answer $answer)
 {
     $this->answers[] = $answer;
     $answer->setQuestion($this);
     return $this;
 }
Пример #14
0
 public function __construct(\AppBundle\Entity\Answer $answer)
 {
     $this->statement = $answer->getStatement();
     $this->id = $answer->getId();
 }
Пример #15
0
 /**
  * @Route("/teacher/quiz/question/{question}", name="editQuestion")
  */
 public function editQuestionAction(Request $request, $question)
 {
     $em = $this->getDoctrine()->getManager();
     $question = $em->getRepository('AppBundle:Question')->find($question);
     $answers = $em->getRepository('AppBundle:Answer')->createQueryBuilder('a');
     $answers = $answers->where('a.question=' . $question->getId())->andWhere('a.enabled = 1')->getQuery()->getResult();
     $quiz = $question->getQuiz();
     $questions = $em->getRepository('AppBundle:Question')->findByQuiz($quiz);
     $image = $em->getRepository('AppBundle:QuestionImage')->findOneByQuestion($question);
     if ($image) {
         $image = $image->getWebPath();
     }
     $correct = $em->getRepository('AppBundle:Answer')->createQueryBuilder('c');
     $correct = $correct->where('c.points > 0')->andWhere('c.question=' . $question->getId())->andWhere('c.enabled = 1')->getQuery()->getResult();
     $answer = new Answer();
     $answer->setEnabled(1);
     $answer->setQuestion($question);
     $form = $this->get('form.factory')->createNamedBuilder('answer', FormType::class, $answer)->add('answer')->add('points')->add('save', SubmitType::class, array('label' => "Dodaj odpowiedź"))->getForm();
     $form->handleRequest($request);
     //		if($form->isValid()){
     //			if($answer->getPoints()>=1 && $correct){
     //				$this->addFlash('notice','W tym pytaniu istnieje już poprawna odpowiedź!');
     //				return $this->render('teacher/edit_question.html.twig', array(
     //					'question' => $question,
     //					'questions' => $questions,
     //					'quiz' => $quiz,
     //					'answers'=>$answers,
     //					'add_answer'=>$form->createView(),
     //					'add_question'=>$formq->createView(),
     //					'add_image'=>$formfile->createView(),
     //					'image'=>$image,
     //				));
     //			}
     //			$em->persist($answer);
     //			$em->flush();
     //			$answers = $em->getRepository('AppBundle:Answer')->findByQuestion($question);
     //		}
     $question_new = new Question();
     $formq = $this->get('form.factory')->createNamedBuilder('question', FormType::class, $question_new)->add('question', TextareaType::class)->add('save', SubmitType::class, array('label' => 'Dodaj'))->getForm();
     $formq->handleRequest($request);
     if ($formq->isValid()) {
         $question_new->setEnabled(1);
         $question_new->setQuiz($quiz);
         $em->persist($question_new);
         $em->flush();
         return $this->redirectToRoute('editQuestion', array('question' => $question_new->getId()));
     }
     $file = new QuestionImage();
     $formfile = $this->get('form.factory')->createNamedBuilder('image', FormType::class, $file)->add('file')->getForm();
     $file->setQuestion($question);
     if ($request->request->has('image')) {
         $formfile->handleRequest($request);
     }
     if ($formfile->isValid()) {
         $file->upload();
         $em->persist($file);
         $em->flush();
         $this->addFlash('notice', 'Pomyślnie dodano obrazek do pytania.');
     }
     if ($form->isValid()) {
         if ($answer->getPoints() >= 1 && $correct) {
             $this->addFlash('notice', 'W tym pytaniu istnieje już poprawna odpowiedź!');
             return $this->render('teacher/edit_question.html.twig', array('question' => $question, 'questions' => $questions, 'quiz' => $quiz, 'answers' => $answers, 'add_answer' => $form->createView(), 'add_question' => $formq->createView(), 'add_image' => $formfile->createView(), 'image' => $image));
         }
         $em->persist($answer);
         $em->flush();
         $answers = $em->getRepository('AppBundle:Answer')->createQueryBuilder('a');
         $answers = $answers->where('a.question=' . $question->getId())->andWhere('a.enabled = 1')->getQuery()->getResult();
     }
     return $this->render('teacher/edit_question.html.twig', array('question' => $question, 'questions' => $questions, 'quiz' => $quiz, 'answers' => $answers, 'add_answer' => $form->createView(), 'add_question' => $formq->createView(), 'add_image' => $formfile->createView(), 'image' => $image));
 }
Пример #16
0
 /**
  * Add answers
  *
  * @param \AppBundle\Entity\Answer $answers
  * @return Question
  */
 public function addAnswer(\AppBundle\Entity\Answer $answers)
 {
     $answers->setQuestion($this);
     $this->answers[] = $answers;
     return $this;
 }
 private function importQuestions(\SPSSReader $SPSS, Dataset $dataset)
 {
     $toFlush = array();
     foreach ($SPSS->variables as $var) {
         if ($var->isExtended) {
             continue;
         }
         $index = isset($SPSS->extendedNames[$var->shortName]) ? $SPSS->extendedNames[$var->shortName] : $var->name;
         // -- Split question id --
         $questionSplitted = explode(' ', mb_convert_encoding($var->label, 'UTF-8', 'ISO-8859-7'), 2);
         $questionSplitted[0] = rtrim($questionSplitted[0], '.');
         $tmpSplit = explode('.', $questionSplitted[0], 2);
         if ($tmpSplit[0] == '3') {
             $tmpSplit[0] = '9';
         } else {
             if ($tmpSplit[0] == '4') {
                 $tmpSplit[0] = '8';
             } else {
                 if ($tmpSplit[0] == '5') {
                     $tmpSplit[0] = '10';
                 } else {
                     if ($tmpSplit[0] == '6') {
                         $tmpSplit[0] = '12';
                     } else {
                         if ($tmpSplit[0] == '7') {
                             $tmpSplit[0] = '13';
                         } else {
                             if ($tmpSplit[0] == '8') {
                                 $tmpSplit[0] = '19';
                             } else {
                                 if ($tmpSplit[0] == '9') {
                                     $tmpSplit[0] = '23';
                                 } else {
                                     if ($tmpSplit[0] == '10') {
                                         $tmpSplit[0] = '24';
                                     } else {
                                         if ($tmpSplit[0] == '11') {
                                             $tmpSplit[0] = '25';
                                         } else {
                                             if ($tmpSplit[0] == '12') {
                                                 $tmpSplit[0] = '36';
                                             } else {
                                                 if ($tmpSplit[0] == '13') {
                                                     $tmpSplit[0] = '37';
                                                 } else {
                                                     if ($tmpSplit[0] == '14') {
                                                         $tmpSplit[0] = '38';
                                                     } else {
                                                         if ($tmpSplit[0] == '15') {
                                                             $tmpSplit[0] = '53';
                                                         } else {
                                                             if ($tmpSplit[0] == '16') {
                                                                 $tmpSplit[0] = '56';
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // C
         $questionSplitted[0] = implode('.', $tmpSplit);
         // -----------------------
         $allQuestions = $this->doctrine->getRepository('AppBundle\\Entity\\Question')->findAll();
         foreach ($allQuestions as $curQuestion) {
             $this->allQuestions[$curQuestion->getQuestionId()] = $curQuestion;
         }
         $allAnswers = $this->doctrine->getRepository('AppBundle\\Entity\\Answer')->findAll();
         foreach ($allAnswers as $curAnswer) {
             $this->allAnswers[$curAnswer->getQuestion()->getQuestionId() . '_' . $curAnswer->getAnswerId()] = $curAnswer;
         }
         if (!isset($this->allQuestions[$questionSplitted[0]])) {
             $question = new Question();
             $question->setQuestionId($questionSplitted[0]);
             $question->setQuestion($questionSplitted[1]);
             $question->setDataset($dataset);
             $this->allQuestions[$questionSplitted[0]] = $question;
         } else {
             $question = $this->allQuestions[$questionSplitted[0]];
             $question->getAnswers()->clear();
         }
         if (!$this->isDimension($question->getQuestionId())) {
             $this->doctrine->getManager()->persist($question);
             $toFlush[] = $question;
             $this->questions[$index] = $question;
         } else {
             $this->dimensions[$index] = $question;
         }
         foreach ($var->valueLabels as $lkey => $lval) {
             if (!isset($this->allAnswers[$questionSplitted[0] . '_' . $lkey])) {
                 $answer = new Answer();
                 $answer->setAnswerId($lkey);
                 $this->allAnswers[$questionSplitted[0] . '_' . $lkey] = $answer;
             } else {
                 $answer = $this->allAnswers[$questionSplitted[0] . '_' . $lkey];
             }
             $answer->setAnswer(mb_convert_encoding($lval, 'UTF-8', 'ISO-8859-7'));
             $answer->setQuestion($question);
             $question->getAnswers()->add($answer);
             if (!$this->isDimension($question->getQuestionId())) {
                 $this->doctrine->getManager()->persist($answer);
                 $toFlush[] = $answer;
             }
         }
     }
     if (count($toFlush) > 0) {
         $this->doctrine->getManager()->flush($toFlush);
     }
 }
Пример #18
0
 /**
  * Add an answer from the submitted data by article ID.
  *
  * @ApiDoc(
  *   resource = true,
  *   description = "Add an answer from the submitted data by article ID.",
  *   statusCodes = {
  *     200 = "Returned when successful",
  *     400 = "Returned when the form has errors"
  *   }
  * )
  *
  * @param ParamFetcher $paramFetcher Paramfetcher
  *
  * @RequestParam(name="id", nullable=false, strict=true, description="Article id.")
  * @RequestParam(name="content", nullable=false, strict=true, description="Answer Content.")
  *
  * @return View
  */
 public function postAnswerAction(ParamFetcher $paramFetcher)
 {
     $em = $this->getDoctrine()->getManager();
     $article = $em->getRepository('AppBundle:Article')->find($paramFetcher->get('id'));
     if (!$article) {
         throw $this->createNotFoundException('Data not found.');
     }
     $answer = new Answer();
     $answer->setArticle($article);
     $answer->setContent($paramFetcher->get('content'));
     $em->persist($answer);
     $em->flush();
     $view = View::create();
     $view->setData($answer)->setStatusCode(200);
     return $view;
 }
Пример #19
0
 /**
  * Creates a form to delete Answer entity by id.
  * @param  Answer $answer The answer object
  * @return \Symfony\Component\Form the form
  */
 private function createDeleteForm(Answer $answer)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('answer_post_delete', array('id' => $answer->getId())))->setMethod('DELETE')->getForm();
 }