From b9376ebef0b95f174d682f71ab8740ea31e420a7 Mon Sep 17 00:00:00 2001 From: michaelpenne Date: Mon, 13 Feb 2006 20:27:34 +0000 Subject: [PATCH] The following changes were made to help reduce confusion for students when essay questions are being used in a quiz. - When a essay question has been submitted or being reviewed and has not been graded by the instructor, then the Marks are not shown and displays a message to the student instead of saying Incorrect. (changes to questiontypes/questiontype.php in functions print_question and print_question_grading_details). - For students, in view.php, a notice is printed to inform him/her that s/he has ungraded essay question(s). - For teachers, in view.php, a notice is printed to inform him/her that s/he has X number of ungraded essays for X number of studnets - In review.php, next to the grade output, informs the viewer if X number of ungraded essays in this attempt. - In questiontypes/essay/questiontype.php created a utility function to generate the numbers used in the above changes. - In lang/en/quiz.php added new lang entries. So, hopefully the student will now understand that their grade does not include the ungraded essay questions. Modification of lang entries might be needed to further drive this point. --- mod/quiz/lang/en/quiz.php | 6 +- mod/quiz/questiontypes/essay/questiontype.php | 66 +++++++++++++++++++ mod/quiz/questiontypes/questiontype.php | 18 ++++- mod/quiz/review.php | 11 +++- mod/quiz/view.php | 19 ++++++ 5 files changed, 116 insertions(+), 4 deletions(-) diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index 44bfbe7431e..95a4b0cf4d8 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -4,13 +4,17 @@ $string['changessaved'] = 'Grading Changes Saved'; $string['comments'] = 'Comments'; $string['editingessay'] = 'Editing Essay'; $string['essay'] = 'Essay'; +$string['essayonly'] = 'Manual grading is so far only implemented for essay questions'; $string['essayquestions'] = 'Essay Questions'; $string['gradeall'] = 'Grade All'; $string['gradeessays'] = 'Grade Essays'; $string['manualgrading'] = 'Manual grading'; $string['nocommentsyet'] = 'No comments yet.'; $string['noessayquestionsfound'] = 'No Essay Questions Found'; -$string['essayonly'] = 'Manual grading is so far only implemented for essay questions'; $string['numungraded'] = '($a ungraded)'; $string['ungraded'] = 'Ungraded'; +$string['ungradednotice'] = 'Note: $a ungraded essay(s) in this attempt.'; +$string['viewessaystograde'] = 'View $a->ungradedessays ungraded essay(s) ($a->usercount $a->students)'; +$string['willbegradedby'] = 'This question will be graded by your $a.'; +$string['youhaveungradedessays'] = 'You have $a essay(s) waiting to be graded.'; ?> diff --git a/mod/quiz/questiontypes/essay/questiontype.php b/mod/quiz/questiontypes/essay/questiontype.php index 5897e21806f..63173c62ac1 100644 --- a/mod/quiz/questiontypes/essay/questiontype.php +++ b/mod/quiz/questiontypes/essay/questiontype.php @@ -237,6 +237,72 @@ class quiz_essay_qtype extends quiz_default_questiontype { return true; } + + /** + * Utility function to count the number of ungraded essays + * and the number of students those essays belong to. + * + * @param object $cmoptions Course module options + * @param mixed $users string/array Specify a specific user or a set of users as an array with ids as keys or as a comma separated list. Defaults to current user. + * @param string $attemptid Specify a specific attempt + * @return array First item in array is the number of ungraded essays and the second is the number of students + * @todo make this function quiz independent + */ + function get_ungraded_count($cmoptions, $users=0, $attemptid=0) { + global $USER, $CFG; + + // prep the userids variable + if (empty($users)) { + $userids = $USER->id; + }else if (is_array($users)) { + $userids = implode(', ', array_keys($users)); + } else { + $userids = $users; + } + + $ungradedcount = 0; // holds the number of ungraded essays + $usercount = array(); // holds the number of users of ungraded essays + + // get the essay questions + $questionlist = quiz_questions_in_quiz($cmoptions->questions); + $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance". + " FROM {$CFG->prefix}quiz_questions q,". + " {$CFG->prefix}quiz_question_instances i". + " WHERE i.quiz = '$cmoptions->id' AND q.id = i.question". + " AND q.id IN ($questionlist)". + " AND q.qtype = '".ESSAY."'". + " ORDER BY q.name"; + + if (empty($attemptid)) { + $attemptsql = "quiz = $cmoptions->id and timefinish > 0 and userid IN ($userids)"; + } else { + $attemptsql = "id = $attemptid"; + } + if ($questions = get_records_sql($sql)) { + // get all the finished attempts by the users + if ($attempts = get_records_select('quiz_attempts', $attemptsql, 'userid, attempt')) { + foreach($questions as $question) { + // determine the number of ungraded attempts essays + foreach ($attempts as $attempt) { + // grab the state then check if it is graded + if (!$neweststate = get_record('quiz_newest_states', 'attemptid', $attempt->uniqueid, 'questionid', $question->id)) { + error("Can not find newest states for attempt $attempt->uniqueid for question $question->id"); + } + if (!$questionstate = get_record('quiz_essay_states', 'stateid', $neweststate->newest)) { + error('Could not find question state'); + } + if (!$questionstate->graded) { + $ungradedcount++; + } + // keep track of users + $usercount[$attempt->userid] = 1; + } + } + } + } + + return array($ungradedcount, count($usercount)); + } } //// END OF CLASS //// diff --git a/mod/quiz/questiontypes/questiontype.php b/mod/quiz/questiontypes/questiontype.php index d474b08d3ee..0cec82d0bd9 100644 --- a/mod/quiz/questiontypes/questiontype.php +++ b/mod/quiz/questiontypes/questiontype.php @@ -464,7 +464,8 @@ class quiz_default_questiontype { 'editquestion', get_string('edit'), 450, 550, get_string('edit')); echo ''; } - if ($question->maxgrade and $options->scores) { + if ($question->maxgrade and $options->scores and + !($question->qtype == ESSAY and !$state->last_graded->options->graded)) { // do not print for ungraded essays echo '
'; echo get_string('marks', 'quiz').': '; if ($cmoptions->optionflags & QUIZ_ADAPTIVE) { @@ -566,7 +567,20 @@ class quiz_default_questiontype { responses (and penalties) */ if (!empty($question->maxgrade) && $options->scores) { - if (!('' === $state->last_graded->grade)) { + if (!('' === $state->last_graded->grade) and + ($question->qtype == ESSAY and !$state->last_graded->options->graded)) { + // Special handling for ungraded essay questions + + // get the word for teacher + if (isset($cmoptions->course) and $course = get_record('course', 'id', $cmoptions->course)) { + $teacher = $course->teacher; + } else { + $teacher = get_string('defaultcourseteacher'); + } + echo '
'; + print_string('willbegradedby', 'quiz', $teacher); + echo '
'; + } else if (!('' === $state->last_graded->grade)) { // Display the grading details from the last graded state $grade->cur = round($state->last_graded->grade, $cmoptions->decimalpoints); $grade->max = $question->maxgrade; diff --git a/mod/quiz/review.php b/mod/quiz/review.php index f7046a7c683..c2bcb3b245c 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -180,10 +180,19 @@ $result->sumgrades = "0"; $result->grade = "0.0"; } + + // if the student has ungraded essay(s), notify him/her of it + list($ungradedessays, $usercount) = $QUIZ_QTYPES[ESSAY]->get_ungraded_count($quiz, $attempt->userid, $attempt->id); + if ($ungradedessays) { + $ungradednotice = '
'.get_string('ungradednotice', 'quiz', $ungradedessays).''; + } else { + $ungradednotice = ''; + } + $percentage = round(($attempt->sumgrades/$quiz->sumgrades)*100, 0); $grade = round(($attempt->sumgrades/$quiz->sumgrades)*$quiz->grade, $CFG->quiz_decimalpoints); $table->data[] = array("$strscore:", "$attempt->sumgrades/$quiz->sumgrades ($percentage %)"); - $table->data[] = array("$strgrade:", $grade.get_string('outof', 'quiz').$quiz->grade); + $table->data[] = array("$strgrade:", $grade.get_string('outof', 'quiz').$quiz->grade.$ungradednotice); } if ($isteacher and $attempt->userid == $USER->id) { // the teacher is at the end of a preview. Print button to start new preview diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 6ef29b5bfed..0cf3b7ce9cb 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -124,6 +124,19 @@ notify("id\">$strviewallanswers ($usercount $strusers)"); } + + if ($users = get_course_students($course->id)) { + list($ungradedessays, $usercount) = $QUIZ_QTYPES[ESSAY]->get_ungraded_count($quiz, $users); + if ($ungradedessays) { + $a = new stdClass; + $a->ungradedessays = $ungradedessays; + $a->usercount = $usercount; + $a->students = $strusers; + + notify("id\">".get_string('viewessaystograde', 'quiz', $a).''); + } + } + echo ''; print_footer($course); exit; @@ -169,6 +182,12 @@ /// Now print table with existing attempts if ($numattempts) { + /// notify the student of ungraded essays + list($ungradedessays, $usercount) = $QUIZ_QTYPES[ESSAY]->get_ungraded_count($quiz); + if ($ungradedessays) { + notify(get_string('youhaveungradedessays', 'quiz', $ungradedessays)); + } + /// prepare table header if ($quiz->grade and $quiz->sumgrades) { // Grades used so have more columns in table if ($quiz->grade <> $quiz->sumgrades) {