Browse Source

Move all functions inside class

SABERES_37_STABLE
Johannes Burk 9 years ago
committed by test
parent
commit
b9f4434f06
  1. 50
      lib.php

50
lib.php

@ -77,8 +77,8 @@ class enrol_apply_plugin extends enrol_plugin {
$applicationinfo->userenrolmentid = $userenrolment->id; $applicationinfo->userenrolmentid = $userenrolment->id;
$applicationinfo->comment = $applydescription; $applicationinfo->comment = $applydescription;
$DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false);
sendConfirmMailToTeachers($instance, $data, $applydescription); $this->sendConfirmMailToTeachers($instance, $data, $applydescription);
sendConfirmMailToManagers($instance, $data, $applydescription); $this->sendConfirmMailToManagers($instance, $data, $applydescription);
// Deprecated fixed by Shiro <gigashiro@gmail.com> // Deprecated fixed by Shiro <gigashiro@gmail.com>
//add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! //add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
@ -224,9 +224,9 @@ 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 = getRelatedInfo($enrol); $info = $this->getRelatedInfo($enrol);
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
sendConfirmMail($info); $this->sendConfirmMail($info);
} }
} }
@ -246,8 +246,8 @@ 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 = getRelatedInfo($enrol); $info = $this->getRelatedInfo($enrol);
sendWaitMail($info); $this->sendWaitMail($info);
} }
} }
} }
@ -273,51 +273,50 @@ class enrol_apply_plugin extends enrol_plugin {
continue; continue;
} }
$info = getRelatedInfo($enrol); $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));
sendCancelMail($info); $this->sendCancelMail($info);
} }
} }
}
function sendCancelMail($info){ function sendCancelMail($info){
global $DB; global $DB;
global $CFG; global $CFG;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); $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 = updateMailContent($body,$replace); $body = $this->updateMailContent($body,$replace);
$contact = core_user::get_support_user(); $contact = core_user::get_support_user();
email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body); email_to_user($info, $contact, get_config('enrol_apply', 'cancelmailsubject'), html_to_text($body), $body);
} }
function sendConfirmMail($info){ function sendConfirmMail($info){
global $DB; global $DB;
global $CFG; global $CFG;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$body = get_config('enrol_apply', 'confirmmailcontent'); $body = get_config('enrol_apply', 'confirmmailcontent');
$body = updateMailContent($body,$replace); $body = $this->updateMailContent($body,$replace);
$contact = core_user::get_support_user(); $contact = core_user::get_support_user();
email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body); email_to_user($info, $contact, get_config('enrol_apply', 'confirmmailsubject'), html_to_text($body), $body);
} }
function sendWaitMail($info){ function sendWaitMail($info){
global $DB; global $DB;
global $CFG; global $CFG;
//global $USER; //global $USER;
$replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username); $replace = array('firstname'=>$info->firstname,'content'=>format_string($info->coursename),'lastname'=>$info->lastname,'username'=>$info->username);
$body = get_config('enrol_apply', 'waitmailcontent'); $body = get_config('enrol_apply', 'waitmailcontent');
$body = updateMailContent($body,$replace); $body = $this->updateMailContent($body,$replace);
$contact = get_admin(); $contact = get_admin();
//confirm mail will sent by the admin //confirm mail will sent by the admin
//$contact = $USER; //$contact = $USER;
email_to_user($info, $contact, get_config('enrol_apply', 'waitmailsubject'), 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){
global $DB; global $DB;
global $CFG; global $CFG;
global $USER; global $USER;
@ -359,9 +358,9 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){
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);
} }
} }
} }
function sendConfirmMailToManagers($instance,$info,$applydescription){ function sendConfirmMailToManagers($instance,$info,$applydescription){
global $DB; global $DB;
global $CFG; global $CFG;
global $USER; global $USER;
@ -402,18 +401,19 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){
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);
} }
} }
} }
function getRelatedInfo($enrolid){ function getRelatedInfo($enrolid){
global $DB; global $DB;
global $CFG; global $CFG;
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 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
join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.id='.$enrolid); join '.$CFG->prefix.'course as c on e.courseid=c.id where ue.id='.$enrolid);
} }
function updateMailContent($content,$replace){ 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);
} }
return $content; return $content;
}
} }

Loading…
Cancel
Save