Date Last Modified

Re: Date Last Modified

by Cristian Martin Nieto -
Number of replies: 0

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.