Permalink
Browse files

MDL-26647 (5) Support showuseridentity on course and activity complet…

…ion reports
  • Loading branch information...
1 parent 43aa295 commit 24e14bc7a60eee1bdfbec97a7a7322d58a42ea9c @sammarshallou sammarshallou committed Apr 13, 2011
Showing with 50 additions and 38 deletions.
  1. +21 −18 course/report/completion/index.php
  2. +16 −16 course/report/progress/index.php
  3. +11 −3 lib/completionlib.php
  4. +2 −1 theme/base/style/core.css
@@ -45,6 +45,7 @@
$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);
@@ -59,8 +60,9 @@
$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) {
@@ -77,7 +79,6 @@ 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
@@ -221,7 +222,8 @@ function csv_quote($value) {
$group,
$firstnamesort ? 'u.firstname ASC' : 'u.lastname ASC',
$csv ? 0 : COMPLETION_REPORT_PAGE,
- $csv ? 0 : $start
+ $csv ? 0 : $start,
+ $context
);
}
@@ -337,7 +339,8 @@ function csv_quote($value) {
// 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;
@@ -371,7 +374,8 @@ function csv_quote($value) {
// 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;
@@ -430,7 +434,8 @@ function csv_quote($value) {
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
@@ -468,9 +473,10 @@ function csv_quote($value) {
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>';
}
///
@@ -539,10 +545,7 @@ function csv_quote($value) {
} else {
- // TODO
- if($idnumbers) {
- print $sep;
- }
+ // The CSV file does not contain any headers
}
@@ -554,16 +557,16 @@ function csv_quote($value) {
// 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.'&amp;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>';
}
}
@@ -10,6 +10,7 @@
if(!$course) {
print_error('invalidcourseid');
}
+$context = context_course::instance($course->id);
// Sort (default lastname, optionally firstname)
$sort = optional_param('sort','',PARAM_ALPHA);
@@ -26,11 +27,9 @@
$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;
@@ -58,7 +57,6 @@ function csv_quote($value) {
require_login($course);
// Check basic permission
-$context=get_context_instance(CONTEXT_COURSE,$course->id);
require_capability('coursereport/progress:view',$context);
// Get group mode
@@ -103,7 +101,8 @@ function csv_quote($value) {
$group,
$firstnamesort ? 'u.firstname ASC' : 'u.lastname ASC',
$csv ? 0 : COMPLETION_REPORT_PAGE,
- $csv ? 0 : $start
+ $csv ? 0 : $start,
+ $context
);
}
@@ -277,13 +276,14 @@ function csv_quote($value) {
}
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));
}
}
@@ -328,14 +328,14 @@ function csv_quote($value) {
// 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.'&amp;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>';
}
}
View
@@ -1057,10 +1057,12 @@ function get_num_tracked_users($where = '', $where_params = array(), $groupid =
* @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;
@@ -1074,6 +1076,9 @@ function get_tracked_users($where = '', $where_params = array(), $groupid = 0,
u.lastname,
u.idnumber
";
+ if ($extracontext) {
+ $sql .= get_extra_user_fields_sql($extracontext, 'u', '', array('idnumber'));
+ }
$sql .= $tracked->sql;
@@ -1190,16 +1195,19 @@ function generate_tracked_user_sql($groupid = 0) {
* @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
@@ -361,7 +361,8 @@ table.mod_index {width:100%;}
*/
.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,

0 comments on commit 24e14bc

Please sign in to comment.