Tony
Tony

Reputation: 3489

How to notify users their connected time to a course since begining

I want to know if there is a plugin or somehow to notify via email to moodle users if they have not connected since xxxx date to complete a course.

Is there a way to make this automatically via cron or so?

Thanks.

Upvotes: 0

Views: 170

Answers (1)

Kade M.
Kade M.

Reputation: 181

You're question is a 2 in 1. You're asking how to identify users who haven't signed on in a while, and how to email them. I'm going to answer in parts accordingly. All of this can be accomplished via cron, but I don't use Moodle so I don't know what plugins are available to you.

He's an example of a query that would identify users who haven't logged on in 180 days (but it will ignore those who have never logged in).

SELECT * FROM mdl_user 
WHERE lastlogin < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY))
AND lastlogin != 0
AND lastaccess < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY))
AND deleted = 0

Now for the email bit. Per Google, Moodle uses the PHPMailer for it's email_to_user() function. An example of using this in PHP:

email_to_user($toUser, $fromUser, $subject, $messageText, $messageHtml, '', '', true);

$toUser and $fromUser should be Moodle user objects, not email addresses. Traversing your query results to build these objects would be all that's left to do.

Last tip: To get a user object based on each result of your query, you can use the get_record function like so:

$userObj = get_record("user", "id", $userID);

Upvotes: 1

Related Questions