From: jamiesensei Date: Mon, 5 May 2008 13:12:11 +0000 (+0000) Subject: For overview report - MDL-14185 "Switch to using formslib and improve the interface... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0217f9327589dff9879567e64e87882f98b8963d;p=moodle.git For overview report - MDL-14185 "Switch to using formslib and improve the interface" and MDL-14186 "Switch to using moodle_url and eliminate the use of $SESSION global" --- diff --git a/lang/en_utf8/quiz_overview.php b/lang/en_utf8/quiz_overview.php index 75ff741cc9..5cf63421d9 100644 --- a/lang/en_utf8/quiz_overview.php +++ b/lang/en_utf8/quiz_overview.php @@ -6,7 +6,14 @@ $string['allattempts'] = 'Show all attempts'; $string['allstudents'] = 'Show all $a'; $string['attemptsonly'] = 'Show $a with attempts only'; $string['noattemptsonly'] = 'Show $a with no attempts only'; +$string['optallattempts'] = 'all attempts'; +$string['optallstudents'] = 'all $a'; +$string['optattemptsonly'] = '$a with attempts only'; +$string['optnoattemptsonly'] = '$a with no attempts only'; $string['overview'] = 'Overview'; $string['overviewdownload'] = 'Overview download'; - +$string['preferencespage'] = 'Preferences just for this page'; +$string['preferencessave'] = 'Save preferences'; +$string['preferencesuser'] = 'Your preferences for this report'; +$string['show'] = 'Show'; ?> diff --git a/mod/quiz/report/overview/overviewsettings_form.php b/mod/quiz/report/overview/overviewsettings_form.php new file mode 100644 index 0000000000..4c41abe88b --- /dev/null +++ b/mod/quiz/report/overview/overviewsettings_form.php @@ -0,0 +1,30 @@ +libdir/formslib.php"; +class mod_quiz_report_overview_settings extends moodleform { + + function definition() { + global $COURSE; + $mform =& $this->_form; +//------------------------------------------------------------------------------- + $mform->addElement('header', 'general', get_string('preferencespage', 'quiz_overview')); + + $options = array(0 => get_string('attemptsonly','quiz_overview', $COURSE->students)); + if ($COURSE->id != SITEID) { + $options[1] = get_string('noattemptsonly', 'quiz_overview', $COURSE->students); + $options[2] = get_string('allstudents','quiz_overview', $COURSE->students); + $options[3] = get_string('allattempts','quiz_overview'); + } + $mform->addElement('select', 'attemptsmode', get_string('show', 'quiz_overview'), $options); + +//------------------------------------------------------------------------------- + $mform->addElement('header', 'general', get_string('preferencesuser', 'quiz_overview')); + + $mform->addElement('text', 'pagesize', get_string('pagesize', 'quiz')); + $mform->setType('pagesize', PARAM_INT); + + $mform->addElement('selectyesno', 'detailedmarks', get_string('showdetailedmarks', 'quiz')); + + $this->add_action_buttons(false, get_string('preferencessave', 'quiz_overview')); + } +} +?> diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 41c32a0ab7..3a9b1d37eb 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -9,6 +9,7 @@ *//** */ require_once($CFG->libdir.'/tablelib.php'); +require_once($CFG->dirroot.'/mod/quiz/report/overview/overviewsettings_form.php'); class quiz_report extends quiz_default_report { @@ -17,7 +18,6 @@ class quiz_report extends quiz_default_report { */ function display($quiz, $cm, $course) { global $CFG, $db; - // Define some strings $strreallydel = addslashes(get_string('deleteattemptcheck','quiz')); $strtimeformat = get_string('strftimedatetime'); @@ -27,7 +27,7 @@ class quiz_report extends quiz_default_report { // Only print headers if not asked to download data if (!$download = optional_param('download', NULL)) { - $this->print_header_and_tabs($cm, $course, $quiz, $reportmode="overview"); + $this->print_header_and_tabs($cm, $course, $quiz, "overview"); } // Deal with actions @@ -65,26 +65,41 @@ class quiz_report extends quiz_default_report { $reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $context); $showgrades = $quiz->grade && $quiz->sumgrades && $reviewoptions->scores; - // Set table options - $noattempts = optional_param('noattempts', 0, PARAM_INT); - $detailedmarks = optional_param('detailedmarks', 0, PARAM_INT); - $pagesize = optional_param('pagesize', 0, PARAM_INT); - $reporturl = $CFG->wwwroot.'/mod/quiz/report.php?mode=overview'; - if ($pagesize < 1) { - $pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE; - } if (!$reviewoptions->scores) { $detailedmarks = 0; } - $reporturlwithoptions = $reporturl . '&id=' . $cm->id . '&noattempts=' . $noattempts . - '&detailedmarks=' . $detailedmarks . '&pagesize=' . $pagesize; + $pageoptions = array(); + $pageoptions['id'] = $cm->id; + $pageoptions['q'] = $quiz->id; + $pageoptions['mode'] = 'overview'; + + $reporturl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions); + $mform = new mod_quiz_report_overview_settings($reporturl); + if ($fromform = $mform->get_data()){ + $attemptsmode = $fromform->attemptsmode; + set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks); + set_user_preference('quiz_report_pagesize', $fromform->pagesize); + $detailedmarks = $fromform->detailedmarks; + $pagesize = $fromform->pagesize; + } else { + $attemptsmode = optional_param('attemptsmode', 0, PARAM_INT); + $detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1); + $pagesize = get_user_preferences('quiz_report_pagesize', 0); + } + if ($pagesize < 1) { + $pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE; + } + + $displayoptions = array(); + $displayoptions['attemptsmode'] = $attemptsmode; + $reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions + $displayoptions); /// find out current groups mode $currentgroup = groups_get_activity_group($cm, true); if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used if (!$download) { - groups_print_activity_menu($cm, $reporturlwithoptions); + groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out()); } } @@ -137,7 +152,7 @@ class quiz_report extends quiz_default_report { $table->define_columns($tablecolumns); $table->define_headers($tableheaders); - $table->define_baseurl($reporturlwithoptions); + $table->define_baseurl($reporturlwithdisplayoptions->out()); $table->sortable(true); $table->collapsible(true); @@ -287,7 +302,7 @@ class quiz_report extends quiz_default_report { // Get users with quiz attempt capability 'students'. // don't need to do this expensive call if we are listing all attempts though. - if ( $noattempts != 3 ) { + if ( $attemptsmode != 3 ) { if (empty($currentgroup)) { // all users who can attempt quizzes $allowed = join(',',array_keys(get_users_by_capability($context, 'mod/quiz:attempt','','','','','','',false))); @@ -307,7 +322,7 @@ class quiz_report extends quiz_default_report { $from = 'FROM '.$CFG->prefix.'user u '; $from .= 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON qa.userid = u.id AND qa.quiz = '.$quiz->id; - if ( $noattempts == 3 ) { // Show all attempts, including students who are no longer in the course + if ( $attemptsmode == 3 ) { // Show all attempts, including students who are no longer in the course $where = ' WHERE qa.id IS NOT NULL'; // Comment out the following line to include preview attempts in the 'show all attempts' filter @@ -316,9 +331,9 @@ class quiz_report extends quiz_default_report { $where = ' WHERE u.id IN (' .$allowed. ') AND (qa.preview = 0 OR qa.preview IS NULL)'; - if ( empty( $noattempts )) { // Show only students with attempts + if ( empty( $attemptsmode )) { // Show only students with attempts $where .= ' AND qa.id IS NOT NULL'; - } else if ( $noattempts == 1 ) { // Show only students without attempts + } else if ( $attemptsmode == 1 ) { // Show only students without attempts $where .= ' AND qa.id IS NULL'; } } @@ -398,14 +413,16 @@ class quiz_report extends quiz_default_report { if (!$download) { $table->initialbars($totalinitials>20); } - if(!empty($attempts) || !empty($noattempts)) { + if(!empty($attempts) || !empty($attemptsmode)) { if ($attempts) { if($detailedmarks) { //get all the attempt ids we want to display on this page //or to export for download. $attemptids = array(); foreach ($attempts as $attempt){ - $attemptids[] = $attempt->attemptuniqueid; + if ($attempt->attemptuniqueid > 0){ + $attemptids[] = $attempt->attemptuniqueid; + } } $gradedstatesbyattempt = quiz_get_newgraded_states($attemptids); } @@ -519,10 +536,11 @@ class quiz_report extends quiz_default_report { if (!$download) { // Start form echo '
'; - echo '
'; + echo $reporturlwithdisplayoptions->hidden_params_out(); echo '
'; // Print table @@ -554,24 +572,17 @@ document.getElementById("noscriptmenuaction").style.display = "none"; if (!empty($attempts)) { echo ''; - $options = array(); - $options["id"] = $cm->id; - $options["q"] = $quiz->id; - $options['sesskey'] = sesskey(); - $options["noheader"] = "yes"; - $options['noattempts'] = $noattempts; - $options['detailedmarks'] = $detailedmarks; echo '\n"; echo '\n"; echo '\n"; echo "
'; - $options["download"] = "ODS"; - print_single_button($reporturl, $options, get_string("downloadods")); + print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'ODS'), + get_string('downloadods')); echo "'; - $options["download"] = "Excel"; - print_single_button($reporturl, $options, get_string("downloadexcel")); + print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'Excel'), + get_string('downloadexcel')); echo "'; - $options["download"] = "CSV"; - print_single_button($reporturl, $options, get_string("downloadtext")); + print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'CSV'), + get_string('downloadtext')); echo ""; helpbutton('overviewdownload', get_string('overviewdownload', 'quiz_overview'), 'quiz'); @@ -590,44 +601,11 @@ document.getElementById("noscriptmenuaction").style.display = "none"; $table->print_html(); } } - // Print display options - echo '
'; - echo ''; - echo '
'; - echo '

'.get_string('displayoptions', 'quiz').':

'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - $options = array(0 => get_string('attemptsonly','quiz_overview', $course->students)); - if ($course->id != SITEID) { - $options[1] = get_string('noattemptsonly', 'quiz_overview', $course->students); - $options[2] = get_string('allstudents','quiz_overview', $course->students); - $options[3] = get_string('allattempts','quiz_overview'); + if (!$download) { + // Print display options + $mform->set_data($displayoptions +compact('detailedmarks', 'pagesize')); + $mform->display(); } - choose_from_menu($options,'noattempts',$noattempts,''); - echo '
'; - echo ' '; - echo ' '; - echo '
'; - echo ''; - echo '
'; - echo '
'; - echo ''; - echo '
'; - echo "\n"; - return true; } } diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index bba51ae37c..0ae7109b8f 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -7,24 +7,28 @@ define('QUIZ_REPORT_DEFAULT_PAGE_SIZE', 30); */ function quiz_get_newgraded_states($attemptids, $idxattemptq = true){ global $CFG; - $attemptidlist = join($attemptids, ','); - $gradedstatesql = "SELECT qs.* FROM " . - "{$CFG->prefix}question_sessions qns, " . - "{$CFG->prefix}question_states qs " . - "WHERE qns.attemptid IN ($attemptidlist) AND " . - "qns.newgraded = qs.id"; - $gradedstates = get_records_sql($gradedstatesql); - if ($idxattemptq){ - $gradedstatesbyattempt = array(); - foreach ($gradedstates as $gradedstate){ - if (!isset($gradedstatesbyattempt[$gradedstate->attempt])){ - $gradedstatesbyattempt[$gradedstate->attempt] = array(); + if ($attemptids){ + $attemptidlist = join($attemptids, ','); + $gradedstatesql = "SELECT qs.* FROM " . + "{$CFG->prefix}question_sessions qns, " . + "{$CFG->prefix}question_states qs " . + "WHERE qns.attemptid IN ($attemptidlist) AND " . + "qns.newgraded = qs.id"; + $gradedstates = get_records_sql($gradedstatesql); + if ($idxattemptq){ + $gradedstatesbyattempt = array(); + foreach ($gradedstates as $gradedstate){ + if (!isset($gradedstatesbyattempt[$gradedstate->attempt])){ + $gradedstatesbyattempt[$gradedstate->attempt] = array(); + } + $gradedstatesbyattempt[$gradedstate->attempt][$gradedstate->question] = $gradedstate; } - $gradedstatesbyattempt[$gradedstate->attempt][$gradedstate->question] = $gradedstate; + return $gradedstatesbyattempt; + } else { + return $gradedstates; } - return $gradedstatesbyattempt; } else { - return $gradedstates; + return array(); } } /**