📄 report.php
字号:
$usercount = count($this->users); // set up table $tablecolumns = array('picture', 'fullname', 'timefinish', 'grade'); $tableheaders = array('', get_string('name'), get_string("completedon", "quiz"), ''); $table = new flexible_table('mod-quiz-report-grading'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($this->viewurl->out()); $table->sortable(true); $table->initialbars($usercount>20); // will show initialbars if there are more than 20 users $table->pageable(true); $table->collapsible(true); $table->column_suppress('fullname'); $table->column_suppress('picture'); $table->column_suppress('grade'); $table->column_class('picture', 'picture'); // attributes in the table tag $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'attempts'); $table->set_attribute('class', 'generaltable generalbox'); $table->set_attribute('align', 'center'); //$table->set_attribute('width', '50%'); // get it ready! $table->setup(); list($select, $from, $where) = $this->attempts_sql($quiz->id, true, $question->id); if($table->get_sql_where()) { // forgot what this does $where .= 'AND '.$table->get_sql_where(); } // sorting of the table if($sort = $table->get_sql_sort()) { $sort = 'ORDER BY '.$sort; // seems like I would need to have u. or qa. infront of the ORDER BY attribues... but seems to work.. } else { // my default sort rule $sort = 'ORDER BY u.firstname, u.lastname, qa.timefinish ASC'; } // set up the pagesize $table->pagesize(QUIZ_REPORT_DEFAULT_PAGE_SIZE, $totalattempts); // get the attempts and process them if ($attempts = get_records_sql($select.$from.$where.$sort,$table->get_page_start(), $table->get_page_size())) { // grade all link $links = "<strong><a href=\"report.php?mode=grading&gradeall=1&q=$quiz->id&questionid=$question->id\">".get_string('gradeall', 'quiz_grading', $totalattempts).'</a></strong>'; if ($ungraded>0){ $links .="<br /><strong><a href=\"report.php?mode=grading&gradeungraded=1&q=$quiz->id&questionid=$question->id\">".get_string('gradeungraded', 'quiz_grading', $ungraded).'</a></strong>'; if ($ungraded>QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE){ $links .="<br /><strong><a href=\"report.php?mode=grading&gradenextungraded=1&q=$quiz->id&questionid=$question->id\">".get_string('gradenextungraded', 'quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE).'</a></strong>'; } } $table->add_data_keyed(array('grade'=> $links)); $table->add_separator(); foreach($attempts as $attempt) { $picture = print_user_picture($attempt->userid, $quiz->course, $attempt->picture, false, true); // link to student profile $userlink = "<a href=\"$CFG->wwwroot/user/view.php?id=$attempt->userid&course=$quiz->course\">". fullname($attempt, true).'</a>'; $gradedclass = question_state_is_graded($attempt)?' class="highlightgraded" ':''; $gradedstring = question_state_is_graded($attempt)?(' '.get_string('graded','quiz_grading')):''; // link for the attempt $attemptlink = "<a {$gradedclass}href=\"report.php?mode=grading&q=$quiz->id&questionid=$question->id&attemptid=$attempt->attemptid\">". userdate($attempt->timefinish, get_string('strftimedatetime')). $gradedstring.'</a>'; // grade all attempts for this user $gradelink = "<a href=\"report.php?mode=grading&q=$quiz->id&questionid=$question->id&userid=$attempt->userid\">". get_string('grade').'</a>'; $table->add_data( array($picture, $userlink, $attemptlink, $gradelink) ); } $table->add_separator(); $table->add_data_keyed(array('grade'=> $links)); // print everything here echo '<div id="tablecontainer">'; $table->print_html(); echo '</div>'; } else { notify(get_string('noattemptstoshow', 'quiz')); } } /** * 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; // TODO get the context, and put in proper roles an permissions checks. $context = NULL; $questions[$question->id] = &$question; $usehtmleditor = can_use_richtext_editor(); list($select, $from, $where) = $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 = get_records_sql($select.$from.$where.$sort, 0, QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE); } else { $attempts = get_records_sql($select.$from.$where.$sort); } if ($attempts){ $firstattempt = current($attempts); $fullname = fullname($firstattempt); if ($gradeungraded) { // getting all ungraded attempts print_heading(get_string('gradingungraded','quiz_grading', $ungraded), '', 3); } else if ($gradenextungraded) { // getting next ungraded attempts print_heading(get_string('gradingnextungraded','quiz_grading', QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE), '', 3); } else if ($userid){ print_heading(get_string('gradinguser','quiz_grading', $fullname), '', 3); } else if ($attemptid){ $a = new object(); $a->fullname = $fullname; $a->attempt = $firstattempt->attempt; print_heading(get_string('gradingattempt','quiz_grading', $a), '', 3); } else { print_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">'. '<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->noeditlink = true; $copy = $state->manualcomment; $state->manualcomment = ''; $options->readonly = 1; $gradedclass = question_state_is_graded($state)?' class="highlightgraded" ':''; $gradedstring = question_state_is_graded($state)?(' '.get_string('graded','quiz_grading')):''; $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 "<span$gradedclass>".get_string('gradingattempt','quiz_grading', $a); echo $gradedstring."</span>"; print_question($question, $state, '', $quiz, $options); $prefix = "manualgrades[$attempt->uniqueid]"; if (!question_state_is_graded($state)) { $grade = ''; } else { $grade = round($state->last_graded->grade, 3); } $state->manualcomment = $copy; include($CFG->dirroot . '/question/comment.html'); echo '</div>'; } echo '<div class="boxaligncenter"><input type="submit" value="'.get_string('savechanges').'" /></div>'. '</form>'; if ($usehtmleditor) { use_html_editor(); } } else { notify(get_string('noattemptstoshow', 'quiz')); } } function attempts_sql($quizid, $wantstateevent=false, $questionid=0, $userid=0, $attemptid=0, $gradeungraded=0, $gradenextungraded=0){ global $CFG; // this sql joins the attempts table and the user table $select = 'SELECT qa.id AS attemptid, qa.uniqueid, qa.attempt, qa.timefinish, qa.preview, u.id AS userid, u.firstname, u.lastname, u.picture '; if ($wantstateevent && $questionid){ $select .= ', qs.event '; } $from = 'FROM '.$CFG->prefix.'user u, ' . $CFG->prefix.'quiz_attempts qa '; if (($wantstateevent|| $gradenextungraded || $gradeungraded) && $questionid){ $from .= "LEFT JOIN {$CFG->prefix}question_sessions qns " . "ON (qns.attemptid = qa.uniqueid AND qns.questionid = $questionid) "; $from .= "LEFT JOIN {$CFG->prefix}question_states qs " . "ON (qs.id = qns.newgraded AND qs.question = $questionid) "; } if ($gradenextungraded || $gradeungraded) { // get ungraded attempts $where = 'WHERE u.id IN ('.$this->userids.') AND qs.event NOT IN ('.QUESTION_EVENTS_GRADED.') '; } else if ($userid) { // get all the attempts for a specific user $where = 'WHERE u.id='.$userid.' '; } else if ($attemptid) { // get a specific attempt $where = 'WHERE qa.id='.$attemptid.' '; } else { // get all user attempts $where = 'WHERE u.id IN ('.$this->userids.') '; } $where .= ' AND u.id = qa.userid AND qa.quiz = '.$quizid; // ignore previews $where .= ' AND preview = 0 '; $where .= ' AND qa.timefinish != 0 '; return array($select, $from, $where); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -