Browse Source

Optimize user notifications for confirm, wait, cancel actions.

SABERES_37_STABLE
Johannes Burk 9 years ago
committed by test
parent
commit
7c38a66258
  1. 66
      lib.php

66
lib.php

@ -211,10 +211,11 @@ class enrol_apply_plugin extends enrol_plugin {
} }
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE); $this->update_user_enrol($instance, $userenrolment->userid, ENROL_USER_ACTIVE);
$info = $this->getRelatedInfo($enrol);
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
$this->sendConfirmMail($info);
$subject = get_config('enrol_apply', 'confirmmailsubject');
$body = get_config('enrol_apply', 'confirmmailcontent');
$this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body);
} }
} }
@ -234,8 +235,9 @@ class enrol_apply_plugin extends enrol_plugin {
$this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT); $this->update_user_enrol($instance, $userenrolment->userid, ENROL_APPLY_USER_WAIT);
$info = $this->getRelatedInfo($enrol); $subject = get_config('enrol_apply', 'waitmailsubject');
$this->sendWaitMail($info); $body = get_config('enrol_apply', 'waitmailcontent');
$this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body);
} }
} }
} }
@ -261,47 +263,25 @@ class enrol_apply_plugin extends enrol_plugin {
continue; continue;
} }
$info = $this->getRelatedInfo($enrol);
$this->unenrol_user($instance, $userenrolment->userid); $this->unenrol_user($instance, $userenrolment->userid);
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
$this->sendCancelMail($info);
}
}
function sendCancelMail($info){ $subject = get_config('enrol_apply', 'cancelmailsubject');
global $DB;
global $CFG;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$body = get_config('enrol_apply', 'cancelmailcontent'); $body = get_config('enrol_apply', 'cancelmailcontent');
$body = $this->updateMailContent($body,$replace); $this->send_mail_to_applicant($instance, $userenrolment->userid, $subject, $body);
$contact = core_user::get_support_user();
email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body);
} }
function sendConfirmMail($info){
global $DB;
global $CFG;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$body = get_config('enrol_apply', 'confirmmailcontent');
$body = $this->updateMailContent($body,$replace);
$contact = core_user::get_support_user();
email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body);
} }
function sendWaitMail($info){ function send_mail_to_applicant($instance, $userid, $subject, $body) {
global $DB; global $DB;
global $CFG; global $CFG;
//global $USER;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); $course = get_course($instance->courseid);
$body = get_config('enrol_apply', 'waitmailcontent'); $user = core_user::get_user($userid);
$body = $this->updateMailContent($body,$replace);
$contact = get_admin(); $body = $this->updateMailContent($body, $course, $user);
//confirm mail will sent by the admin $contact = core_user::get_support_user();
//$contact = $USER; email_to_user($user, $contact, $subject, html_to_text($body), $body);
email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), html_to_text($body), $body);
} }
function sendConfirmMailToTeachers($instance,$info,$applydescription){ function sendConfirmMailToTeachers($instance,$info,$applydescription){
@ -391,14 +371,12 @@ class enrol_apply_plugin extends enrol_plugin {
} }
} }
function getRelatedInfo($enrolid){ function updateMailContent($content, $course, $user) {
global $DB; $replace = array(
global $CFG; 'firstname' => $user->firstname,
return $DB->get_record_sql('select u.*,c.fullname as coursename from '.$CFG->prefix.'user_enrolments as ue left join '.$CFG->prefix.'user as u on ue.userid=u.id left join '.$CFG->prefix.'enrol as e on ue.enrolid=e.id left 'content' => format_string($course->fullname),
join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.id='.$enrolid); 'lastname' => $user->lastname,
} 'username' => $user->username);
function updateMailContent($content,$replace){
foreach ($replace as $key=>$val) { foreach ($replace as $key=>$val) {
$content = str_replace("{".$key."}",$val,$content); $content = str_replace("{".$key."}",$val,$content);
} }

Loading…
Cancel
Save