Skip to content

Commit

Permalink
MDL-12547 "allow manual quiz grading to sort by groups" added code to…
Browse files Browse the repository at this point in the history
… select which group to grade.
  • Loading branch information
jamiesensei committed May 23, 2008
1 parent 1256ee3 commit 3014691
Showing 1 changed file with 51 additions and 30 deletions.
81 changes: 51 additions & 30 deletions mod/quiz/report/grading/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Flow of the file:
// Get variables, run essential queries
// Check for post data submitted. If exists, then process data (the data is the grades and comments for essay questions)
// Check for userid, attemptid, or gradeall and for questionid. If found, print out the appropriate essay question attempts
// Check for userid, attemptid and for questionid. If found, print out the appropriate essay question attempts
// Switch:
// first case: print out all essay questions in quiz and the number of ungraded attempts
// second case: print out all users and their attempts for a specific essay question
Expand All @@ -28,15 +28,38 @@ class quiz_report extends quiz_default_report {
* Displays the report.
*/
function display($quiz, $cm, $course) {

global $CFG;

$viewoptions = array('mode'=>'grading', 'q'=>$quiz->id);
$action = optional_param('action', 'viewquestions', PARAM_ALPHA);
if ($action !== 'viewquestions'){
$viewoptions += array('action'=> $action);
}
$questionid = optional_param('questionid', 0, PARAM_INT);
if ($questionid){
$viewoptions += array('questionid'=>$questionid);
}

// grade question specific parameters

if ($userid = optional_param('userid', 0, PARAM_INT)){
$viewoptions += array('userid'=>$userid);
}
if ($attemptid = optional_param('attemptid', 0, PARAM_INT)){
$viewoptions += array('attemptid'=>$attemptid);
}
if ($action !== 'viewquestions'){
$viewoptions += array('action'=> $action);
}


$this->cm = $cm;

$this->print_header_and_tabs($cm, $course, $quiz, $reportmode="grading");

// Check permissions
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('mod/quiz:grade', $context)) {
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!has_capability('mod/quiz:grade', $this->context)) {
notify(get_string('gradingnotallowed', 'quiz_grading'));
return true;
}
Expand Down Expand Up @@ -101,6 +124,16 @@ function display($quiz, $cm, $course) {
notify(get_string('changessavedwitherrors', 'quiz'), 'notifysuccess');
}
}
$this->viewurl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $viewoptions);
/// find out current groups mode
$currentgroup = groups_get_activity_group($this->cm, true);

if ($groupmode = groups_get_activity_groupmode($this->cm)) { // Groups are being used
groups_print_activity_menu($this->cm, $this->viewurl->out(false, array('userid'=>0, 'attemptid'=>0)));
}

$this->users = get_users_by_capability($this->context, 'mod/quiz:attempt','','','','',$currentgroup,'',false);
$this->userids = implode(',', array_keys($this->users));

// our 3 different views
// the first one displays all of the manually graded questions in the quiz
Expand All @@ -120,7 +153,7 @@ function display($quiz, $cm, $course) {
$this->view_question($quiz, $question);
break;
case 'grade':
$this->print_questions_and_form($quiz, $question);
$this->print_questions_and_form($quiz, $question, $userid, $attemptid);
break;
}
return true;
Expand All @@ -130,17 +163,13 @@ function display($quiz, $cm, $course) {
* Prints a table containing all manually graded questions
*
* @param object $quiz Quiz object of the currrent quiz
* @param object $course Course object of the current course
* @param string $userids Comma-separated list of userids in this course
* @return boolean
* @todo Look for the TODO in this code to see what still needs to be done
**/
function view_questions($quiz) {
global $CFG, $QTYPE_MANUAL;

$users = get_course_students($quiz->course);

if(empty($users)) {
if(empty($this->users)) {
print_heading(get_string("noattempts", "quiz"));
return true;
}
Expand Down Expand Up @@ -171,8 +200,7 @@ function view_questions($quiz) {
notify(get_string('essayonly', 'quiz_grading'));

// get all the finished attempts by the users
$userids = implode(', ', array_keys($users));
if ($attempts = get_records_select('quiz_attempts', "quiz = $quiz->id and timefinish > 0 AND userid IN ($userids) AND preview = 0", 'userid, attempt')) {
if ($attempts = get_records_select('quiz_attempts', "quiz = $quiz->id and timefinish > 0 AND userid IN ({$this->userids}) AND preview = 0", 'userid, attempt')) {
foreach($questions as $question) {

$link = "<a href=\"report.php?mode=grading&amp;q=$quiz->id&amp;action=viewquestion&amp;questionid=$question->id\">".
Expand Down Expand Up @@ -205,9 +233,8 @@ function view_questions($quiz) {
function view_question($quiz, $question) {
global $CFG, $db;

$users = get_course_students($quiz->course);
$userids = implode(',', array_keys($users));
$usercount = count($users);

$usercount = count($this->users);

// set up table
$tablecolumns = array('picture', 'fullname', 'timefinish', 'grade');
Expand All @@ -217,7 +244,7 @@ function view_question($quiz, $question) {

$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($CFG->wwwroot.'/mod/quiz/report.php?mode=grading&amp;q='.$quiz->id.'&amp;action=viewquestion&amp;questionid='.$question->id);
$table->define_baseurl($this->viewurl->out());

$table->sortable(true);
$table->initialbars($usercount>20); // will show initialbars if there are more than 20 users
Expand All @@ -243,7 +270,7 @@ function view_question($quiz, $question) {
// this sql is a join of the attempts table and the user table. I do this so I can sort by user name and attempt number (not id)
$select = 'SELECT '.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS userattemptid, qa.id AS attemptid, qa.uniqueid, qa.attempt, qa.timefinish, u.id AS userid, u.firstname, u.lastname, u.picture ';
$from = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON (u.id = qa.userid AND qa.quiz = '.$quiz->id.') ';
$where = 'WHERE u.id IN ('.$userids.') ';
$where = 'WHERE u.id IN ('.$this->userids.') ';
$where .= 'AND '.$db->IfNull('qa.attempt', '0').' != 0 ';
$where .= 'AND '.$db->IfNull('qa.timefinish', '0').' != 0 ';
$where .= 'AND preview = 0 '; // ignore previews
Expand Down Expand Up @@ -293,7 +320,7 @@ function view_question($quiz, $question) {
}

// grade all and "back" links
$links = "<div class=\"boxaligncenter\"><a href=\"report.php?mode=grading&amp;action=grade&amp;q=$quiz->id&amp;questionid=$question->id&amp;gradeall=1\">".get_string('gradeall', 'quiz').'</a> | '.
$links = "<div class=\"boxaligncenter\"><a href=\"report.php?mode=grading&amp;action=grade&amp;q=$quiz->id&amp;questionid=$question->id\">".get_string('gradeall', 'quiz').'</a> | '.
"<a href=\"report.php?mode=grading&amp;q=$quiz->id&amp;action=viewquestions\">".get_string('backtoquestionlist', 'quiz').'</a></div>'.
// print everything here
Expand Down Expand Up @@ -331,34 +358,28 @@ function is_graded($question, $attempt) {
* @return void
* @todo Finish documenting this function
**/
function print_questions_and_form($quiz, $question) {
function print_questions_and_form($quiz, $question, $userid, $attemptid) {
global $CFG, $db;

// grade question specific parameters
$gradeall = optional_param('gradeall', 0, PARAM_INT);
$userid = optional_param('userid', 0, PARAM_INT);
$attemptid = optional_param('attemptid', 0, PARAM_INT);

// TODO get the context, and put in proper roles an permissions checks.
$context = NULL;

$questions[$question->id] = &$question;
$usehtmleditor = can_use_richtext_editor();
$users = get_course_students($quiz->course);
$userids = implode(',', array_keys($users));

// this sql joins the attempts table and the user table
$select = 'SELECT '.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS userattemptid,
qa.id AS attemptid, qa.uniqueid, qa.attempt, qa.timefinish, qa.preview,
u.id AS userid, u.firstname, u.lastname, u.picture ';
$from = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON (u.id = qa.userid AND qa.quiz = '.$quiz->id.') ';

if ($gradeall) { // get all user attempts
$where = 'WHERE u.id IN ('.$userids.') ';
} else if ($userid) { // get all the attempts for a specific user
if ($userid) { // get all the attempts for a specific user
$where = 'WHERE u.id='.$userid.' ';
} else { // get a specific attempt
} else if ($attemptid) { // get a specific attempt
$where = 'WHERE qa.id='.$attemptid.' ';
} else { // get all user attempts
$where = 'WHERE u.id IN ('.$this->userids.') ';
}

// ignore previews
Expand Down Expand Up @@ -394,7 +415,7 @@ function print_questions_and_form($quiz, $question) {
$options->readonly = 1;

// print the user name, attempt count, the question, and some more hidden fields
echo '<div class="boxaligncenter" width="80%" style="padding:15px;">'.
echo '<div class="boxaligncenter" width="80%" style="clear:left;padding:15px;">'.
fullname($attempt, true).': '.
get_string('attempt', 'quiz').$attempt->attempt;

Expand Down

0 comments on commit 3014691

Please sign in to comment.