<?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) {
$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
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.'.
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 ? '&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.
+ '&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
}
// Row for each user
-foreach($progress as $user) {
+foreach($progress->users as $user) {
// User name
if($csv) {
print csv_quote(fullname($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='';
exit;
}
print '</table>';
+print $pagingbar;
print '<ul class="progress-actions"><li><a href="index.php?course='.$course->id.
'&format=csv">'.get_string('csvdownload','completion').'</a></li>
* 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) {
$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) {