list($esql, $params) = get_enrolled_sql($context, '', $currentgroup, true);
list($sort, $sortparams) = users_order_by_sql('u');
+ $extrafields = get_extra_user_fields($context);
+
$params['a1lessonid'] = $lesson->id;
$params['b1lessonid'] = $lesson->id;
$params['c1lessonid'] = $lesson->id;
- $ufields = user_picture::fields('u');
+ $ufields = user_picture::fields('u', $extrafields);
$sql = "SELECT DISTINCT $ufields
FROM {user} u
JOIN (
$table = new html_table();
+ $headers = [get_string('name')];
+
+ foreach ($extrafields as $field) {
+ $headers[] = get_user_field_name($field);
+ }
+
+ $headers [] = get_string('attempts', 'lesson');
+
// Set up the table object.
if ($data->lessonscored) {
- $table->head = array(get_string('name'), get_string('attempts', 'lesson'), get_string('highscore', 'lesson'));
- } else {
- $table->head = array(get_string('name'), get_string('attempts', 'lesson'));
+ $headers [] = get_string('highscore', 'lesson');
+ }
+
+ $colcount = count($headers);
+
+ $table->head = $headers;
+
+ $table->align = [];
+ $table->align = array_pad($table->align, $colcount, 'center');
+ $table->align[$colcount - 1] = 'left';
+
+ if ($data->lessonscored) {
+ $table->align[$colcount - 2] = 'left';
}
- $table->align = array('center', 'left', 'left');
- $table->wrap = array('nowrap', 'nowrap', 'nowrap');
+
+ $table->wrap = [];
+ $table->wrap = array_pad($table->wrap, $colcount, 'nowrap');
+
$table->attributes['class'] = 'standardtable generaltable';
- $table->size = array(null, '70%', null);
// print out the $studentdata array
// going through each student that has attempted the lesson, so, each student should have something to be displayed
}
// get line breaks in after each attempt
$attempts = implode("<br />\n", $attempts);
+ $row = [$studentname];
+
+ foreach ($extrafields as $field) {
+ $row[] = $student->$field;
+ }
+
+ $row[] = $attempts;
if ($data->lessonscored) {
// Add the grade if the lesson is graded.
- $table->data[] = array($studentname, $attempts, $bestgrade . "%");
- } else {
- // This lesson does not have a grade.
- $table->data[] = array($studentname, $attempts);
+ $row[] = $bestgrade."%";
}
+
+ $table->data[] = $row;
+
// Add the student data.
$dataforstudent->id = $student->id;
$dataforstudent->fullname = $studentname;