Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
titleImplementation Completed!

See the Animations on this implementation. After seeing the animations, here's a demo server you can play with.


The Moodle Tool Adapter is a tool adapter that permits Moodle tools to be used natively (as LAMS Tools) within a LAMS-Moodle integrated environment.


  1. Authoring and Preview
  2. Enactment/Runtime and Monitoring
  3. Using Moodle Tool outputs for Branching
  4. Achieving interoperability using Export and Import


You can use the demo server to try this implementation of the Moodle Forum in LAMS. We are looking forward for comments and suggestions in the LAMS Community Tech Forums. Please let us know what you think!


titleImportant Integration Principle

The main principle we follow is to avoid any modification to existing code whenever possible and extend the current method or functions instead.

Modifications to Moodle

We added a new column to the \course_modules_ table so it distinguishes between LAMS course module instance (_is_lams). The is_lams is a integer value that can have only a 0 or 1 value. If 0, it means that it isn't a LAMS instance. We use this field to filter instances of course modules in the course page (as you can see below).

This file is copy of modedit.php where we add only a few lines (this is an actual diff):


No need for course footer, so we remove this too.

That's all!

As we have added a new column to the course_modules, when a Moodle Course page is displayed, we don't want to show instances of Moodle that we have created for LAMS (as these instances might be used at authoring stage). Therefore, we add a new constraint to the function get_course_mods($courseid) function to show only course modules that aren't used in LAMS.


Modifications to Moodle Forum Tool

Just as we did with the course_modules table, we add an is_lams column to the forum table. Default value is 0.

No Format
\#$forums = get_records('forum', 'course', $course->id);     $forums = get_records_select('forum', "course=$course->id and is_lams=0");

We replaced the get_records function for a get_records_select instead and add the is_lams=0 so it only shows forums that weren't created for LAMS.

This file is also a copy of the original moodle/forum/mod_form.php which we remove a lot of features that]. The only additions/modifications are:


Instead of showing the standard Save options, we only show one Save button.

In order to make the Moodle Forum Tool "workflow aware", we need to introduce a "Next Activity" button so after the students have posted their messages they can continue to other activities in the sequence. However, we only show this button if this is a Moodle Forum instance used in LAMS (is_lams = 1).

As part of adding a new Moodle Tool into LAMS, we need to add a few functions to the Moodle Forum tool so they can be use from LAMS. These functions are based on existing Moodle Forum functions.


Exports a Forum object into a file and sends it to LAMS so it can export it with a LAMS sequence (see Export and Import Animation)

No Format
 * LAMS Function
 * Deserializes a serialized Moodle forum, and creates a new instance of it
function forum_import_instance($filepath, $userid, $courseid, $sectionid) {
    // file contents contains serialized forum object
    $filestr = file_get_contents($filepath);
    $forum = $all[0];
    $discussions= $all[1];

    // import this forum into a new course
    $forum->course = $courseid;

    // escape text columns for saving into database
    $forum->name = addslashes($forum->name);
    $forum->intro = addslashes($forum->intro);

    if ( ! $forum->id = insert_record('forum', $forum) ) {
        return 0; 

    $module = get_record('modules', 'name', 'forum');
    $section = get_course_section($sectionid, $courseid);

    $cm->course = $courseid;
    $cm->module = $module->id;
    $cm->instance = $forum->id;
    $cm->added = time();
    $cm->section = $section->id;
    $cm->is_lams = 1; 
    $cm->id = insert_record('course_modules', $cm);
    //add discussions and their posts
    	  add_discussions_instance($discussions, $forum->id,$courseid);
    return $cm->id;

This does the import of a LAMS sequence that contains a Moodle Forum. (see Export and Import Animation).

No Format
 * LAMS Function
 * Return a statistic for a given user in this Moodle forum for use in branching
function forum_get_tool_output($id, $outputname, $userid) {
    $cm = get_record('course_modules', 'id', $id);
    if ($cm) {
        $posts = forum_get_user_posts($cm->instance, $userid);
        switch ($outputname) {
            case ("learner.number.of.words"):
                $numwords = 0;
                foreach ($posts as $postid=>$post) {
                    $numwords += count(explode(' ', $post->message));
                return $numwords;
            case ("learner.number.of.posts"):
                return count($posts);
    return 0;


LAMS Integration Interface

Completed, but not documented yet. Coming soon...


The code is available in our CVS server. If you want to download the code, here are the CVS details. As of 22/08/2008, this code is consider in Beta. Further testing is required.