]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17003: Completion progress report needs paging system as large reports can kill...
authorsam_marshall <sam_marshall>
Fri, 24 Oct 2008 16:20:37 +0000 (16:20 +0000)
committersam_marshall <sam_marshall>
Fri, 24 Oct 2008 16:20:37 +0000 (16:20 +0000)
course/report/progress/index.php
lang/en_utf8/completion.php
lib/completionlib.php
theme/standard/styles_layout.css

index 978ecd13591c8e62ef3222b9c6d37201792915d5..99d0c27348725786777b6ac25af6da5ee2dae77d 100644 (file)
@@ -1,8 +1,9 @@
 <?php
-
 require_once('../../../config.php');
 global $DB;
 
+define('COMPLETION_REPORT_PAGE',50);
+
 // Get course
 $course=$DB->get_record('course',array('id'=>required_param('course',PARAM_INT)));
 if(!$course) {
@@ -18,6 +19,9 @@ $format=optional_param('format','',PARAM_ALPHA);
 $excel=$format=='excelcsv';
 $csv=$format=='csv' || $excel;
 
+// Whether to start at a particular position
+$start=optional_param('start',0,PARAM_INT);
+
 // Whether to show idnumber
 // TODO: This should really not be using a config option 'intended' for 
 // gradebook, but that option is also used in quiz reports as well. There ought
@@ -54,8 +58,8 @@ $activities=$completion->get_activities();
 if(count($activities)==0) {
     print_error('err_noactivities','completion',$reportsurl);
 }
-$progress=$completion->get_progress_all($firstnamesort,$group);
 
+$progress=$completion->get_progress_all($firstnamesort,$group,COMPLETION_REPORT_PAGE,$start);
 
 if($csv) {
     header('Content-Disposition: attachment; filename=progress.'.
@@ -93,17 +97,47 @@ if($csv) {
     groups_print_course_menu($course,$CFG->wwwroot.'/course/report/progress/?course='.$course->id);
 }
 
++// Do we need a paging bar?
+if($progress->total > COMPLETION_REPORT_PAGE) {
+    $pagingbar='<div class="completion_pagingbar">';
+
+    if($start>0) {
+        $newstart=$start-COMPLETION_REPORT_PAGE;
+        if($newstart<0) {
+            $newstart=0;
+        }
+        $pagingbar.=link_arrow_left(get_string('previous'),'./?course='.$course->id.
+            ($newstart ? '&amp;start='.$newstart : ''),false,'completion_prev');
+    }
+
+    $a=new StdClass;
+    $a->from=$start+1;
+    $a->to=$start+COMPLETION_REPORT_PAGE;
+    $a->total=$progress->total;
+    $pagingbar.='<p>'.get_string('reportpage','completion',$a).'</p>';
+
+    if($start+COMPLETION_REPORT_PAGE < $progress->total) {
+        $pagingbar.=link_arrow_right(get_string('next'),'./?course='.$course->id.
+            '&amp;start='.($start+COMPLETION_REPORT_PAGE),false,'completion_next');
+    }
+
+    $pagingbar.='</div>';    
+} else {
+    $pagingbar='';
+}
+
 // Okay, let's draw the table of progress info,
 
 // Start of table  
 if(!$csv) {
     print '<br class="clearer"/>'; // ugh
-    if(count($progress)==0) {
+    if(count($progress->users)==0) {
         print '<p class="nousers">'.get_string('err_nousers','completion').'</p>';
         print '<p><a href="'.$reportsurl.'">'.get_string('continue').'</a></p>';
         print_footer($course);
         exit;
     }
+    print $pagingbar;
     print '<table id="completion-progress" class="generaltable flexible boxaligncenter" style="text-align:left"><tr style="vertical-align:top">';
 
     // User heading / sort option
@@ -166,7 +200,7 @@ if($csv) {
 }
 
 // Row for each user
-foreach($progress as $user) {
+foreach($progress->users as $user) {
     // User name
     if($csv) {
         print csv_quote(fullname($user));
@@ -186,9 +220,9 @@ foreach($progress as $user) {
 
         // Get progress information and state
         if(array_key_exists($activity->id,$user->progress)) {
-            $progress=$user->progress[$activity->id];
-            $state=$progress->completionstate;
-            $date=userdate($progress->timemodified);
+            $thisprogress=$user->progress[$activity->id];
+            $state=$thisprogress->completionstate;
+            $date=userdate($thisprogress->timemodified);
         } else {
             $state=COMPLETION_INCOMPLETE;
             $date='';
@@ -233,6 +267,7 @@ if($csv) {
     exit;
 }
 print '</table>';
+print $pagingbar;
 
 print '<ul class="progress-actions"><li><a href="index.php?course='.$course->id.
     '&amp;format=csv">'.get_string('csvdownload','completion').'</a></li>
index 7b9ed60ae1326d5128866d5929bcfba92f93e165..ef204c84d8de207d393a849d7e7f8cdff7e652f4 100644 (file)
@@ -42,6 +42,7 @@ $string['help_completionview']='requiring view to complete';
 $string['progress']='Student progress';
 $string['progress-title']='$a->user, $a->activity: $a->state $a->date';
 $string['progresstrackedroles'] = 'Progress-tracked roles';
+$string['reportpage']='Showing users {$a->from} to {$a->to} of {$a->total}.';
 $string['restoringcompletiondata']='Writing completion data';
 $string['saved']='Saved';
 $string['unlockcompletion']='Unlock completion options';
index 7e7f7b29d6d89af466d849e7834ef2b13ee4b615..b8049d9fed57e81db253a49993c40c7c545d1b6e 100644 (file)
@@ -608,22 +608,31 @@ class completion_info {
      *   last name
      * @param int $groupid Group ID or 0 (default)/false for all groups
      * @return Array of user objects (like mdl_user id, firstname, lastname, idnumber)
+     * @param int $pagesize Number of users to actually return (0 = unlimited)
+     * @param int $start User to start at if paging (0 = first set)
+     * @return Object with ->total and ->start (same as $start) and ->users;
+     *   an array of user objects (like mdl_user id, firstname, lastname)
      *   containing an additional ->progress array of coursemoduleid => completionstate
      */
-    public function get_progress_all($sortfirstname=false, $groupid=0) {
+    public function get_progress_all($sortfirstname=false, $groupid=0,
+  +     $pagesize=0,$start=0) {
         global $CFG, $DB;
+        $resultobject=new StdClass;
 
         // Get list of applicable users
         $users = $this->internal_get_tracked_users($sortfirstname, $groupid);
+        $resultobject->start=$start;
+        $resultobject->total=count($users);
+        $users=array_slice($users,$start,$pagesize);
 
         // Get progress information for these users in groups of 1, 000 (if needed)
         // to avoid making the SQL IN too long
-        $result = array();
+        $resultobject->users=array();
         $userids = array();
         foreach ($users as $user) {
             $userids[] = $user->id;
-            $result[$user->id] = $user;
-            $result[$user->id]->progress = array();
+            $resultobject->users[$user->id]=$user;
+            $resultobject->users[$user->id]->progress=array();            
         }
 
         for($i=0; $i<count($userids); $i+=1000) {
@@ -644,12 +653,12 @@ WHERE
                 $this->internal_systemerror('Failed to obtain completion progress');
             }
             foreach ($rs as $progress) {
-                $result[$progress->userid]->progress[$progress->coursemoduleid] = $progress;
+                $resultobject->users[$progress->userid]->progress[$progress->coursemoduleid]=$progress;
             }
             $rs->close();
         }
 
-        return $result;
+        return $resultobject;
     }
 
     public function inform_grade_changed($cm, $item, $grade, $deleted) {
index cd09216f8ea771e7135b0be1576c69057e7c5dbc..f27ae4d5a0fdd5e808f5b37a7f80f57be9c1893f 100644 (file)
@@ -2847,6 +2847,22 @@ body.notes .notesgroup {
 #course-report-progress-index .progress-actions {
   text-align:center;
 }
+#course-report-progress-index .completion_pagingbar {
+  margin:1em 0;
+  text-align:center;
+}
+#course-report-progress-index .completion_prev {
+  display:inline;
+  margin-right:2em;
+}
+#course-report-progress-index .completion_pagingbar p {
+  display:inline;
+  margin:0;
+}
+#course-report-progress-index .completion_next {
+  display:inline;
+  margin-left:2em;
+}
 
 /***
  *** Logs