Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/report/responses/report.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 require_once($CFG->dirroot.'/mod/quiz/report/attemptsreport.php');
00030 require_once($CFG->dirroot.'/mod/quiz/report/responses/responsessettings_form.php');
00031 require_once($CFG->dirroot.'/mod/quiz/report/responses/responses_table.php');
00032 
00033 
00048 class quiz_responses_report extends quiz_attempt_report {
00049 
00050     public function display($quiz, $cm, $course) {
00051         global $CFG, $COURSE, $DB, $PAGE, $OUTPUT;
00052 
00053         $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
00054 
00055         $download = optional_param('download', '', PARAM_ALPHA);
00056 
00057         list($currentgroup, $students, $groupstudents, $allowed) =
00058                 $this->load_relevant_students($cm, $course);
00059 
00060         $pageoptions = array();
00061         $pageoptions['id'] = $cm->id;
00062         $pageoptions['mode'] = 'responses';
00063 
00064         $reporturl = new moodle_url('/mod/quiz/report.php', $pageoptions);
00065         $qmsubselect = quiz_report_qm_filter_select($quiz);
00066 
00067         $mform = new mod_quiz_report_responses_settings($reporturl,
00068                 array('qmsubselect' => $qmsubselect, 'quiz' => $quiz,
00069                 'currentgroup' => $currentgroup, 'context' => $this->context));
00070 
00071         if ($fromform = $mform->get_data()) {
00072             $attemptsmode = $fromform->attemptsmode;
00073             if ($qmsubselect) {
00074                 $qmfilter = $fromform->qmfilter;
00075             } else {
00076                 $qmfilter = 0;
00077             }
00078             set_user_preference('quiz_report_responses_qtext', $fromform->qtext);
00079             set_user_preference('quiz_report_responses_resp', $fromform->resp);
00080             set_user_preference('quiz_report_responses_right', $fromform->right);
00081             set_user_preference('quiz_report_pagesize', $fromform->pagesize);
00082             $includeqtext = $fromform->qtext;
00083             $includeresp = $fromform->resp;
00084             $includeright = $fromform->right;
00085             $pagesize = $fromform->pagesize;
00086 
00087         } else {
00088             $attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
00089             if ($qmsubselect) {
00090                 $qmfilter = optional_param('qmfilter', 0, PARAM_INT);
00091             } else {
00092                 $qmfilter = 0;
00093             }
00094             $includeqtext = get_user_preferences('quiz_report_responses_qtext', 0);
00095             $includeresp = get_user_preferences('quiz_report_responses_resp', 1);
00096             $includeright = get_user_preferences('quiz_report_responses_right', 0);
00097             $pagesize = get_user_preferences('quiz_report_pagesize', 0);
00098         }
00099 
00100         $this->validate_common_options($attemptsmode, $pagesize, $course, $currentgroup);
00101         if (!$includeqtext && !$includeresp && !$includeright) {
00102             $includeresp = 1;
00103             set_user_preference('quiz_report_responses_resp', 1);
00104         }
00105 
00106         // We only want to show the checkbox to delete attempts
00107         // if the user has permissions and if the report mode is showing attempts.
00108         $includecheckboxes = has_capability('mod/quiz:deleteattempts', $this->context)
00109                 && ($attemptsmode != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
00110 
00111         $displayoptions = array();
00112         $displayoptions['attemptsmode'] = $attemptsmode;
00113         $displayoptions['qmfilter'] = $qmfilter;
00114         $displayoptions['qtext'] = $includeqtext;
00115         $displayoptions['resp'] = $includeresp;
00116         $displayoptions['right'] = $includeright;
00117 
00118         $mform->set_data($displayoptions + array('pagesize' => $pagesize));
00119 
00120         if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
00121             // This option is only available to users who can access all groups in
00122             // groups mode, so setting allowed to empty (which means all quiz attempts
00123             // are accessible, is not a security porblem.
00124             $allowed = array();
00125         }
00126 
00127         if (empty($currentgroup) || $groupstudents) {
00128             if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
00129                 if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
00130                     require_capability('mod/quiz:deleteattempts', $this->context);
00131                     $this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
00132                     redirect($reporturl->out(false, $displayoptions));
00133                 }
00134             }
00135         }
00136 
00137         // Load the required questions.
00138         $questions = quiz_report_get_significant_questions($quiz);
00139 
00140         $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
00141         $courseshortname = format_string($course->shortname, true,
00142                 array('context' => $coursecontext));
00143 
00144         $displaycoursecontext = get_context_instance(CONTEXT_COURSE, $COURSE->id);
00145         $displaycourseshortname = format_string($COURSE->shortname, true,
00146                 array('context' => $displaycoursecontext));
00147 
00148         $table = new quiz_report_responses_table($quiz, $this->context, $qmsubselect,
00149                 $qmfilter, $attemptsmode, $groupstudents, $students, $questions,
00150                 $includecheckboxes, $reporturl, $displayoptions);
00151         $filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
00152                 $courseshortname, $quiz->name);
00153         $table->is_downloading($download, $filename,
00154                 $displaycourseshortname . ' ' . format_string($quiz->name, true));
00155         if ($table->is_downloading()) {
00156             raise_memory_limit(MEMORY_EXTRA);
00157         }
00158 
00159         if (!$table->is_downloading()) {
00160             // Only print headers if not asked to download data
00161             $this->print_header_and_tabs($cm, $course, $quiz, 'responses');
00162         }
00163 
00164         if ($groupmode = groups_get_activity_groupmode($cm)) {   // Groups are being used
00165             if (!$table->is_downloading()) {
00166                 groups_print_activity_menu($cm, $reporturl->out(true, $displayoptions));
00167             }
00168         }
00169 
00170         // Print information on the number of existing attempts
00171         if (!$table->is_downloading()) { //do not print notices when downloading
00172             if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
00173                 echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
00174             }
00175         }
00176 
00177         $hasquestions = quiz_questions_in_quiz($quiz->questions);
00178         if (!$table->is_downloading()) {
00179             if (!$hasquestions) {
00180                 echo quiz_no_questions_message($quiz, $cm, $this->context);
00181             } else if (!$students) {
00182                 echo $OUTPUT->notification(get_string('nostudentsyet'));
00183             } else if ($currentgroup && !$groupstudents) {
00184                 echo $OUTPUT->notification(get_string('nostudentsingroup'));
00185             }
00186 
00187             // Print display options
00188             $mform->display();
00189         }
00190 
00191         $hasstudents = $students && (!$currentgroup || $groupstudents);
00192         if ($hasquestions && ($hasstudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
00193             // Print information on the grading method and whether we are displaying
00194             if (!$table->is_downloading()) { //do not print notices when downloading
00195                 if ($strattempthighlight = quiz_report_highlighting_grading_method(
00196                         $quiz, $qmsubselect, $qmfilter)) {
00197                     echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
00198                 }
00199             }
00200 
00201             list($fields, $from, $where, $params) = $table->base_sql($allowed);
00202 
00203             $table->set_count_sql("SELECT COUNT(1) FROM $from WHERE $where", $params);
00204 
00205             $table->set_sql($fields, $from, $where, $params);
00206 
00207             // Define table columns
00208             $columns = array();
00209             $headers = array();
00210 
00211             if (!$table->is_downloading() && $includecheckboxes) {
00212                 $columns[] = 'checkbox';
00213                 $headers[] = null;
00214             }
00215 
00216             $this->add_user_columns($table, $columns, $headers);
00217 
00218             if ($table->is_downloading()) {
00219                 $this->add_time_columns($columns, $headers);
00220             }
00221 
00222             $this->add_grade_columns($quiz, $columns, $headers);
00223 
00224             foreach ($questions as $id => $question) {
00225                 if ($displayoptions['qtext']) {
00226                     $columns[] = 'question' . $id;
00227                     $headers[] = get_string('questionx', 'question', $question->number);
00228                 }
00229                 if ($displayoptions['resp']) {
00230                     $columns[] = 'response' . $id;
00231                     $headers[] = get_string('responsex', 'quiz_responses', $question->number);
00232                 }
00233                 if ($displayoptions['right']) {
00234                     $columns[] = 'right' . $id;
00235                     $headers[] = get_string('rightanswerx', 'quiz_responses', $question->number);
00236                 }
00237             }
00238 
00239             $table->define_columns($columns);
00240             $table->define_headers($headers);
00241             $table->sortable(true, 'uniqueid');
00242 
00243             // Set up the table
00244             $table->define_baseurl($reporturl->out(true, $displayoptions));
00245 
00246             $this->configure_user_columns($table);
00247 
00248             $table->no_sorting('feedbacktext');
00249             $table->column_class('sumgrades', 'bold');
00250 
00251             $table->set_attribute('id', 'attempts');
00252 
00253             $table->collapsible(true);
00254 
00255             $table->out($pagesize, true);
00256         }
00257         return true;
00258     }
00259 }
 All Data Structures Namespaces Files Functions Variables Enumerations