Browse Source

Merge pull request #86 from Chiew96/master

Notification fix
SABERES_37_STABLE
Flotter Totte 6 years ago
committed by GitHub
parent
commit
2ab98035d4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      edit.php
  2. 14
      edit_form.php
  3. 19
      lib.php

6
edit.php

@ -63,13 +63,13 @@ if ($instanceid) {
// Process notify setting for editing... // Process notify setting for editing...
// Convert to array for use with multi-select element. // Convert to array for use with multi-select element.
$notify = array('$@NONE@$'); //$notify = array('$@NONE@$');
/* /*
if ($instance->customtext2 != '') { if ($instance->customtext2 != '') {
$notify = explode(',', $instance->customtext2); $notify = explode(',', $instance->customtext2);
} }
*/ */
$instance->notify = $notify; //$instance->notify = $notify;
$mform = new enrol_apply_edit_form(null, array($instance, $plugin, $context)); $mform = new enrol_apply_edit_form(null, array($instance, $plugin, $context));
@ -91,10 +91,12 @@ if ($mform->is_cancelled()) {
// Convert back to string for storing in enrol table. // Convert back to string for storing in enrol table.
//$data->customtext2 = implode(',', $notify); //$data->customtext2 = implode(',', $notify);
if ($instance->id) { if ($instance->id) {
$notify = implode(",", $notify);
$instance->status = $data->status; $instance->status = $data->status;
$instance->name = $data->name; $instance->name = $data->name;
$instance->customtext1 = $data->customtext1; $instance->customtext1 = $data->customtext1;
$instance->customtext2 = $data->customtext2; $instance->customtext2 = $data->customtext2;
$instance->customtext3 = $notify;
$instance->customint1 = $data->customint1; $instance->customint1 = $data->customint1;
$instance->customint2 = $data->customint2; $instance->customint2 = $data->customint2;
$instance->customint3 = $data->customint3; $instance->customint3 = $data->customint3;

14
edit_form.php

@ -29,6 +29,7 @@ require_once($CFG->libdir.'/formslib.php');
class enrol_apply_edit_form extends moodleform { class enrol_apply_edit_form extends moodleform {
protected function definition() { protected function definition() {
global $DB;
$mform = $this->_form; $mform = $this->_form;
list($instance, $plugin, $context) = $this->_customdata; list($instance, $plugin, $context) = $this->_customdata;
@ -84,6 +85,19 @@ class enrol_apply_edit_form extends moodleform {
} }
$select = $mform->addElement('select', 'notify', get_string('notify_desc', 'enrol_apply'), $choices); $select = $mform->addElement('select', 'notify', get_string('notify_desc', 'enrol_apply'), $choices);
$select->setMultiple(true); $select->setMultiple(true);
$userid = $DB->get_field('enrol', 'customtext3', array('id' => $instance->id), IGNORE_MISSING);
if(!empty($userid)) {
if($userid == '$@ALL@$') {
$select->setSelected('$@ALL@$');
}
else if($userid == '$@NONE@$') {
$select->setSelected('$@NONE@$');
}
else {
$userid = explode(",", $userid);
$select->setSelected($userid);
}
}
$mform->addElement('text', 'customint3', get_string('maxenrolled', 'enrol_apply')); $mform->addElement('text', 'customint3', get_string('maxenrolled', 'enrol_apply'));
$mform->setType('customint3', PARAM_INT); $mform->setType('customint3', PARAM_INT);

19
lib.php

@ -397,8 +397,7 @@ class enrol_apply_plugin extends enrol_plugin {
$renderer = $PAGE->get_renderer('enrol_apply'); $renderer = $PAGE->get_renderer('enrol_apply');
$course = get_course($instance->courseid); $course = get_course($instance->courseid);
$user = core_user::get_user($userid); $applicant = core_user::get_user($userid);
$contact = core_user::get_support_user();
// Include standard user profile fields? // Include standard user profile fields?
$standarduserfields = null; $standarduserfields = null;
@ -411,8 +410,8 @@ class enrol_apply_plugin extends enrol_plugin {
$extrauserfields = null; $extrauserfields = null;
if ($instance->customint2) { if ($instance->customint2) {
require_once($CFG->dirroot.'/user/profile/lib.php'); require_once($CFG->dirroot.'/user/profile/lib.php');
profile_load_custom_fields($user); profile_load_custom_fields($applicant);
$extrauserfields = $user->profile; $extrauserfields = $applicant->profile;
} }
// Send notification to users with manageapplications in course context (instance depending)? // Send notification to users with manageapplications in course context (instance depending)?
@ -421,7 +420,7 @@ class enrol_apply_plugin extends enrol_plugin {
$manageurl = new moodle_url("/enrol/apply/manage.php", array('id' => $instance->id)); $manageurl = new moodle_url("/enrol/apply/manage.php", array('id' => $instance->id));
$content = $renderer->application_notification_mail_body( $content = $renderer->application_notification_mail_body(
$course, $course,
$user, $applicant,
$manageurl, $manageurl,
$data->applydescription, $data->applydescription,
$standarduserfields, $standarduserfields,
@ -429,7 +428,7 @@ class enrol_apply_plugin extends enrol_plugin {
foreach ($courseuserstonotify as $user) { foreach ($courseuserstonotify as $user) {
$message = new enrol_apply_notification( $message = new enrol_apply_notification(
$user, $user,
$contact, $applicant,
'application', 'application',
get_string('mailtoteacher_suject', 'enrol_apply'), get_string('mailtoteacher_suject', 'enrol_apply'),
$content, $content,
@ -448,7 +447,7 @@ class enrol_apply_plugin extends enrol_plugin {
$manageurl = new moodle_url('/enrol/apply/manage.php'); $manageurl = new moodle_url('/enrol/apply/manage.php');
$content = $renderer->application_notification_mail_body( $content = $renderer->application_notification_mail_body(
$course, $course,
$user, $applicant,
$manageurl, $manageurl,
$data->applydescription, $data->applydescription,
$standarduserfields, $standarduserfields,
@ -456,7 +455,7 @@ class enrol_apply_plugin extends enrol_plugin {
foreach ($globaluserstonotify as $user) { foreach ($globaluserstonotify as $user) {
$message = new enrol_apply_notification( $message = new enrol_apply_notification(
$user, $user,
$contact, $applicant,
'application', 'application',
get_string('mailtoteacher_suject', 'enrol_apply'), get_string('mailtoteacher_suject', 'enrol_apply'),
$content, $content,
@ -475,7 +474,7 @@ class enrol_apply_plugin extends enrol_plugin {
* @return array Array of user IDs. * @return array Array of user IDs.
*/ */
public function get_notifycoursebased_users($instance) { public function get_notifycoursebased_users($instance) {
$value = $instance->customtext2; $value = $instance->customtext3;
if (empty($value) or $value === '$@NONE@$') { if (empty($value) or $value === '$@NONE@$') {
return array(); return array();
} }
@ -508,7 +507,7 @@ class enrol_apply_plugin extends enrol_plugin {
* @return array Array of user IDs. * @return array Array of user IDs.
*/ */
public function get_notifyglobal_users() { public function get_notifyglobal_users() {
return get_users_from_config($this->get_config('notifyglobal'), 'enrol/apply:manageapplications'); return get_users_from_config($this->get_config('notifyglobal'), 'enrol/apply:manageapplications', false);
} }
private function update_mail_content($content, $course, $user, $userenrolment) { private function update_mail_content($content, $course, $user, $userenrolment) {

Loading…
Cancel
Save