← blogs.sussex.ac.uk

Moodle history/extended memory issue – cache with $USER->display & course_display

The problem :

When a user in moodle chooses to view a single section of a site, they are shown the section as expected.

Moodle stores which section you are viewing, so that when you go to a resource or activity and then return to the site, you are still viewing the section you last looked at.

This can be useful for users within the context of a single session. However, we found that even if a user logs out, changes computer, or returns to a site after several days they are still shown the section they last looked at.

Imagine if once you loged in sites like amazon, ebay, facebook or youtube and went into a view, it showed you the content you last looked at. This never happens. So the fact that it happens in moodle is perhaps understandably confusing for our users.

Some of our students report they are unable to see resources tutors inform them have been added, beacause moodle is only showing them a single section of a site when they login in. Other report no longer being able to see resources they have previously accessed, simply because moodle is showing them only one section – the section in the course moodle remembers in the db from when they last visited the course.

Our solution :

The behaviour users expect is when they visit a site, to be shown the landing page of a course/site. We need to clear moodle’s ‘extended memory’ to achieve this.

Clearing this memory when a user logs out would seem to be the natural approach. Realistically most users do not press the logout button, but simply shut down or close the browser. Triggering events on browser close isn’t an easy task.

So we approached it by clearing this data on login, which achieves the same effect.

There are two separate places where moodle looks to see which section the user was previously viewing in a site.

  • In the database – table called prefix_course_display
  • In the $user->display cookie array, keyed by course id

Both of these needed to be cleared to give moodle a more standard web pattern of behaviour.

Our code :

In login/index.php

Moodle1.9

// clear data on users last section visited in sites / courses
if (record_exists('course_display', 'userid', $user->id) ) {
delete_records('course_display', 'userid', $user->id);
foreach($user->display as $key => $value) {
$user->display[$key] = '';
}
}

Moodle2

if ($DB->record_exists('course_display', array('userid'=> $user->id) ) ) {
$DB->delete_records('course_display', array('userid' => $user->id) );
foreach($user->display as $key => $value) {
$user->display[$key] = '';
}
}

This might not be the best or only solution, so we would be grateful to hear from others who found the same problem, and how they dealt with it.

Again – the very helpful DB layer 2.0 pages in moodle helped us upgrade our 1.9 code to moodle2.

We implemented this fix in Jan 2010, and so far have seen a complete drop in the number of users contacting support about not being able to see a resource or section.

Post a Comment

Your email is never shared. Required fields are marked *

*
*