Example #1
0
 /**
  * Prints questions with comment and grade form underneath each question
  *
  * @return void
  * @todo Finish documenting this function
  **/
 function print_questions_and_form($quiz, $question, $userid, $attemptid, $gradeungraded, $gradenextungraded, $ungraded)
 {
     global $CFG, $DB, $OUTPUT;
     $context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
     $questions[$question->id] =& $question;
     $usehtmleditor = can_use_html_editor();
     list($select, $from, $where, $params) = $this->attempts_sql($quiz->id, false, $question->id, $userid, $attemptid, $gradeungraded, $gradenextungraded);
     $sort = 'ORDER BY u.firstname, u.lastname, qa.attempt ASC';
     if ($gradenextungraded) {
         $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params, 0, QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE);
     } else {
         $attempts = $DB->get_records_sql($select . $from . $where . $sort, $params);
     }
     if ($attempts) {
         $firstattempt = current($attempts);
         $fullname = fullname($firstattempt);
         if ($gradeungraded) {
             // getting all ungraded attempts
             echo $OUTPUT->heading(get_string('gradingungraded', 'quiz_grading', $ungraded), 3);
         } else {
             if ($gradenextungraded) {
                 // getting next ungraded attempts
                 echo $OUTPUT->heading(get_string('gradingnextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE), 3);
             } else {
                 if ($userid) {
                     echo $OUTPUT->heading(get_string('gradinguser', 'quiz_grading', $fullname), 3);
                 } else {
                     if ($attemptid) {
                         $a = new object();
                         $a->fullname = $fullname;
                         $a->attempt = $firstattempt->attempt;
                         echo $OUTPUT->heading(get_string('gradingattempt', 'quiz_grading', $a), 3);
                     } else {
                         echo $OUTPUT->heading(get_string('gradingall', 'quiz_grading', count($attempts)), 3);
                     }
                 }
             }
         }
         // Display the form with one part for each selected attempt
         echo '<form method="post" action="report.php" class="mform" id="manualgradingform">' . '<input type="hidden" name="mode" value="grading" />' . '<input type="hidden" name="q" value="' . $quiz->id . '" />' . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . '<input type="hidden" name="questionid" value="' . $question->id . '" />';
         foreach ($attempts as $attempt) {
             // Load the state for this attempt (The questions array was created earlier)
             $states = get_question_states($questions, $quiz, $attempt);
             // The $states array is indexed by question id but because we are dealing
             // with only one question there is only one entry in this array
             $state =& $states[$question->id];
             $options = quiz_get_reviewoptions($quiz, $attempt, $context);
             unset($options->questioncommentlink);
             $options->readonly = 1;
             if (question_state_is_graded($state)) {
                 $gradedclass = 'main highlightgraded';
                 $gradedstring = ' ' . get_string('graded', 'quiz_grading');
             } else {
                 $gradedclass = 'main';
                 $gradedstring = '';
             }
             $a = new object();
             $a->fullname = fullname($attempt, true);
             $a->attempt = $attempt->attempt;
             // print the user name, attempt count, the question, and some more hidden fields
             echo '<div class="boxaligncenter" width="80%" style="clear:left;padding:15px;">';
             echo $OUTPUT->heading(get_string('gradingattempt', 'quiz_grading', $a) . $gradedstring, 3, $gradedclass);
             // Print the question, without showing any previous comment.
             $copy = $state->manualcomment;
             $state->manualcomment = '';
             $options->noeditlink = true;
             print_question($question, $state, '', $quiz, $options);
             // The print the comment and grade fields, putting back the previous comment.
             $state->manualcomment = $copy;
             question_print_comment_fields($question, $state, 'manualgrades[' . $attempt->uniqueid . ']', $quiz, get_string('manualgrading', 'quiz'));
             echo '</div>';
         }
         echo '<div class="boxaligncenter"><input type="submit" value="' . get_string('savechanges') . '" /></div>' . '</form>';
     } else {
         echo $OUTPUT->notification(get_string('noattemptstoshow', 'quiz'));
     }
 }
 /**
  * Print the fields of the comment form for questions in this attempt.
  * @param $slot which question to output the fields for.
  * @param $prefix Prefix to add to all field names.
  */
 public function question_print_comment_fields($slot, $prefix)
 {
     // Work out a nice title.
     $student = get_record('user', 'id', $this->get_userid());
     $a = new object();
     $a->fullname = fullname($student, true);
     $a->attempt = $this->get_attempt_number();
     question_print_comment_fields($this->quba->get_question_attempt($slot), $prefix, $this->get_display_options(true)->markdp, get_string('gradingattempt', 'quiz_grading', $a));
 }
Example #3
0
 /**
  * Print the fields of the comment form for questions in this attempt.
  * @param $questionid a question id.
  * @param $prefix Prefix to add to all field names.
  */
 public function question_print_comment_fields($questionid, $prefix)
 {
     global $DB;
     $this->ensure_question_loaded($questionid);
     $this->ensure_state_loaded($questionid);
     /// Work out a nice title.
     $student = $DB->get_record('user', array('id' => $this->get_userid()));
     $a = new stdClass();
     $a->fullname = fullname($student, true);
     $a->attempt = $this->get_attempt_number();
     question_print_comment_fields($this->questions[$questionid], $this->states[$questionid], $prefix, $this->quiz, get_string('gradingattempt', 'quiz_grading', $a));
 }