Skip to content

Commit

Permalink
MDL-20636 Now the quiz review page works.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Feb 9, 2011
1 parent 167f156 commit b2607cc
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 266 deletions.
6 changes: 3 additions & 3 deletions mod/quiz/accessrules.php
Expand Up @@ -166,8 +166,8 @@ public function prevent_access() {

/**
* Do any of the rules mean that this student will no be allowed any further attempts at this
* quiz. Used, for example, to change the label by the grade displayed on the view page from
* 'your current score is' to 'your final score is'.
* quiz. Used, for example, to change the label by the grade displayed on the view page from
* 'your current grade is' to 'your final grade is'.
*
* @param integer $numattempts the number of previous attempts this user has made.
* @param object $lastattempt information about the user's last completed attempt.
Expand Down Expand Up @@ -484,7 +484,7 @@ public function description() {
/**
* If this rule can determine that this user will never be allowed another attempt at
* this quiz, then return true. This is used so we can know whether to display a
* final score on the view page. This will only be called if there is not a currently
* final grade on the view page. This will only be called if there is not a currently
* active attempt for this user.
* @param integer $numattempts the number of previous attempts this user has made.
* @param object $lastattempt information about the user's last completed attempt.
Expand Down
14 changes: 10 additions & 4 deletions mod/quiz/attemptlib.php
Expand Up @@ -33,9 +33,6 @@
}


// TODO get_question_score -> mark


/**
* Class for quiz exceptions. Just saves a couple of arguments on the
* constructor for a moodle_exception.
Expand Down Expand Up @@ -557,6 +554,15 @@ public function is_own_attempt() {
(!$this->is_preview_user() || $this->attempt->preview);
}

/**
* Get the overall feedback corresponding to a particular mark.
* @param $grade a particular grade.
*/
public function get_overall_feedback($grade) {
return quiz_feedback_for_grade($grade, $this->get_quiz(),
$this->quizobj->get_context(), $this->get_cm());
}

/**
* Wrapper round the has_capability funciton that automatically passes in the quiz context.
*/
Expand Down Expand Up @@ -713,7 +719,7 @@ public function get_question_status($slot, $showcorrectness) {
* @param integer $slot the number used to identify this question within this attempt.
* @return string the formatted grade, to the number of decimal places specified by the quiz.
*/
public function get_question_score($slot) {
public function get_question_mark($slot) {
return quiz_format_question_grade($this->get_quiz(), $this->quba->get_question_mark($slot));
}

Expand Down
4 changes: 2 additions & 2 deletions mod/quiz/db/install.xml
Expand Up @@ -17,7 +17,7 @@
<FIELD NAME="attemptonlast" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="preferredbehaviour" NEXT="attempts"/>
<FIELD NAME="attempts" TYPE="int" LENGTH="6" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="The maximum number of attempts that a student is allowed at this quiz. 0 mean no limit." PREVIOUS="attemptonlast" NEXT="grademethod"/>
<FIELD NAME="grademethod" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" COMMENT="How individual attempt grades are combined to get the overall grade. From the top of mod/quiz/lib.php: 1 = QUIZ_GRADEHIGHEST, 2 = QUIZ_GRADEAVERAGE, 3 = QUIZ_ATTEMPTFIRST, 4 = QUIZ_ATTEMPTLAST." PREVIOUS="attempts" NEXT="decimalpoints"/>
<FIELD NAME="decimalpoints" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="2" SEQUENCE="false" COMMENT="Number of decimal points to display when printing scores belonging to this quiz." PREVIOUS="grademethod" NEXT="questiondecimalpoints"/>
<FIELD NAME="decimalpoints" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="2" SEQUENCE="false" COMMENT="Number of decimal points to display when printing grades belonging to this quiz." PREVIOUS="grademethod" NEXT="questiondecimalpoints"/>
<FIELD NAME="questiondecimalpoints" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="-2" SEQUENCE="false" COMMENT="The number of decimal digits to use when displaying question grades. -1 = use decimalpoints, otherwise a separate setting." PREVIOUS="decimalpoints" NEXT="reviewattempt"/>
<FIELD NAME="reviewattempt" TYPE="int" LENGTH="6" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether users are allowed to review their quiz attempts at various times. This is a bit field, decoded by the mod_quiz_display_options class. It is formed by ORing together the constants defined there." PREVIOUS="questiondecimalpoints" NEXT="reviewcorrectness"/>
<FIELD NAME="reviewcorrectness" TYPE="int" LENGTH="6" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether users are allowed to review their quiz attempts at various times. A bit field, like reviewattempt." PREVIOUS="reviewattempt" NEXT="reviewmarks"/>
Expand Down Expand Up @@ -102,7 +102,7 @@
<KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="quiz"/>
</KEYS>
</TABLE>
<TABLE NAME="quiz_feedback" COMMENT="Feedback given to students based on which grade band their overall score lies." PREVIOUS="quiz_question_instances" NEXT="quiz_reports">
<TABLE NAME="quiz_feedback" COMMENT="Feedback given to students based on which grade band their overall grade lies." PREVIOUS="quiz_question_instances" NEXT="quiz_reports">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="quizid"/>
<FIELD NAME="quizid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key references quiz.id." PREVIOUS="id" NEXT="feedbacktext"/>
Expand Down
14 changes: 7 additions & 7 deletions mod/quiz/index.php
Expand Up @@ -86,9 +86,9 @@
array_push($headings, get_string('feedback', 'quiz'));
array_push($align, 'left');
}
$showing = 'scores'; // default
$showing = 'grades'; // default

$scores = $DB->get_records_sql_menu('
$grades = $DB->get_records_sql_menu('
SELECT qg.quiz, qg.grade
FROM {quiz_grades} qg
JOIN {quiz} q ON q.id = qg.quiz
Expand Down Expand Up @@ -140,22 +140,22 @@
// fields set to make the following call work.
$data[] = quiz_attempt_summary_link_to_reports($quiz, $cm, $context);

} else if ($showing == 'scores') {
} else if ($showing == 'grades') {
// Grade and feedback.
$attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'all');
list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);

$grade = '';
$feedback = '';
if ($quiz->grade && array_key_exists($quiz->id, $scores)) {
if ($alloptions->scores) {
if ($quiz->grade && array_key_exists($quiz->id, grades)) {
if ($alloptions->marks) {
$a = new stdClass;
$a->grade = quiz_format_grade($quiz, $scores[$quiz->id]);
$a->grade = quiz_format_grade($quiz, grades[$quiz->id]);
$a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
$grade = get_string('outofshort', 'quiz', $a);
}
if ($alloptions->overallfeedback) {
$feedback = quiz_feedback_for_grade($scores[$quiz->id], $quiz, $context, $cm);
$feedback = quiz_feedback_for_grade(grades[$quiz->id], $quiz, $context, $cm);
}
}
$data[] = $grade;
Expand Down
6 changes: 3 additions & 3 deletions mod/quiz/lang/en/quiz.php
Expand Up @@ -218,7 +218,7 @@
$string['decimaldigits'] = 'Decimal digits in grades';
$string['decimalformat'] = 'decimals';
$string['decimalplaces'] = 'Decimal places in grades';
$string['decimalplaces_help'] = 'This setting specifies the number of digits shown after the decimal point when displaying scores or grades. It only effects the display of grades, not the grades stored in the database, nor the internal calculations, which are carried out to full accuracy.';
$string['decimalplaces_help'] = 'This setting specifies the number of digits shown after the decimal point when displaying grades or grades. It only effects the display of grades, not the grades stored in the database, nor the internal calculations, which are carried out to full accuracy.';
$string['decimalplacesquestion'] = 'Decimal places in question grades';
$string['decimalplacesquestion_help'] = 'This setting specifies the number of digits shown after the decimal point when displaying the grades for individual questions.';
$string['decimalpoints'] = 'Decimal points';
Expand Down Expand Up @@ -314,8 +314,8 @@
$string['file'] = 'File';
$string['fileformat'] = 'File format';
$string['fillcorrect'] = 'Fill with correct';
$string['filloutnumericalanswer'] = 'You provide at least one possible answer and tolerance. The first matching answer will be used to determine the score and feedback. If you supply some feedback with no answer at the end, that will be shown to students whose response is not matched by any of the other answers.';
$string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. \'*\' can be used as a wildcard to match any characters. The first matching answer will be used to determine the score and feedback.';
$string['filloutnumericalanswer'] = 'You provide at least one possible answer and tolerance. The first matching answer will be used to determine the grade and feedback. If you supply some feedback with no answer at the end, that will be shown to students whose response is not matched by any of the other answers.';
$string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. \'*\' can be used as a wildcard to match any characters. The first matching answer will be used to determine the grade and feedback.';
$string['filloutthreequestions'] = 'You must provide at least three questions with matching answers. You can provide extra wrong answers by giving an answer with a blank question. Entries where both the question and the answer are blank will be ignored.';
$string['fillouttwochoices'] = 'You must fill out at least two choices. Choices left blank will not be used.';
$string['finishattemptdots'] = 'Finish attempt...';
Expand Down
10 changes: 5 additions & 5 deletions mod/quiz/lib.php
Expand Up @@ -326,7 +326,7 @@ function quiz_get_best_grade($quiz, $userid) {
global $DB;
$grade = $DB->get_field('quiz_grades', 'grade', array('quiz' => $quiz->id, 'userid' => $userid));

// Need to detect errors/no result, without catching 0 scores.
// Need to detect errors/no result, without catching 0 grades.
if ($grade === false) {
return null;
}
Expand Down Expand Up @@ -599,10 +599,10 @@ function quiz_grade_item_update($quiz, $grades = NULL) {
}

/* description by TJ:
1/ If the quiz is set to not show scores while the quiz is still open, and is set to show scores after
1/ If the quiz is set to not show grades while the quiz is still open, and is set to show grades after
the quiz is closed, then create the grade_item with a show-after date that is the quiz close date.
2/ If the quiz is set to not show scores at either of those times, create the grade_item as hidden.
3/ If the quiz is set to show scores, create the grade_item visible.
2/ If the quiz is set to not show grades at either of those times, create the grade_item as hidden.
3/ If the quiz is set to show grades, create the grade_item visible.
*/
$openreviewoptions = mod_quiz_display_options::make_from_quiz($quiz,
mod_quiz_display_options::LATER_WHILE_OPEN);
Expand Down Expand Up @@ -812,7 +812,7 @@ function quiz_get_recent_mod_activity(&$activities, &$index, $timestart,

$tmpactivity->content->attemptid = $attempt->id;
$tmpactivity->content->attempt = $attempt->attempt;
if (quiz_has_grades($quiz) && $options->scores) {
if (quiz_has_grades($quiz) && $options->marks) {
$tmpactivity->content->sumgrades = quiz_format_grade($quiz, $attempt->sumgrades);
$tmpactivity->content->maxgrade = quiz_format_grade($quiz, $quiz->sumgrades);
} else {
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/locallib.php
Expand Up @@ -508,7 +508,7 @@ function quiz_update_all_attempt_sumgrades($quiz) {
}

/**
* The quiz grade is the score that student's results are marked out of. When it
* The quiz grade is the maximum that student's results are marked out of. When it
* changes, the corresponding data in quiz_grades and quiz_feedback needs to be
* rescaled. After calling this function, you probably need to call
* quiz_update_all_attempt_sumgrades, quiz_update_all_final_grades and
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/report/overview/report.php
Expand Up @@ -21,7 +21,7 @@ function display($quiz, $cm, $course) {

$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);

// Work out some display options - whether there is feedback, and whether scores should be shown.
// Work out some display options - whether there is feedback, and whether grades should be shown.
$hasfeedback = quiz_has_feedback($quiz);
$fakeattempt = new stdClass();
$fakeattempt->preview = false;
Expand Down

0 comments on commit b2607cc

Please sign in to comment.