Block Building for Moodle 2

This year, instead of hacking the Moodle core to death we have decided to stick with core Moodle code, and this time we have put all our custom pages in their own folder.
I am in the process of converting many custom code projects into blocks and mods. An it’s surprisingly easy with Moodle 2.

Today I built a simple course header block that displays the course title with a nicely rounded CSS background image.
Previously we used to draw course headers in Photoshop but now we don’t need to.
And because we can place blocks in the centre of our theme the headers sit very neatly at the top of the course content above the resources.

At present it’s limited to 1 image but the plan is to develop it further whereby the tutor can select from a variety of images when in editing mode.
For example, there may be an image for construction courses, one for hairdressing courses etc… Plus a few generic ones.

This saves hours of time – no more Photoshop!

The next mod we need to build is similar to a label but instead creates a pre-drawn banner and associated link to a child course. At present we draw images, add them to a label and hyperlink them to a hidden child course. Painful and time consuming!

However, time is always the issue. And we are fully stretched with a new term just a few days away so finding time to code is harder than the code itself!
It will be non stop tech support for the next month and then we will see how we go!

And the senior powers that be require a Moodle reporting engine that links to our MIS system! I’d rather build the fun stuff but need to keep the bosses happy!

Bug fixing week (Moodle 2)

This week I finally found some time to sit in front of my computer and address some of the niggly little glitches that have arisen since our Moodle 2 upgrade.

One of which was the sending of emails via the cron. For some unknown reason, Moodle 2 could not initiate the send mail function. After several hours debugging and trying various things I decided to put the path to the sendmail server directly into Moodle, as opposed to using the default PHP path. And sure enough it worked! Even though the paths are exactly the same and worked prior to the upgrade, this was the only way I could get around it.

The next problem I had was with external Database enrolments via ODBC . For some reason, our Moodle 2.0 installation was refusing to run the queries even though I could communicate directly with the external database. Eventually, after searching through countless PHP pages I decided to drop ODBC in favour of FreeTDS. This worked like a charm.

Lastly, our cron was falling over when trying to run the course completion function. This was due to a mismatch in database collations. For some reason, 3 of our tables were set to utf8_general_ci, instead of utf_unicode_ci. I changed these tables to unicode and the cron completed this action.

Then I encountered another problem. Again cron related Playtech Casinos. The process kept on terminating whilst completing meta enrol enrolments. This happened everytime and just by chance I happened to time how long the process would last until it terminated. It was exactly 60 seconds. So to fix this I changed the timeout in php.ini to a much longer time limit of 300 seconds and now the cron completes perfectly.

It is now the end of the week and although the above fixes are more work arounds as opposed to actual core fixes at least things are working again. I have submitted some of my findings to the Moodle Tracker and hopefully some of these issues will be resolved in future releases.

I finished the week by installing the Drag and Drop file uplaoder block by the brilliant Davo Smith. This is by far my favourite block of all time. For those that are unfamiliar with it check out: http://moodle.org/mod/forum/discuss.php?d=181988

The only hack I had to make was to make the block sticky on all courses. As it’s a course block its not possible to make it sticky in Moodle 2.0 on all course pages by default.

To do this find the line:

function applicable_formats() {
return array('course' => true);
}

And change to:

function applicable_formats() {
return array('all' => true);
}

Now you can add the block to the frontpage and set it to appear on all pages.
Once my workload settles down I’m looking forward to coding and developing again.