Date Last Modified

Date Last Modified

by Donald Robertson -
Number of replies: 3

Hi,

Apologies if this has already been answered: I've just starting tinkering with Moodle development...

Is it possible to create a plugin which would display the date/time a course was last edited by a teacher or course creator?  Does Moodle store a record of that information?  Is there already a way to access this information via the Moodle admin interface without writing new code?

We have a lot of courses and struggle to keep track of when they were last updated so we currently just enter the date manually in brackets after the title.  I'm looking for a way to automate this via a plugin.

Thanks,

Donald Robertson

Average of ratings: -
In reply to Donald Robertson

Re: Date Last Modified

by ryan sanders -

just thinking outloud. 

recent activity block

site admin menu -> reports

i wonder if "notes" or "sticky notes" might work? i doubt that would be good enough....

------------------------

are you asking more of a "front end" tied directly to each module (resource / activity) of when it was last edited (besides a student going through it). example.... 

html yada yada title 2015-01-02 edit by X person

database joo joo title 2014-05-23 edit by Y person

-------------------

not sure if i would want info displayed to students, but if i clicked "turn on editing" and info displayed! eewww that might be handy! i would take the suffering of server usage for some tracker like functionality!

-------------------

wonder if you could do some "javascript" to look for "turn on editing", and then check for data/time stamp in a given "element id" for the title. and adjust time stamp that way. no core files change. just a little javascript sniplet.  meh students would still see date/time stamp. but *shrugs*

In reply to ryan sanders

Re: Date Last Modified

by Donald Robertson -

Thanks!

Maybe I'm missing it but I can't see information that shows clearly-enough when a course was last edited in the recent activity block or the reports available.

I want it to be visible to admins when a course was last edited.  So maybe in smallprint in the footer of the main course page, for example.  Maybe like the footer messages you see in blogs like Wordpress.  I've noticed that in Moodle HTML pages it says in the footer:

"Last modified: Sunday, 30 November 2014, 9:55 PM"

So students can already see that one, I think.  Basically, I'd like to see something like that in the footer of the main course page, or in a block, to show when the course as a whole (i.e., anything in it) was last modified.

Yeah, maybe it could be done with JS but that seems a bit of a fudge.  The HTML blocks obviously store information on when they were last edited so if that's true of all activities then maybe a plugin could search through that data and output the most recent "date modified" it finds within a course.

Best,

Donald

In reply to Donald Robertson

Re: Date Last Modified

by Cristian Martin Nieto -

Hello Donald,

The way I addressed this issue was to create a new course format plugin. Since the format I use the most is the topics format, I used that as a base.

Inside of renderer.php file I copied these 2 functions from /course/format/renderer.php:

public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused)
public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {


These functions manage the way your course is being printed, so I added this line that will create a custom tag:

echo html_writer::tag('span', format_topics_custom_get_last_modified_info($course->id), array('class' => 'last-modified'));


The last-modified class is the class I am going to use in styles.css to style it, and the format_topics_custom_get_last_modified_info function looks like this in lib.php:

function format_topics_custom_get_last_modified_info ($courseid) {
    global $DB;
    
    $info = $DB->get_record_sql('SELECT u.id, u.firstname, u.lastname, log.timecreated FROM {logstore_standard_log} log
                                INNER JOIN {user} u ON log.userid = u.id
                                WHERE log.action = "updated" AND log.edulevel = 1 AND log.courseid = ?
                                ORDER BY log.timecreated DESC
                                LIMIT 0,1', array($courseid));
    
    return 'Last update on ' . date("F j, Y, g:i a", $info->timecreated) . ' (' . $info->firstname . ' '. $info->lastname . ')';
}


I think these are the only bits of code that you should need, from there you can adapt them to your needs depending on how you are using the system and how you customised it.