General developer forum

 
 
Picture of Chris Jenkins
I'm new to Moodle and need to create a trigger
 

Hi, We've deployed Moodle and I have no idea what I'm doing smile

I'd like our course(s) to invoke a web service to an external app once a student has completed it (trigger??). Perhaps I need to build a client (web service) app and have Moodle pass it parameters and invoke it.

What's the accepted "Moodle" way I should do this?

Thanks, Chris

 
Average of ratings: -
Picture of Rex Lorenzo
Re: I'm new to Moodle and need to create a trigger
Group DevelopersGroup Particularly helpful MoodlersGroup Testers

I would suggest creating a local plugin that responds to the "course_created" event using the Events API.

 
Average of ratings: -
Me
Re: I'm new to Moodle and need to create a trigger
 

Hi Chris,
The events API does indeed look like the way to do this, However from your original post, It seems you want something to trigger when a course is compeleted.

From 2.3.2 onwards it looks like course_completed might be the one to meet your requirements. I have not played with this, so cannot help with code. This would make use of Course completion and activity completion to allow the course to have a course completion event.

Events which exist    (scroll down a bit).
Users

  • course_completed (introduced in version 2.3.2)
    • full course_completions table record
 
Average of ratings: -
Picture of Chris Jenkins
Re: I'm new to Moodle and need to create a trigger
 

Thanks Richard!

Thats good news, it looks like I just create a "course completed" handler and register it by including it in mdl_events_handlers table:

INSERT INTO `moodle`.`mdl_events_handlers` (`id`, `eventname`, `component`, `handlerfile`, `handlerfunction`, `schedule`, `status`, `internal`) VALUES ('18', 'course_completed', 'mod_sp', '/mod/sp/lib.php', 'a:2:{i:0;s:18:\"enrol_meta_handler\";i:1;s:14:\"course_completed\";}', 'instant', '0', '1');

 Then I just implement the lib.php handler and bob's your uncle!

Does this sound right.. anyone?  

 
Average of ratings: -
Picture of Rex Lorenzo
Re: I'm new to Moodle and need to create a trigger
Group DevelopersGroup Particularly helpful MoodlersGroup Testers

Yikes, no, you shouldn't register to handle an event that way.

Please read the "Handling an event" part of the documentation:

http://docs.moodle.org/dev/Events_API#Example

There is a code example in the mod/forum directory.

 
Average of ratings: -