Exemplo n.º 1
0
 public function getPointsByQuiz(Quiz $quiz)
 {
     return $this->getEntityManager()->createQuery('SELECT SUM(answer.points) FROM AppBundle:Answer answer
                 INNER JOIN answer.question question
                 INNER JOIN question.quiz quiz
                 WHERE quiz.id=' . $quiz->getId())->getResult()[0][1];
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $quiz = new Quiz();
     $quiz->setImage('111');
     $manager->persist($quiz);
     $manager->flush();
 }
Exemplo n.º 3
0
 public function testSetName()
 {
     $quiz = new Quiz();
     $quizName = "some name";
     $returnedFromSetName = $quiz->setName($quizName);
     $this->assertEquals(TestUtility::getProperty($quiz, 'name'), $quizName);
     $this->assertEquals($returnedFromSetName, $quiz);
 }
Exemplo n.º 4
0
 /**
  * @Route("/teacher/quiz/new/", name="new_quiz")
  */
 public function newQuizAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $quiz = new Quiz();
     $quiz->setTeacher($this->getUser());
     $form = $this->createFormBuilder($quiz)->add('name', TextType::class)->add('save', SubmitType::class, array('label' => "Utwórz"))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $quiz->setEnabled(1);
         $em->persist($quiz);
         $em->flush();
         return $this->redirectToRoute('editQuiz', array('id' => $quiz->getId()));
     }
     return $this->render('teacher/new_quiz.html.twig', array('add_quiz' => $form->createView()));
 }
Exemplo n.º 5
0
 /**
  * Displays a form to create a new Quiz entity.
  *
  * @Route("/dodaj", name="quiz_new")
  * @Template()
  */
 public function newAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $qb = $em->getRepository('AppBundle:Quiz')->createQueryBuilder('q');
     $qb->select('COUNT(q)');
     $count = $qb->getQuery()->getSingleScalarResult();
     $entity = new Quiz();
     $entity->setTitle('Quiz - ' . $count);
     $form = $this->createCreateForm($entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         $em->flush();
         return $this->redirectToRoute('quiz_show', array('link' => $entity->getLink()));
     }
     return array('entity' => $entity, 'form' => $form->createView());
 }
Exemplo n.º 6
0
 /**
  * @Route("/quiz/{id}/correction", name="quiz_correct")
  */
 public function correctAction(\AppBundle\Entity\Quiz $quiz)
 {
     if ($this->getUser() !== $quiz->getUser()) {
         return $this->createNotFoundException('Quiz not found');
     }
     $questions = [];
     /** @var \AppBundle\Entity\Answer $answer */
     foreach ($quiz->getAnswers() as $answer) {
         $question = $answer->getQuestion();
         if (array_key_exists($question->getId(), $questions)) {
             $questions[$question->getId()]['givenAnswers'][] = $answer;
         } else {
             $questions[$question->getId()] = ['rightAnswers' => array_filter($question->getAnswers()->toArray(), function ($answer) {
                 return $answer->isTrue();
             }), 'givenAnswers' => [$answer], 'statement' => $question->getStatement()];
         }
     }
     foreach ($questions as $id => $question) {
         $question['rightButNotGivenAnswers'] = array_diff($question['rightAnswers'], $question['givenAnswers']);
         $questions[$id] = $question;
     }
     return $this->render(':quiz:correct.html.twig', ['questions' => $questions, 'quiz' => $quiz]);
 }
Exemplo n.º 7
0
 /**
  * @param Quiz $quiz
  * @return Variant|null
  */
 public function findRandomVariant(Quiz $quiz)
 {
     $variants = $quiz->getVariants();
     return $variants->get(rand(0, $variants->count()));
 }