Adding a bim2 activity – development progress

Okay, so after fixing up the naming problems with bim2 etc, it’s time to actually get the code going.

To do

A list of things to do once I get back online

  • DONE mod_form.php needs to be modified to use the new editor element for Moodle 2.0
    Actually, this looks to have been created by a typo or other problem within the bim2 mod_form.php. It is now working.
  • DONE Check the location/process for help files.
    Seems like in Moodle 2.0, help files are being converted to strings and reside in the language file.
  • DONE Update lib.php:add_instance to call grade_item_update
  • See what Rolley can do about making the bim icon transparent.


When someone chooses to add a bim2 activity into a Moodle course, the first thing they see is the form provided by mod_form.php. I’m hoping/wondering if this can essentially stay the same as that used in bim. So let’s copy that across. No, empty page.

Ahh, I have to get the database for bim2 up and going. Seems the transition to bimTwo as the internal Moodle name for bim2 doesn’t work entirely. The table name regular expression check doesn’t like table names with uppercase characters, so for the tables it will have to be bimtwo

So, the tables are created now. Does the mod_form.php work? No still empty. Something not working here, solving this should be interesting as I’m currently without Internet access. How about commenting out the entire bim2 contents from mod_form.php. Seems the problem is a bit earlier.

~/course/modedit.php is where this is run from, let’s have a look there. Let’s stick some debugging stuff in and find out where we get up to. Or, alternatively you could try running the mod_form.php file through PHP from the commmand line and discover where the syntax error is in the file. i.e.

david-joness-macbook-pro-2:~ david$ php mod_form.php

Parse error: syntax error, unexpected ',' in mod_form.php on line 89

This is why, on one-hand, it would be good to be developing in PHP/Moodle more often. I wouldn’t be making so many newbie misassumptions and mistakes.

Ahh, nice, I think. Fixed up the syntax error and no get this error in the browser

Coding error detected, it must be fixed by a programmer: MFORMS: Coding error, text formats are handled only by new editor element.

My immediate assumption here is that this is being caused by the original bim code including some Moodle 1.x specific code around the use of the HTML editor and its inclusion in forms. I’m offline so can’t check the syntax for this, will solve for now by commenting out the offending elements.

Next step is to update the get_string data. This is how Moodle separates text to be displayed on a web page into separate language files. I haven’t updated the bim2 english language file to include the labels used in mod_form.php.

Somewhat related to this are the help files, most of these should be able to come over, at least at the start. Ahh, appears the naming/directory structure may be a little different (or I’ve made a simple tranlsation mistake)

So, the form is basically working (minus the HTML editor field). Can I submit, well no, that’s the next step.


The add_instance function in ~/mod/bimTwo/lib.php defines what should happen when the mod_form.php is submitted. Currently, it is empty/boilerplate. Will have to update it. This is again getting into the area of “Moodle 2 conversion problems”. As the database API is one place I believe that has undergone some change.

Actually, the NEWMODULE stuff looks like it might already have been updated. But I’m getting the error

Coding error detected, it must be fixed by a programmer: moodle_database::insert_record_raw() no fields found.

This is happening in this statement

$DB->insert_record('bimTwo', $bimTwo);

$bimTwo has the contents from the form, and it all appears good. So, some problem in the insert_record function. Ahh, wonder if this is where the database naming problem crops up, the ‘bimTwo’ that is the first parameter, should probably be without the upper case T

Yep, that appears to have fixed up the original error, now I’m getting Incorrect function. Ahh, wasn’t returning the id. Done. Now a problem Error reading from database I think that may well be another table naming problem.


The error is cropping up when this file is being run. Yep, almost certainly the problem with the different names. Am going to have to revert back to bimtwo as the name for everything.

Yep, that’s fixed it. It is now possible to add a bim2 activity (not that it will do anything useful) to Moodle 2. As you can see in the following image.

And the edit button basically works as well, in that it shows the mod_form.php output yet again and allows changes.

Ahh, but the information about the BIM settings is not being saved from the form to the database. Something is missing. Mmmm, most of the bim specific fields are missing from the basic bimtwo table, have to update that in xmldb. The browser form memory remembers the fields, but it appears that I didn’t hit the magic ‘Save’ in xmldb

Yep, that did it.

Evidence of bim2 activity in Moodle 2

To do

Have a lot of clearing up to do when I can get back online.

The next major step, however, is to start implementing the main user interface of bim2. i.e. the process and output that staff and students see when they actually try to use the bim2 activity, rather than simply create it.

It is here where I’m hoping that I will be making the largest changes between bim2 and bim. It’s also where I’m hoping the changes will be worthwhile and not introduce new and interesting problems.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s