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');By changing the $type variable you can add any kind of event rules to the moodle.
//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);
?>