$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+$context = context_course::instance($course->id);
$url = new moodle_url('/course/report/completion/index.php', array('course'=>$course->id));
$PAGE->set_url($url);
$sifirst = optional_param('sifirst', 'all', PARAM_ALPHA);
$silast = optional_param('silast', 'all', PARAM_ALPHA);
-// Whether to show idnumber
-$idnumbers = $CFG->grade_report_showuseridnumber;
+// Whether to show extra user identity information
+$extrafields = get_extra_user_fields($context);
+$leftcols = 1 + count($extrafields);
// Function for quoting csv cell values
function csv_quote($value) {
// Check permissions
require_login($course);
-$context=get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('coursereport/completion:view', $context);
// Get group mode
$group,
$firstnamesort ? 'u.firstname ASC' : 'u.lastname ASC',
$csv ? 0 : COMPLETION_REPORT_PAGE,
- $csv ? 0 : $start
+ $csv ? 0 : $start,
+ $context
);
}
// Print criteria group names
print PHP_EOL.'<tr style="vertical-align: top">';
- print '<th scope="row" class="rowheader">'.get_string('criteriagroup', 'completion').'</th>';
+ echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
+ get_string('criteriagroup', 'completion') . '</th>';
$current_group = false;
$col_count = 0;
// Print aggregation methods
print PHP_EOL.'<tr style="vertical-align: top">';
- print '<th scope="row" class="rowheader">'.get_string('aggregationmethod', 'completion').'</th>';
+ echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
+ get_string('aggregationmethod', 'completion').'</th>';
$current_group = false;
$col_count = 0;
if (COMPLETION_REPORT_COL_TITLES) {
print PHP_EOL.'<tr>';
- print '<th scope="row" class="rowheader">'.get_string('criteria', 'completion').'</th>';
+ echo '<th scope="row" class="rowheader" colspan="' . $leftcols . '">' .
+ get_string('criteria', 'completion') . '</th>';
foreach ($criteria as $criterion) {
// Get criteria details
print '</th>';
- // Print user id number column
- if($idnumbers) {
- print '<th>'.get_string('idnumber').'</th>';
+ // Print user identity columns
+ foreach ($extrafields as $field) {
+ echo '<th scope="col" class="completion-identifyfield">' .
+ get_user_field_name($field) . '</th>';
}
///
} else {
- // TODO
- if($idnumbers) {
- print $sep;
- }
+ // The CSV file does not contain any headers
}
// User name
if($csv) {
print csv_quote(fullname($user));
- if($idnumbers) {
- print $sep.csv_quote($user->idnumber);
+ foreach ($extrafields as $field) {
+ echo $sep . csv_quote($user->{$field});
}
} else {
print PHP_EOL.'<tr id="user-'.$user->id.'">';
print '<th scope="row"><a href="'.$CFG->wwwroot.'/user/view.php?id='.
$user->id.'&course='.$course->id.'">'.fullname($user).'</a></th>';
- if($idnumbers) {
- print '<td>'.htmlspecialchars($user->idnumber).'</td>';
+ foreach ($extrafields as $field) {
+ echo '<td>' . s($user->{$field}) . '</td>';
}
}
if(!$course) {
print_error('invalidcourseid');
}
+$context = context_course::instance($course->id);
// Sort (default lastname, optionally firstname)
$sort = optional_param('sort','',PARAM_ALPHA);
$silast = optional_param('silast', 'all', PARAM_ALPHA);
$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
-// to be a generic option somewhere.
-$idnumbers = $CFG->grade_report_showuseridnumber;
+// Whether to show extra user identity information
+$extrafields = get_extra_user_fields($context);
+$leftcols = 1 + count($extrafields);
function csv_quote($value) {
global $excel;
require_login($course);
// Check basic permission
-$context=get_context_instance(CONTEXT_COURSE,$course->id);
require_capability('coursereport/progress:view',$context);
// Get group mode
$group,
$firstnamesort ? 'u.firstname ASC' : 'u.lastname ASC',
$csv ? 0 : COMPLETION_REPORT_PAGE,
- $csv ? 0 : $start
+ $csv ? 0 : $start,
+ $context
);
}
}
print '</th>';
- if($idnumbers) {
- print '<th>'.get_string('idnumber').'</th>';
+ // Print user identity columns
+ foreach ($extrafields as $field) {
+ echo '<th scope="col" class="completion-identifyfield">' .
+ get_user_field_name($field) . '</th>';
}
-
} else {
- if($idnumbers) {
- print $sep;
+ foreach ($extrafields as $field) {
+ echo $sep . csv_quote(get_user_field_name($field));
}
}
// User name
if($csv) {
print csv_quote(fullname($user));
- if($idnumbers) {
- print $sep.csv_quote($user->idnumber);
+ foreach ($extrafields as $field) {
+ echo $sep . csv_quote($user->{$field});
}
} else {
print '<tr><th scope="row"><a href="'.$CFG->wwwroot.'/user/view.php?id='.
$user->id.'&course='.$course->id.'">'.fullname($user).'</a></th>';
- if($idnumbers) {
- print '<td>'.htmlspecialchars($user->idnumber).'</td>';
+ foreach ($extrafields as $field) {
+ echo '<td>' . s($user->{$field}) . '</td>';
}
}
* @param string $sort Order by clause (optional)
* @param integer $limitfrom Result start (optional)
* @param integer $limitnum Result max size (optional)
+ * @param context $extracontext If set, includes extra user information fields
+ * as appropriate to display for current user in this context
* @return array
*/
function get_tracked_users($where = '', $where_params = array(), $groupid = 0,
- $sort = '', $limitfrom = '', $limitnum = '') {
+ $sort = '', $limitfrom = '', $limitnum = '', context $extracontext = null) {
global $DB;
u.lastname,
u.idnumber
";
+ if ($extracontext) {
+ $sql .= get_extra_user_fields_sql($extracontext, 'u', '', array('idnumber'));
+ }
$sql .= $tracked->sql;
* @param int $groupid Group ID or 0 (default)/false for all groups
* @param int $pagesize Number of users to actually return (optional)
* @param int $start User to start at if paging (optional)
+ * @param context $extracontext If set, includes extra user information fields
+ * as appropriate to display for current user in this context
* @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($where = '', $where_params = array(), $groupid = 0,
- $sort = '', $pagesize = '', $start = '') {
+ $sort = '', $pagesize = '', $start = '', context $extracontext = null) {
global $CFG, $DB;
// Get list of applicable users
- $users = $this->get_tracked_users($where, $where_params, $groupid, $sort, $start, $pagesize);
+ $users = $this->get_tracked_users($where, $where_params, $groupid, $sort,
+ $start, $pagesize, $extracontext);
// Get progress information for these users in groups of 1, 000 (if needed)
// to avoid making the SQL IN too long
*/
.completion-expired {background:#FFDDDD;}
.completion-expected {font-size:0.75em;}
-.completion-sortchoice {font-size:0.75em;vertical-align:bottom;}
+.completion-sortchoice,
+.completion-identifyfield {font-size:0.75em;vertical-align:bottom;}
.completion-progresscell {text-align:right;}
.completion-expired .completion-expected {font-weight:bold;}
#page-course-report-progress-index th,