Skip to content

Commit

Permalink
MDL-32275 enrol: Last site access column now shows last course access
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Cooper committed Sep 26, 2014
1 parent 272fec3 commit e89682d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
17 changes: 12 additions & 5 deletions enrol/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1099,19 +1099,26 @@ public function get_users_for_display(course_enrolment_manager $manager, $sort,
*/
private function prepare_user_for_display($user, $extrafields, $now) {
$details = array(
'userid' => $user->id,
'courseid' => $this->get_course()->id,
'picture' => new user_picture($user),
'firstname' => fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())),
'lastseen' => get_string('never'),
'userid' => $user->id,
'courseid' => $this->get_course()->id,
'picture' => new user_picture($user),
'firstname' => fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())),
'lastseen' => get_string('never'),
'lastcourseaccess' => get_string('never'),
);
foreach ($extrafields as $field) {
$details[$field] = $user->{$field};
}

// Last time user has accessed the site.
if ($user->lastaccess) {
$details['lastseen'] = format_time($now - $user->lastaccess);
}

// Last time user has accessed the course.
if ($user->lastseen) {
$details['lastcourseaccess'] = format_time($now - $user->lastseen);
}
return $details;
}

Expand Down
4 changes: 2 additions & 2 deletions enrol/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@

$fields = array(
'userdetails' => $userdetails,
'lastseen' => get_string('lastaccess'),
'lastcourseaccess' => get_string('lastcourseaccess'),
'role' => get_string('roles', 'role'),
'group' => get_string('groups', 'group'),
'enrol' => get_string('enrolmentinstances', 'enrol')
Expand All @@ -196,7 +196,7 @@
if (!has_capability('moodle/course:viewhiddenuserfields', $context)) {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
if (isset($hiddenfields['lastaccess'])) {
unset($fields['lastseen']);
unset($fields['lastcourseaccess']);
}
if (isset($hiddenfields['groups'])) {
unset($fields['group']);
Expand Down
3 changes: 3 additions & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@
$string['firstaccess'] = 'First access';
$string['firstname'] = 'First name';
$string['firstnamephonetic'] = 'First name - phonetic';
$string['firstsiteaccess'] = 'First access to site';
$string['firsttime'] = 'Is this your first time here?';
$string['folder'] = 'Folder';
$string['folderclosed'] = 'Closed folder';
Expand Down Expand Up @@ -1007,12 +1008,14 @@
$string['languagegood'] = 'This language pack is up-to-date! :-)';
$string['last'] = 'Last';
$string['lastaccess'] = 'Last access';
$string['lastcourseaccess'] = 'Last access to course';
$string['lastedited'] = 'Last edited';
$string['lastip'] = 'Last IP address';
$string['lastlogin'] = 'Last login';
$string['lastmodified'] = 'Last modified';
$string['lastname'] = 'Surname';
$string['lastnamephonetic'] = 'Surname - phonetic';
$string['lastsiteaccess'] = 'Last access to site';
$string['lastyear'] = 'Last year';
$string['latestlanguagepack'] = 'Check for latest language pack on moodle.org';
$string['layouttable'] = 'Layout table';
Expand Down
11 changes: 8 additions & 3 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,12 @@
}
if (!isset($hiddenfields['lastaccess'])) {
$tablecolumns[] = 'lastaccess';
$tableheaders[] = get_string('lastaccess');
if ($course->id == SITEID) {
// Exception case for viewing participants on site home.
$tableheaders[] = get_string('lastsiteaccess');
} else {
$tableheaders[] = get_string('lastcourseaccess');
}
}

if ($bulkoperations && $mode === MODE_USERDETAILS) {
Expand All @@ -376,8 +381,8 @@
$table->define_headers($tableheaders);
$table->define_baseurl($baseurl->out());

if (!isset($hiddenfields['lastaccess'])) {
$table->sortable(true, 'lastaccess', SORT_DESC);
if (!isset($hiddenfields['lastcourseaccess'])) {
$table->sortable(true, 'lastcourseaccess', SORT_DESC);
} else {
$table->sortable(true, 'firstname', SORT_ASC);
}
Expand Down
4 changes: 2 additions & 2 deletions user/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@
} else {
$datestring = get_string("never");
}
echo html_writer::tag('dt', get_string('firstaccess'));
echo html_writer::tag('dt', get_string('firstsiteaccess'));
echo html_writer::tag('dd', $datestring);
}
if (!isset($hiddenfields['lastaccess'])) {
Expand All @@ -416,7 +416,7 @@
} else {
$datestring = get_string("never");
}
echo html_writer::tag('dt', get_string('lastaccess'));
echo html_writer::tag('dt', get_string('lastsiteaccess'));
echo html_writer::tag('dd', $datestring);
}

Expand Down
2 changes: 1 addition & 1 deletion user/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
} else {
$datestring = get_string("never");
}
echo html_writer::tag('dt', get_string('lastaccess'));
echo html_writer::tag('dt', get_string('lastcourseaccess'));
echo html_writer::tag('dd', $datestring);
}

Expand Down

0 comments on commit e89682d

Please sign in to comment.