Moodle Grid Format doesn’t render images

If you are using the Moodle course grid format, then you might find it doesn’t render images and instead creates URLs that have @@pluginfile@@ in them. This is a sign that these URLs have not been through the lib/filelib.php file_rewrite_pluginfile_urls() function.

To fix this, you’ll need to edit the file course/format/grid/format.php

Find this section:

if (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible) { ... }

Replace this:

echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);

With this:

$summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $context->id, 'course', 'section', $thissection->id);
echo $summarytext;

Another solution to this would be to use the format_summary_text() function in course/format/renderer.php which basically takes the step above, but I think this would need a bigger code change. However it might be the correct way to fix this issue long term.

Linux Date/Timestamp

I often find myself needing to append a date (and sometimes a time stamp) to files. 

The following will generate the current date in the format YYYYMMDD which is the most suitable for sorting files.

$ date +%Y%m%d

Example output is “20120528” or Year = 2012, Month=05 (May) and day = 28.

Similarly the following will output the current time in the format HH24MMSS (24 hour time)

$date +%H%M%S

Example output is “193347” or Hour = 19, Minute = 33 and second = 47 (19:33.47). 

The two can be combined:

$date +%Y%m%d-%H%M%S

Example output is 20120528-193347. Note the separation of the date and time with a dash.

You can use these commands in your shell scripts. For example, this will create an empty test file called “Test.txt.20120528-193347”:

$ touch Test.txt.`date +%Y%m%d-%H%M%S`

As you can see, quite handy for organising files.