-
Notifications
You must be signed in to change notification settings - Fork 1
Example Extension
philcali edited this page Dec 12, 2011
·
3 revisions
For example's sake, I'm going to create a block that sends a welcome message to a student that enlists in the course for the very first time.
The only two areas that will be highlighted for UES are example/db/events.php
and example/eventslib.php
.
In eventslib.php
:
<?php
abstract class ues_greeting_events {
function greet($user, $message) {
$message = new stdClass;
$message->userto = $user->userid;
$message->subject = "Welcome";
$message->fullmessage = $message;
$message->userfrom = 1;
$message->fullmessageformat = FORMAT_MOODLE;
$message->component = "moodle";
return $message;
}
function ues_student_enroll($params) {
extract($params);
$message = self::greet($ues_user, "Welcome to " . $group->name);
message_send($message);
}
}
In db/events.php
:
<?php
$handlers = array("ues_student_enroll" => array(
"handlerfile" => "/blocks/example/eventslib.php",
"handlerfunction" => array("ues_greeting_events", "ues_student_enroll"),
"schedule" => "instant"
));
Now, every time a student registers for a course for the first time, they will be greeted with a welcome message. This a very trivial example, but it would be possible to give the instructor the ability to customize a greeting message and use it.