Adding a general discussion to a course upon creation

Adding a general discussion to a course upon creation

by Deleted user -
Number of replies: 0

Dear All,

I am trying to add code to lib/blocklib.php so that whenever I create a course a general discussion forum is created alongside the news forum. I added the following code and from a little experimentation I believe the problem is that the course_module entry is not picked up correctly, but I am completely confused and do not know how to do it. Any pointers?

include_once("$CFG->dirroot/course/lib.php");
    echo "Now creating a new forum for course:\t", $course->id;
if (! $module = $DB->get_record("modules", array("name" => "forum"))) {
        echo $OUTPUT->notification("Could not find forum module!!");
        return false;
    }    
    $course_forum = new stdClass();
$course_forum->section = 0;
$course_forum->module = $module->id;
$course_forum->section = 0;
$course_forum-> name = 'General Discussion Forum';
$course_forum-> intro = 'General Discussion Forum';
$course_forum->type = 'general';
$course_forum->forcesubscribe = 0;
$course_forum->trackingtype = 1;
$course_forum->maxbytes = 512000;
$course_forum->maxattachments = 9;
$course_forum->blockperiod = 0;
$course_forum->introformat = 1;
$course_forum->course = $course->id;
$course_forum->blockafter = 0;
$course_forum->warnafter = 0;
$course_forum->assessed = 0;
$course_forum->assesstimestart = 0;
$course_forum->assesstimefinish = 0;
$course_forum->groupmode = 0;
$course_forum->groupingid = 0;
$course_forum->mform_show_advanced_last = 1;
$course_forum->visible = 1;
$course_forum->availablefrom = 0;

$course_forum->availableuntil = 0;
$course_forum->conditiongraderepeats = 1;
$course_forum->timemodified = time();
 $course_forum->id = $DB->insert_record('forum',$course_forum);
$course_forum->coursemodule = get_coursemodule_from_id('forum',$course_forum->id,$course->id);
course_add_cm_to_section($course, $course_forum->coursemodule, 0);

Regards,

George

P.S: I know I can easily add it later on, I just want to get the code working.

 

 

Average of ratings: -