]> git.mjollnir.org Git - moodle.git/commitdiff
For overview report - MDL-14185 "Switch to using formslib and improve the interface...
authorjamiesensei <jamiesensei>
Mon, 5 May 2008 13:12:11 +0000 (13:12 +0000)
committerjamiesensei <jamiesensei>
Mon, 5 May 2008 13:12:11 +0000 (13:12 +0000)
lang/en_utf8/quiz_overview.php
mod/quiz/report/overview/overviewsettings_form.php [new file with mode: 0644]
mod/quiz/report/overview/report.php
mod/quiz/report/reportlib.php

index 75ff741cc9d4dbc7f66af9f7003a693fc7040fe9..5cf63421d9a5e7fa91742ff9021d4f1866aff9fe 100644 (file)
@@ -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 (file)
index 0000000..4c41abe
--- /dev/null
@@ -0,0 +1,30 @@
+<?php  // $Id$
+require_once "$CFG->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'));
+    }
+}
+?>
index 41c32a0ab737d20ee468752c72ec4a992260a465..3a9b1d37ebc1002a9bbffec06825fa893ccb7ed2 100644 (file)
@@ -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 . '&amp;id=' . $cm->id . '&amp;noattempts=' . $noattempts .
-                '&amp;detailedmarks=' . $detailedmarks . '&amp;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 '<div id="tablecontainer">';
-                echo '<form id="attemptsform" method="post" action="' . $reporturlwithoptions .
+                echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) .
                         '" onsubmit="var menu = document.getElementById(\'menuaction\'); ' .
                         'return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\''.
                         $strreallydel.'\') : true);">';
+                echo $reporturlwithdisplayoptions->hidden_params_out();
                 echo '<div>';
 
                 // Print table
@@ -554,24 +572,17 @@ document.getElementById("noscriptmenuaction").style.display = "none";
 
                 if (!empty($attempts)) {
                     echo '<table class="boxaligncenter"><tr>';
-                    $options = array();
-                    $options["id"] = $cm->id;
-                    $options["q"] = $quiz->id;
-                    $options['sesskey'] = sesskey();
-                    $options["noheader"] = "yes";
-                    $options['noattempts'] = $noattempts;
-                    $options['detailedmarks'] = $detailedmarks;
                     echo '<td>';
-                    $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 "</td>\n";
                     echo '<td>';
-                    $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 "</td>\n";
                     echo '<td>';
-                    $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 "</td>\n";
                     echo "<td>";
                     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 '<div class="controls">';
-        echo '<form id="options" action="' . $reporturl . '" method="get">';
-        echo '<div>';
-        echo '<p>'.get_string('displayoptions', 'quiz').': </p>';
-        echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
-        echo '<input type="hidden" name="q" value="'.$quiz->id.'" />';
-        echo '<input type="hidden" name="noattempts" value="0" />';
-        echo '<input type="hidden" name="detailedmarks" value="0" />';
-        echo '<table id="overview-options" class="boxaligncenter">';
-        echo '<tr align="left">';
-        echo '<td><label for="pagesize">'.get_string('pagesize', 'quiz').'</label></td>';
-        echo '<td><input type="text" id="pagesize" name="pagesize" size="3" value="'.$pagesize.'" /></td>';
-        echo '</tr>';
-        echo '<tr align="left">';
-        echo '<td colspan="2">';
-        $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 '</td></tr>';
-        echo '<tr align="left">';
-        echo '<td colspan="2">';
-        echo '<input type="checkbox" id="checkdetailedmarks" name="detailedmarks" '.
-                ($detailedmarks?'checked="checked" ':'').'value="1" /> ';
-        echo '<label for="checkdetailedmarks">'.get_string('showdetailedmarks', 'quiz').'</label> ';
-        echo '</td></tr>';
-        echo '<tr><td colspan="2" align="center">';
-        echo '<input type="submit" value="'.get_string('go').'" />';
-        echo '</td></tr></table>';
-        echo '</div>';
-        echo '</form>';
-        echo '</div>';
-        echo "\n";
-
         return true;
     }
 }
index bba51ae37c095f1dc6cea10921ffc9b926cf830e..0ae7109b8fd882372fceb9221c32433aa78f5b01 100644 (file)
@@ -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();
     }
 }
 /**