Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

Demo

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!

...

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
titlemoodle/mod/forum/lib.php
/**
 * 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);
  
    $all=unserialize($filestr);
    $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
    if($discussions!=''){
    	  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
titlemoodle/mod/forum/lib.php
/**
 * 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;
}

...