General developer forum

 
 
Picture of Paul Solecki
Where to hook in to the course completion event?
 

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: -
Picture of Ray Morris
Re: Where to hook in to the course completion event?
Group DevelopersGroup Particularly helpful Moodlers

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.)

 
Average of ratings: -
Picture of Paul Solecki
Re: Where to hook in to the course completion event?
 

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.

 
Average of ratings: -
Picture of Ray Morris
Re: Where to hook in to the course completion event?
Group DevelopersGroup Particularly helpful Moodlers

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.

 
Average of ratings: -
Picture of Ray Morris
Re: Where to hook in to the course completion event?
Group DevelopersGroup Particularly helpful Moodlers

This is the tracker issue for this:

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

 
Average of ratings: -
Picture of Aaron Barnes
Re: Where to hook in to the course completion event?
Group Developers

Issue updated with a patch smile

Cheers,
Aaron

 
Average of ratings: -
Picture of Sami Hwang
Re: Where to hook in to the course completion event?
 

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

 

 

 
Average of ratings: -
Picture of Aaron Barnes
Re: Where to hook in to the course completion event?
Group Developers

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

 
Average of ratings: -
Picture of Aaron Barnes
Re: Where to hook in to the course completion event?
Group Developers

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

 
Average of ratings: -
Picture of Sami Hwang
Re: Where to hook in to the course completion event?
 

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

 
Average of ratings: -
Picture of Aaron Barnes
Re: Where to hook in to the course completion event?
Group Developers

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

 
Average of ratings: -
Picture of Mahtab Hussain
Re: Where to hook in to the course completion event?
 

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

 
Average of ratings: -