Help with events!

Help with events!

by Alejandro Hernandez Lara -
Number of replies: 6

Hello Community! i need know which is the event that is triggered when a user opens and exit a course, 

thanks!

Average of ratings: -
In reply to Alejandro Hernandez Lara

Re: Help with events!

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Ordinarily I would think _onopen and _onclose, but the problem is the onclose event. Not all pages are closed properly by users. This is a question that can have many answers, so I suggest you write a short descriptor of what it is you are trying/wanting to do and post the question in the General Developer's Forum.

Start with the Developer's Documentation first, and then work from there. 

In reply to Colin Fraser

Re: Help with events!

by Alejandro Hernandez Lara -

Thanks for your answer, i explain now:

I am developing a plugin that register the time that an user stay in a course. 

1)When enter to the course

2)When exit the course

In reply to Alejandro Hernandez Lara

Re: Help with events!

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi Alejandro -

To answer the original question, there are no specific events generated (assuming you mean the Moodle events system) for entering or exiting a course. This is because there is no easy way to determine this.

To develop a plugin that determines this, you would first need to define what actions constitute entering and exiting a course.

For example, if use access the course from the "view" page (e.g. http://[yoursite]/course/view.php?id=2), a "course viewed" event will be generated to the logging system. If a user goes directly to an activity in the course (e.g. http://[yoursite]/mod/page/view.php?id=10), a "course module event" will be generated for that module. Both of these events could be considered to be an "enter the course" event, if the user was not previously considered already "entered".

Likewise, what actions do you want to consider as "exiting the course"? A user could login, look at a course resource, and then leave for a holiday with their session logged in. At what point after that would you consider there to have been an "exit the course" action?

Other people have created plugins, such as reports, to estimate the amount of time a user spends in a course. But it will always be at best a inaccurate estimate. You can never be sure that the user actually did anything useful in that time. Typically these estimates comb through the log records, looking for unbroken entries for a specific course, and adding up the time differences. You also have to consider using the session timeout setting for the site. This is the amount of inactive time a user is allowed before they are automatically logged out. If you can't find log records for a user from one entry to the next that is within that time frame, you should assume that they were inactive and left the session.

Hope this helps, and good luck.

mike

In reply to Colin Fraser

Re: Help with events!

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If relevant (I'm not sure it is). I'd much rather we moved threads than ask the same question in multiple forums wink

In reply to Howard Miller

Re: Help with events!

by Mary Cooch -
Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators

Yes - if you see a question that needs moving, just let us know and we can do that.

Average of ratings: Useful (1)
In reply to Alejandro Hernandez Lara

Re: Help with events!

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Firstly... PLEASE don't create new threads about (what seems to be) the same issue. This splits the replies and causes confusion

https://moodle.org/mod/forum/discuss.php?d=345703

Secondly, what you are trying to do is basically impossible. You can't tell when somebody exits a course and you certainly can't determine if they were 'engaged' (in some sense) while they were there. There is no 'I have finished looking at this' button and even if there was users wouldn't press it. We get asked variations on this all the time. I understand that somebody is making you provide meaningless stats on courses but you'd be just as accurate and meaningful making them up wink