Where to hook in to the course completion event?

Where to hook in to the course completion event?

by Paul Solecki -
Number of replies: 11

Hi all,

Very new to moodle but I have some things I need to do when a course is completed.

I notice there is a course_completed event on the Wanted list for the Event API but I need it now.

Where is the best point to add in my code?

Many thanks,

Paul.

Average of ratings: -
In reply to Paul Solecki

Re: Where to hook in to the course completion event?

by Ray Morris -

I'm somewhat new with Moodle myself, but I'd think an event should be raised within:

lib/completion/cron.php  function completion_cron_completions() {

 

Looks like about 2/3rds of the way into the function it actually marks the completions.  Reading the Events API page, it looks like I should be pretty simple to add. I suppose one could add it, then send the proposed code to the author listed at the top of the module for review.

 

If you do code it, please post your code here as well and / or email me as I'd be interested in helping / reviewing / using that.  If you try to add it and run into any questions or prpblems I'd be glad to try to help work through any problems. (I have many years of programming expereince, not much Moodle experience.)

In reply to Ray Morris

Re: Where to hook in to the course completion event?

by Paul Solecki -

Well our project was scrapped a couple of weeks ago. I decided to hook into the scorm player rather than waiting for moodle to mark things as completed.


In /mod/scorm/datamodel.php I used a flag in the

foreach (data_submitted() as $element => $value) {

loop, I then checked whether cmi.core.lesson_status was set to completed to set my flag to true. Once at the end of this, if the completed flag is set to true then I do my bit of processing.

I never actually got to properly test it but I think it should work.

In reply to Paul Solecki

Re: Where to hook in to the course completion event?

by Ray Morris -

We did the same thing previously, checking for the completion of the SCORM.  Now that we have a course with multiple SCORMs, we're going to do it "right" by firing from course competion.

 

BTW I mentioned doing it in the cron script.  Taking a second look, I think the right place would be:

 

lib/completion/completion_completion.php 

public function mark_complete

 

I'm submitting a tracker issue to get feedback from Aaron Barnes, maintainer of the completion module, and other interested parties.

I'm kind of tempted to sprinkle events in a few places within completion - it's job is basically to track completion events, it seems, so it would be good if it raised events, I'm thinking.

In reply to Ray Morris

Re: Where to hook in to the course completion event?

by Ray Morris -

This is the tracker issue for this:

http://tracker.moodle.org/browse/MDL-34795

In reply to Ray Morris

Re: Where to hook in to the course completion event?

by Aaron Barnes -

Issue updated with a patch smile

Cheers,
Aaron

In reply to Aaron Barnes

Re: Where to hook in to the course completion event?

by Sami Hwang -

Hello Aaron,

We are currently using Moodle 2.1 with a course completion and restriction module. The thing is that when I test our courses, I noticed that a check mark will appear even when users do not reach completion. To fix this problem, do I have to upgrade to Moodle 2.2 or 2.3? Is ther any thing I can do within completion_completion.php?

Any advice would be appreciated.

 

Sami

 

 

In reply to Sami Hwang

Re: Where to hook in to the course completion event?

by Aaron Barnes -

Hi Sami,

If you are referring to the checkmarks on the course page, then the issue is that they are "Activity completion" indicators. Activity completion is a related system to Course completion, which can be independant of it. You can be complete in an activity without completing the entire course, it will depend on how your criteria are set up. Is this the issue? or -

If you are referring to the ticks in the Course completion report, then if you could attach a screenshot of the issue (including table headers) I'd love to try help you with it smile

Hope that helps,
Aaron

In reply to Aaron Barnes

Re: Where to hook in to the course completion event?

by Aaron Barnes -

Hi Sami,

I'd also just like to note, if you can upgrade to Moodle 2.3 please do! Course completion had a significant backend update in that release and is far more reliable.

Thanks,
Aaron

In reply to Aaron Barnes

Re: Where to hook in to the course completion event?

by Sami Hwang -

Thank you for your quick resposne Aaron,

I will definitely ask the possibility of upgrade to our IT manager.

In the mean time, I also need to find out what I can do with our current version 2.1. I set the current criteria as 'student must view this activty to complete it' and completiong tracking 'show activity as complete when conditions are met' As I stated in my previous posting, I noticed that even users do not finish a course and go back to the course list, a check mark appears. I don't think I am talking about a course completion report. I attached the picture to illustrate my point.(By the way, I modified the location of the check mark right next to the course title.) My question is that is there any patch to fix this problem in Moodle 2.1? Tabel header screen shot means the header of our DB table ?

image

In reply to Sami Hwang

Re: Where to hook in to the course completion event?

by Aaron Barnes -

Hi Sami,

So what you are referring to is Activity Completion, which sounds like it is working correctly. Activity completion by itself has no connection to the completion of a course, and the criteria "student must view activity" means that simply after viewing the activity the tickbox should remain their for that user until the activity's criteria are editing (and therefore completion data is reset).

This document may be more help - http://docs.moodle.org/23/en/Using_Activity_completion

Good luck!
Aaron

In reply to Aaron Barnes

Re: Where to hook in to the course completion event?

by Mahtab Hussain -

May you live in peace Aaron!

We are using Moodle 2.3. I have applied a patch for the course completion event in lib/completion/completion_completion.php.

I have developed a custom module, where I created event handler code in events.php. Now, I am to define respective event handler function but I am not aware what data ($eventdata) and its structure I am receiving.

Can you please guide me what is the structure of event data returned by course completion event?

Warm regards,

Mahtab Hussain