Esempio n. 1
0
/**
 * Get details of all the questions that make up a random question block.
 * @param int $questionID				- ID of the random question to look up.
 * @param object $configObject	- Configuration object.
 * @return array								- Array of the questions that make up a random question block.
 */
function randomDetails($questionID, $configObject, $db)
{
    $question_no = 0;
    $random_questions = array();
    $old_q_id = '';
    $old_score_method = '';
    $old_q_media_width = '';
    $old_q_media_height = '';
    $old_correct = array();
    $old_option_text = array();
    $result = $db->prepare("SELECT theme, options1.option_text, leadin, scenario, q_media_width, q_media_height, options2.correct, options2.marks_correct, options2.option_text, q_type, display_method, score_method, DATE_FORMAT(last_edited,' {$configObject->get('cfg_short_date')}'), status, settings FROM options AS options1, questions LEFT JOIN options AS options2 ON questions.q_id = options2.o_id WHERE options1.option_text=questions.q_id AND options1.o_id=? ");
    $result->bind_param('i', $questionID);
    $result->execute();
    $result->store_result();
    if ($result->num_rows > 0) {
        $result->bind_result($theme, $q_id, $leadin, $scenario, $q_media_width, $q_media_height, $correct, $marks, $option_text, $q_type, $display_method, $score_method, $display_last_edited, $status, $settings);
        while ($result->fetch()) {
            if ($old_q_id != $q_id and $old_q_id != '') {
                $old_leadin = QuestionUtils::clean_leadin($old_leadin);
                $random_questions[$question_no]['theme'] = $old_theme;
                $random_questions[$question_no]['q_id'] = $old_q_id;
                $random_questions[$question_no]['type'] = $old_q_type;
                $random_questions[$question_no]['leadin'] = $old_leadin;
                $random_questions[$question_no]['scenario'] = $old_scenario;
                $random_questions[$question_no]['scenario'] = $old_scenario;
                $random_questions[$question_no]['correct'] = $old_correct;
                $random_questions[$question_no]['status'] = $old_status;
                $random_questions[$question_no]['settings'] = $old_settings;
                $random_questions[$question_no]['display_last_edited'] = $display_last_edited;
                $random_questions[$question_no]['marks'] = qMarks($old_q_type, '', $old_marks, $old_option_text, $old_correct, $old_display_method, $old_score_method);
                $random_questions[$question_no]['random_mark'] = qRandomMarks($old_q_type, '', $old_marks, $old_option_text, $old_correct, $old_display_method, $old_score_method, $old_q_media_width, $old_q_media_height);
                $old_correct = array();
                $old_option_text = array();
                $question_no++;
            }
            $old_theme = $theme;
            $old_q_id = $q_id;
            $old_q_type = $q_type;
            $old_leadin = $leadin;
            $old_scenario = $scenario;
            $old_status = $status;
            $old_settings = $settings;
            $old_marks = $marks;
            $old_correct[] = $correct;
            $old_option_text[] = $option_text;
            $old_display_method = $display_method;
            $old_score_method = $score_method;
            $old_q_media_width = $q_media_width;
            $old_q_media_height = $q_media_height;
        }
        // Write out the last question.
        $old_leadin = QuestionUtils::clean_leadin($old_leadin);
        $random_questions[$question_no]['theme'] = $old_theme;
        $random_questions[$question_no]['q_id'] = $old_q_id;
        $random_questions[$question_no]['type'] = $old_q_type;
        $random_questions[$question_no]['leadin'] = $old_leadin;
        $random_questions[$question_no]['scenario'] = $old_scenario;
        $random_questions[$question_no]['correct'] = $old_correct;
        $random_questions[$question_no]['status'] = $old_status;
        $random_questions[$question_no]['settings'] = $old_settings;
        $random_questions[$question_no]['display_last_edited'] = $display_last_edited;
        $random_questions[$question_no]['marks'] = qMarks($old_q_type, '', $old_marks, $old_option_text, $old_correct, $old_display_method, $old_score_method);
        $random_questions[$question_no]['random_mark'] = qRandomMarks($old_q_type, '', $old_marks, $old_option_text, $old_correct, $old_display_method, $old_score_method, $old_q_media_width, $old_q_media_height);
    }
    $result->close();
    return $random_questions;
}
Esempio n. 2
0
 /**
  *  Wrapper for the qRandomMarks function in calculate_marks.inc which 
  *  calculates the "Monky Mark/Random Mark" for a question 
  */
 public function qRandomMarks($question_type, $tmp_exclude, $marks_correct, $option_text, $correct, $display_method, $score_method, $old_q_media_width, $old_q_media_height)
 {
     return qRandomMarks($question_type, $tmp_exclude, $marks_correct, $option_text, $correct, $display_method, $score_method, $old_q_media_width, $old_q_media_height);
 }
Esempio n. 3
0
 /**
  * Creates an array called 'paper_buffer' which contains all the questions on the paper.
  * @return bool - If no questions are found will return FALSE.
  */
 public function load_answers()
 {
     $question_no = 0;
     $old_q_id = 0;
     $old_correct = array();
     $old_option_text = array();
     $this->total_marks = 0;
     $this->orig_total_marks = 0;
     $this->total_random_mark = 0;
     $this->display_excluded = '';
     $this->display_experimental = array();
     // Load the correct answers into 'paper_buffer' array.
     $result = $this->db->prepare("SELECT q_id, marks_correct, marks_incorrect, display_method, score_method, q_media_height, q_media_width, q_type, correct, score_method, option_text, status, display_pos, settings FROM (papers, questions) LEFT JOIN options ON questions.q_id = options.o_id WHERE papers.question = questions.q_id AND papers.paper = ? AND q_type != 'info' ORDER BY screen, display_pos, id_num");
     $result->bind_param('i', $this->paperID);
     $result->execute();
     $result->store_result();
     $result->bind_result($q_id, $marks_correct, $marks_incorrect, $display_method, $score_method, $q_media_height, $q_media_width, $q_type, $correct, $score_method, $option_text, $status, $display_pos, $settings);
     while ($result->fetch()) {
         if ($q_id != $old_q_id or $old_display_pos != $display_pos) {
             if ($old_q_id != 0) {
                 $old_status_obj = $this->question_statuses[$old_status];
                 if (!$old_status_obj->get_exclude_marking()) {
                     $tmp_exclude = $this->exclusions->get_exclusions_by_qid($old_q_id);
                     if ($old_q_type == 'random') {
                         $tmp_id = $this->getRandomDetails($old_q_id);
                         $last_random = $this->paper_buffer[$old_q_id]['random_questions'][$tmp_id];
                         $old_q_type = $last_random['q_type'];
                         $old_marks_correct = $this->get_marks_correct($last_random['q_type'], $last_random['marks_correct'], $last_random['settings']);
                         $old_option_text = $last_random['option_text'];
                         $old_correct = $last_random['correct'];
                         $old_display_method = $last_random['display_method'];
                         $old_score_method = $last_random['score_method'];
                         $this->total_marks += qMarks($old_q_type, $tmp_exclude, $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
                         $this->orig_total_marks += qMarks($old_q_type, '', $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
                     } else {
                         $this->total_marks += qMarks($old_q_type, $tmp_exclude, $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
                         $this->orig_total_marks += qMarks($old_q_type, '', $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
                         $this->total_random_mark += qRandomMarks($old_q_type, $tmp_exclude, $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method, $old_q_media_width, $old_q_media_height);
                         $this->checkDisplayExcluded($tmp_exclude, $question_no, $old_q_type);
                     }
                 } else {
                     $this->displayExperimental($question_no, $old_status_obj->get_name());
                 }
                 $old_marks_correct = 0;
             }
             $question_no++;
             $option_no = 0;
             $old_correct = array();
             $old_option_text = array();
             $question_id = $q_id;
             $this->paper_buffer[$question_id]['q_type'] = $q_type;
             $this->paper_buffer[$question_id]['score_method'] = $score_method;
             $this->paper_buffer[$question_id]['display_method'] = $display_method;
             $this->paper_buffer[$question_id]['marks_correct'] = $this->get_marks_correct($q_type, $marks_correct, $settings);
             $this->paper_buffer[$question_id]['marks_incorrect'] = $marks_incorrect;
             $this->paper_buffer[$question_id]['status'] = $status;
             $this->paper_buffer[$question_id]['settings'] = $settings;
             if ($q_type == 'blank') {
                 $this->paper_buffer[$question_id]['correct'] = $this->extract_blank_correct($option_text);
             } else {
                 $this->paper_buffer[$question_id]['correct'][$option_no] = $correct;
             }
         } else {
             $this->paper_buffer[$question_id]['correct'][$option_no] = $correct;
         }
         $option_no++;
         $old_q_id = $q_id;
         $old_display_pos = $display_pos;
         $old_q_type = $q_type;
         $old_display_method = $display_method;
         $old_score_method = $score_method;
         $old_correct[] = $correct;
         $old_q_media_width = $q_media_width;
         $old_q_media_height = $q_media_height;
         $old_option_text[] = $option_text;
         $old_marks_correct = $this->get_marks_correct($q_type, $marks_correct, $settings);
         $old_marks_incorrect = $marks_incorrect;
         $old_status = $status;
         $old_settings = $settings;
     }
     $result->close();
     if ($this->paper_buffer === null) {
         // There are no questions on the paper.
         return false;
     }
     $old_status_obj = $this->question_statuses[$old_status];
     if (!$old_status_obj->get_exclude_marking()) {
         $tmp_exclude = $this->exclusions->get_exclusions_by_qid($old_q_id);
         if ($old_q_type == 'random') {
             $tmp_id = $this->getRandomDetails($old_q_id);
             $last_random = $this->paper_buffer[$old_q_id]['random_questions'][$tmp_id];
             $old_q_type = $last_random['q_type'];
             $old_marks_correct = $this->get_marks_correct($last_random['q_type'], $last_random['marks_correct'], $last_random['settings']);
             $old_option_text = $last_random['option_text'];
             $old_correct = $last_random['correct'];
             $old_display_method = $last_random['display_method'];
             $old_score_method = $last_random['score_method'];
             $this->total_marks += qMarks($old_q_type, $tmp_exclude, $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
             $this->orig_total_marks += qMarks($old_q_type, '', $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
         } else {
             $this->total_marks += qMarks($old_q_type, $tmp_exclude, $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
             $this->orig_total_marks += qMarks($old_q_type, '', $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method);
             $this->total_random_mark += qRandomMarks($old_q_type, $tmp_exclude, $old_marks_correct, $old_option_text, $old_correct, $old_display_method, $old_score_method, $old_q_media_width, $old_q_media_height);
             $this->checkDisplayExcluded($tmp_exclude, $question_no, $old_q_type);
         }
     } else {
         $this->displayExperimental($question_no, $old_status_obj->get_name());
     }
     $this->question_no = $question_no;
 }