Browse Source

Optimize sending application notification to teachers and managers.

SABERES_37_STABLE
Johannes Burk 9 years ago
committed by test
parent
commit
cec7f27c29
  1. 112
      lib.php
  2. 56
      renderer.php

112
lib.php

@ -62,11 +62,6 @@ class enrol_apply_plugin extends enrol_plugin {
if ($data = $form->get_data()) {
// Only process when form submission is for this instance (multi instance support).
if ($data->instance == $instance->id) {
$userInfo = $data;
$applydescription = $userInfo->applydescription;
unset($userInfo->applydescription);
$userInfo->id = $USER->id;
$timestart = 0;
$timeend = 0;
$roleid = $instance->roleid;
@ -75,10 +70,10 @@ class enrol_apply_plugin extends enrol_plugin {
$userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST);
$applicationinfo = new stdClass();
$applicationinfo->userenrolmentid = $userenrolment->id;
$applicationinfo->comment = $applydescription;
$applicationinfo->comment = $data->applydescription;
$DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false);
$this->sendConfirmMailToTeachers($instance, $data, $applydescription);
$this->sendConfirmMailToManagers($instance, $data, $applydescription);
$this->send_application_notification($instance, $USER->id, $data);
redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid");
}
@ -284,89 +279,56 @@ class enrol_apply_plugin extends enrol_plugin {
email_to_user($user, $contact, $subject, html_to_text($body), $body);
}
function sendConfirmMailToTeachers($instance,$info,$applydescription){
global $DB;
global $CFG;
global $USER;
function send_application_notification($instance, $userid, $data) {
global $PAGE;
$courseid = $instance->courseid;
$instanceid = $instance->id;
$renderer = $PAGE->get_renderer('enrol_apply');
if($instance->customint3 == 1){
$course = get_course($courseid);
$context = context_course::instance($courseid, MUST_EXIST);
$teacherType = $DB->get_record('role',array("shortname"=>"editingteacher"));
$teachers = $DB->get_records('role_assignments', array('contextid'=>$context->id,'roleid'=>$teacherType->id));
$course = get_course($instance->courseid);
$user = core_user::get_user($userid);
$contact = core_user::get_support_user();
if (!$instance->customint1) {
$info = null;
// Include standard user profile fields?
$standarduserfields = null;
if ($instance->customint1) {
$standarduserfields = $data;
unset($standarduserfields->applydescription);
}
$extra = null;
if($instance->customint2){
// Include extra user profile fields?
$extrauserfields = null;
if ($instance->customint2) {
require_once($CFG->dirroot.'/user/profile/lib.php');
$user = $DB->get_record('user',array('id'=>$USER->id));
$user = $DB->get_record('user',array('id' => $user->id));
profile_load_custom_fields($user);
$extra = $user->profile;
$extrauserfields = $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){
$editTeacher = $DB->get_record('user',array('id'=>$teacher->userid));
// Send notification to Teachers? Instance depending.
if ($instance->customint3 == 1) {
$context = context_course::instance($instance->courseid);
$editingteacherroles = get_archetype_roles('editingteacher');
$editingteacherrole = reset($editingteacherroles);
$teachers = get_role_users($editingteacherrole->id, $context);
$info = $editTeacher;
$info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
}
$manageurl = new moodle_url("/enrol/apply/manage.php", array('id' => $instance->id));
$body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields);
foreach ($teachers as $teacher) {
email_to_user($teacher, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
}
}
function sendConfirmMailToManagers($instance,$info,$applydescription){
global $DB;
global $CFG;
global $USER;
$courseid = $instance->courseid;
if(get_config('enrol_apply', 'sendmailtomanager') == 1){
$course = get_course($courseid);
// Send notification to managers in system context?
if (get_config('enrol_apply', 'sendmailtomanager') == 1) {
$context = context_system::instance();
$managerType = $DB->get_record('role',array("shortname"=>"manager"));
$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;
}
$managerroles = get_archetype_roles('manager');
$managerrole = reset($editingteacherroles);
$managers = get_role_users($managerrole->id, $context);
$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){
$userWithManagerRole = $DB->get_record('user',array('id'=>$manager->userid));
$info = $userWithManagerRole;
$info->coursename = $course->fullname;
email_to_user($info, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
$body = $renderer->application_notification_mail_body($course, $user, $manageurl, $data->applydescription, $standarduserfields, $extrauserfields);
foreach ($managers as $manager) {
email_to_user($manager, $contact, get_string('mailtoteacher_suject', 'enrol_apply'), html_to_text($body), $body);
}
}
}

56
renderer.php

@ -72,40 +72,40 @@ class enrol_apply_renderer extends plugin_renderer_base {
$table->out(50, true);
}
public function application_notification_mail_body($course, $user, $manageurl, $applydescription, $info = null, $extra = null) {
public function application_notification_mail_body($course, $user, $manageurl, $applydescription, $standarduserfields = null, $extrauserfields = 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){
if($standarduserfields){
$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>';
$body .= '<p>'. get_string('firstname') .': '.$standarduserfields->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$standarduserfields->lastname.'</p>';
$body .= '<p>'. get_string('email') .': '.$standarduserfields->email.'</p>';
$body .= '<p>'. get_string('city') .': '.$standarduserfields->city.'</p>';
$body .= '<p>'. get_string('country') .': '.$standarduserfields->country.'</p>';
$body .= '<p>'. get_string('preferredlanguage') .': '.$standarduserfields->lang.'</p>';
$body .= '<p>'. get_string('description') .': '.$standarduserfields->description_editor['text'].'</p>';
$body .= '<p>'. get_string('firstnamephonetic') .': '.$standarduserfields->firstnamephonetic.'</p>';
$body .= '<p>'. get_string('lastnamephonetic') .': '.$standarduserfields->lastnamephonetic.'</p>';
$body .= '<p>'. get_string('middlename') .': '.$standarduserfields->middlename.'</p>';
$body .= '<p>'. get_string('alternatename') .': '.$standarduserfields->alternatename.'</p>';
$body .= '<p>'. get_string('url') .': '.$standarduserfields->url.'</p>';
$body .= '<p>'. get_string('icqnumber') .': '.$standarduserfields->icq.'</p>';
$body .= '<p>'. get_string('skypeid') .': '.$standarduserfields->skype.'</p>';
$body .= '<p>'. get_string('aimid') .': '.$standarduserfields->aim.'</p>';
$body .= '<p>'. get_string('yahooid') .': '.$standarduserfields->yahoo.'</p>';
$body .= '<p>'. get_string('msnid') .': '.$standarduserfields->msn.'</p>';
$body .= '<p>'. get_string('idnumber') .': '.$standarduserfields->idnumber.'</p>';
$body .= '<p>'. get_string('institution') .': '.$standarduserfields->institution.'</p>';
$body .= '<p>'. get_string('department') .': '.$standarduserfields->department.'</p>';
$body .= '<p>'. get_string('phone') .': '.$standarduserfields->phone1.'</p>';
$body .= '<p>'. get_string('phone2') .': '.$standarduserfields->phone2.'</p>';
$body .= '<p>'. get_string('address') .': '.$standarduserfields->address.'</p>';
}
if($extra){
foreach ($extra as $key => $value) {
if($extrauserfields){
foreach ($extrauserfields as $key => $value) {
$body .= '<p>'. $key .': '.$value.'</p>';
}
}

Loading…
Cancel
Save