Browse Source

Optimize notification mail sending

SABERES_37_STABLE
Johannes Burk 9 years ago
committed by test
parent
commit
51cf0cbf55
  1. 125
      lib.php
  2. 43
      renderer.php

125
lib.php

@ -330,51 +330,30 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){
$context = context_course::instance($courseid, MUST_EXIST); $context = context_course::instance($courseid, MUST_EXIST);
$teacherType = $DB->get_record('role',array("shortname"=>"editingteacher")); $teacherType = $DB->get_record('role',array("shortname"=>"editingteacher"));
$teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id)); $teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id));
if (!$instance->customint1) {
$info = null;
}
$extra = null;
if($instance->customint2){
require_once($CFG->dirroot.'/user/profile/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
profile_load_custom_fields($user);
$extra = $user->profile;
}
$manageurl = new moodle_url("/enrol/apply/manage.php", array('id'=>$instanceid));
global $PAGE;
$renderer = $PAGE->get_renderer('enrol_apply');
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra);
$contact = core_user::get_support_user();
foreach($teachers as $teacher){ foreach($teachers as $teacher){
$editTeacher = $DB->get_record('user',array('id'=>$teacher->userid)); $editTeacher = $DB->get_record('user',array('id'=>$teacher->userid));
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($instance->customint1){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($instance->customint2){
require_once($CFG->dirroot.'/user/profile/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
profile_load_custom_fields($user);
foreach ($user->profile as $key => $value) {
$body .= '<p>'. $key .': '.$value.'</p>';
}
}
$body .= '<p>'. html_writer::link(new moodle_url("/enrol/apply/manage.php", array('id'=>$instanceid)), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = core_user::get_support_user();
$info = $editTeacher; $info = $editTeacher;
$info->coursename = $course->fullname; $info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
@ -394,50 +373,30 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){
$context = context_system::instance(); $context = context_system::instance();
$managerType = $DB->get_record('role',array("shortname"=>"manager")); $managerType = $DB->get_record('role',array("shortname"=>"manager"));
$managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id)); $managers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$managerType->id));
if (!$instance->customint1) {
$info = null;
}
$extra = null;
if($instance->customint2){
require_once($CFG->dirroot.'/user/profile/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
profile_load_custom_fields($user);
$extra = $user->profile;
}
$manageurl = new moodle_url('/enrol/apply/manage.php');
global $PAGE;
$renderer = $PAGE->get_renderer('enrol_apply');
$body = $renderer->application_notification_mail_body($course, $USER, $manageurl, $applydescription, $info, $extra);
$contact = core_user::get_support_user();
foreach($managers as $manager){ foreach($managers as $manager){
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid)); $userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($instance->customint1){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($instance->customint2){
require_once($CFG->dirroot.'/user/profile/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
profile_load_custom_fields($user);
foreach ($user->profile as $key => $value) {
$body .= '<p>'. $key .': '.$value.'</p>';
}
}
$body .= '<p>'. html_writer::link(new moodle_url('/enrol/apply/manage.php'), get_string('applymanage', 'enrol_apply')).'</p>';
$contact = core_user::get_support_user();
$info = $userWithManagerRole; $info = $userWithManagerRole;
$info->coursename = $course->fullname; $info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body); email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);

43
renderer.php

@ -71,4 +71,47 @@ class enrol_apply_renderer extends plugin_renderer_base {
$table->out(50, true); $table->out(50, true);
} }
public function application_notification_mail_body($course, $user, $manageurl, $applydescription, $info = null, $extra = null) {
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>';
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$user->firstname.' '.$user->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($info){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$info->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$info->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$info->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$info->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$info->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$info->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$info->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$info->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$info->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$info->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$info->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$info->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$info->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$info->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$info->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$info->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$info->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$info->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$info->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$info->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
}
if($extra){
foreach ($extra as $key => $value) {
$body .= '<p>'. $key .': '.$value.'</p>';
}
}
$body .= '<p>'. html_writer::link($manageurl, get_string('applymanage', 'enrol_apply')).'</p>';
return $body;
}
} }
Loading…
Cancel
Save