30 Ekim 2015 Cuma

Moodle Adding Event Monitor Rules in Bulk to all of the Courses

Event Monitor Rules feature is a new and a missing feature which has arrived to moodle in version 2.8. This feature help students to be informed by email if a course material added updated or deleted etc. So they do not need to login to check whether a content has been added to the course or not. It also informs teachers and admins about  a specific event occurred (a course has been added, a content has been viewed etc.).

But if you are administering a moodle with 150+ courses it is real heavy duty task to add rules one by one to every course created in moodle.

So with the following php code you can add a rule to the every course created in moodle.

$link = mysql_connect('moodle_host_name_or_ip', 'database_username', 'database_password');
//if connection is not successful you will see text error
if (!$link) {
             die('Could not connect: ' . mysql_error());
//if connection is successfuly you will see message bellow
echo 'Connected successfully\n';

$content="Course content has been added.
$content2="Link : {rulename}
Description: {description}
Event Name: {eventname}



//This query finds the courses in moodle
$query_id= "select id from mdl_course";
$result_id = mysql_query($query_id);
echo $result_id;
while($row = mysql_fetch_row($result_id)) {
    echo $row[0];
    echo "\n";
//This below query adds the event monitor rules into he courses.
$query="INSERT INTO mdl_tool_monitor_rules (userid,courseid,name,plugin,eventname,description,
descriptionformat,frequency,timewindow,template,templateformat,timecreated,timemodified) VALUES('2','".$row[0]."',
'Course Content has been added','core','".$type."','".$content."','1','1','60','".$content2."','1','1445596840','1445596840')";

By changing the $type variable you can add any kind of event rules to the moodle.

Hiç yorum yok:

Yorum Gönder