/**
  * Gets a activequiz_question object with the slot set
  *
  * @param int                                $slotnum The index of the slot we want, i.e. the question number
  * @param \mod_activequiz\activequiz_attempt $attempt The current attempt
  *
  * @return \mod_activequiz\activequiz_question
  */
 public function get_question_with_slot($slotnum, $attempt)
 {
     $slots = $attempt->getSlots();
     $quba = $attempt->get_quba();
     // first check if this is the last question
     if (empty($slots[$slotnum])) {
         $attempt->islastquestion(true);
     } else {
         $attempt->islastquestion(false);
     }
     // since arrays are indexed starting at 0 and we reference questions starting with 1, we subtract 1
     $slotnum = $slotnum - 1;
     // get the first question
     $qubaQuestion = $quba->get_question($slots[$slotnum]);
     foreach ($this->qbankOrderedQuestions as $qbankQuestion) {
         /** @var \mod_activequiz\activequiz_question $qbankQuestion */
         if ($qbankQuestion->getQuestion()->id == $qubaQuestion->id) {
             // set the slot on the qbank question as this is the actual id we're using for question number
             $qbankQuestion->set_slot($slots[$slotnum]);
             return $qbankQuestion;
         }
     }
     // if we get here return null due to no question
     return null;
 }
 /**
  * Render a review question with no editing capabilities.
  *
  * Reviewing will be based upon the after review options specified in module settings
  *
  * @param int                                $slot
  * @param \mod_activequiz\activequiz_attempt $attempt
  *
  * @return string HTML fragment for the question
  */
 public function render_review_question($slot, $attempt)
 {
     $qnum = $attempt->get_question_number();
     $output = '';
     $output .= html_writer::start_div('activequizbox', array('id' => 'q' . $qnum . '_container'));
     $output .= $attempt->render_question($slot, true, $this->rtq->get_review_options('after'));
     $output .= html_writer::end_div();
     return $output;
 }
Example #3
0
 /**
  * Calculate the grade for attempt passed in
  *
  * This function does the scaling down to what was desired in the activequiz settings
  * from what the quiz was actually set up with
  *
  * Is public function so that tableviews can get an attempt calculated grade
  *
  * @param \mod_activequiz\activequiz_attempt $attempt
  * @return number The grade to save
  */
 public function calculate_attempt_grade($attempt)
 {
     $quba = $attempt->get_quba();
     $totalpoints = 0;
     $totalslotpoints = 0;
     foreach ($attempt->getSlots() as $slot) {
         $totalpoints = $totalpoints + $quba->get_question_max_mark($slot);
         $slotpoints = $quba->get_question_mark($slot);
         if (!empty($slotpoints)) {
             $totalslotpoints = $totalslotpoints + $slotpoints;
         }
     }
     // use cross multiplication to scale to the desired points
     $scaledpoints = $totalslotpoints * $this->rtq->getRTQ()->scale / $totalpoints;
     return $scaledpoints;
 }