Patch - Email when student is marked as attended

Patch - Email when student is marked as attended

by Dustin Elliott -
Number of replies: 0
Ok so this is my first attempt at creating a patch for the Face-to-Face module to send out an email to the student when they are marked as attending a Face-to-Face class.

If you use the lib.php file attached to this post you will need to add 2 strings to the file /mod/facetoface/lang/en_utf8/facetoface.php

String1 named "classattendedemailsubject"
String2 named "classattendedemailbody"

I left those out because they contain some site specific information but they are the email subject line and body so you can customize them to meet your needs.

Please feel free to suggest any changes or clean up the code as this is really my first endeavor into PHP as well, you won't hurt my feelings. big grin

Everything I added is between commented lines:
Start of my code: //--------------------DRE August 21--------------------\\
End of my code: //-----------------------DRE---------------------------\\


/mod/facetoface/lib.php



function facetoface_take_individual_attendance($submissionid,$didattend) {
global $USER, $CFG;

//--------------------DRE August 21--------------------\\
$userrecord = get_record_sql("SELECT f.*, s.userid, s.facetoface
FROM {$CFG->prefix}facetoface_submissions s
JOIN {$CFG->prefix}facetoface f ON f.id = s.facetoface
JOIN {$CFG->prefix}course_modules cm ON cm.instance = f.id
JOIN {$CFG->prefix}modules m ON m.id = cm.module
WHERE s.id = $submissionid AND m.name='facetoface'");
//-----------------------DRE---------------------------\\

//print_object($USER);
$timenow = time();

//--------------------DRE August 21--------------------\\
$attendeuser = get_record('user', 'id', $userrecord->userid);
$f2fname = get_record('facetoface', 'id', $userrecord->facetoface);

$user->email = $attendeuser->email;
$user->firstname = $attendeuser->firstname;
$user->lastname = $attendeuser->lastname;

$emailinfo = new object();
$emailinfo->firstname = $user->firstname;
$emailinfo->lastname = $user->lastname;
$emailinfo->f2fname = $f2fname->name;

$supportuser = generate_email_supportuser();
$subject = get_string('classattendedemailsubject', 'facetoface', $f2fname->name);
$message = get_string('classattendedemailbody', 'facetoface', $emailinfo);
//-----------------------DRE---------------------------\\

// Indicate attendance by setting the grading to 0 (did not attend) or 100 (did attend)
if ($didattend) {
$grading = 100;
//--------------------DRE August 21--------------------\\
//Send email to student when they are marked as attended
email_to_user($user, $supportuser, $subject, $message, $messagehtml='');
//-----------------------DRE---------------------------\\
}
else {
$grading = 0;
}

$record = get_record_sql("SELECT f.*, s.userid
FROM {$CFG->prefix}facetoface_submissions s
JOIN {$CFG->prefix}facetoface f ON f.id = s.facetoface
JOIN {$CFG->prefix}course_modules cm ON cm.instance = f.id
JOIN {$CFG->prefix}modules m ON m.id = cm.module
WHERE s.id = $submissionid AND m.name='facetoface'");

$grade = new stdclass();
$grade->userid = $record->userid;
$grade->rawgrade = $grading;
$grade->rawgrademin = 0;
$grade->rawgrademax = 100;
$grade->timecreated = $timenow;
$grade->timemodified = $timenow;
$grade->usermodified = $USER->id;

return facetoface_grade_item_update($record, $grade);
}

Average of ratings: -