event monitor etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
event monitor etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

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';

$type="\\core\\event\\course_module_created";
$content="Course content has been added.
";
$content2="Link : {rulename}
Description: {description}
Event Name: {eventname}
";

$type=mysql_real_escape_string($type);
$content=mysql_real_escape_string($content);
$content2=mysql_real_escape_string($content2);

mysql_select_db('moodle');


//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')";
mysql_query($query);
    }
mysql_close($link);

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

İzleyiciler