Example #1
0
 public function executeAdd()
 {
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         // create question
         $user = $this->getUser()->getSubscriber();
         $question = new Question();
         $question->setTitle($this->getRequestParameter('title'));
         $question->setBody($this->getRequestParameter('body'));
         $question->setUser($user);
         $question->save();
         $user->isInterestedIn($question);
         $question->addTagsForUser($this->getRequestParameter('tag'), $user->getId());
         return $this->redirect('@question?stripped_title=' . $question->getStrippedTitle());
     }
 }
 /**
  * @expectedException mdagostino\MultipleChoiceExams\ExpiredTimeException
  * @expectedExceptionMessage There is no left time to complete the exam.
  */
 public function testTimeLeftZero()
 {
     // This test checks if the questions are not available to be answered
     // when the time to complete the exam is exactly the duration of the exam.
     $exam = new Exam();
     $exam->setDuration(30);
     $examTimer = \Mockery::mock('ExamTimer');
     // The time is in seconds, 30 minutes are 1800 seconds.
     $examTimer->shouldReceive('getTime')->andReturn(0, 1000, 1800);
     $exam->setTimer($examTimer);
     for ($i = 0; $i < 10; $i++) {
         $available_answers = array('one', 'two', 'three');
         $right_answers = array('one', 'three');
         $question = new Question();
         $question->setTitle('Question ' . $i)->setDescription('Description for question ' . $i)->setAvailableAnswers($available_answers)->setRightAnswers($right_answers);
         $questions[] = $question;
     }
     $exam->setQuestions($questions);
     $exam->start();
     $exam->answerQuestion(0, array('one'));
     $exam->answerQuestion(1, array('one', 'two'));
     $exam->answerQuestion(2, array('one', 'three'));
     $exam->finalize();
     $this->assertFalse($exam->isApproved());
 }
Example #3
0
 /**
  * duplicate question from DB
  *
  * @author Sebastien Piraux <*****@*****.**>
  * @return object duplicated question
  */
 public function duplicate()
 {
     // question
     $duplicated = new Question();
     $duplicated->setTitle($this->title);
     $duplicated->setDescription($this->description);
     $duplicated->setType($this->type);
     $duplicated->setGrade($this->grade);
     $duplicated->setCategoryId($this->categoryId);
     $duplicatedId = $duplicated->save();
     // attachment need to be copied in the correct repository but for that we need the id
     if (!empty($this->attachment) && file_exists($this->questionDirSys . $this->attachment)) {
         $duplicated->copyAttachment($this->questionDirSys . $this->attachment);
     }
     // else $duplicated->attachment keeps its default value
     // and its answers
     $duplicated->answer = $this->answer->duplicate($duplicatedId);
     return $duplicated;
 }