Browse Source

Refactor settings

SABERES_37_STABLE
Johannes Burk 9 years ago
committed by test
parent
commit
55d7a07709
  1. 7
      apply_form.php
  2. 16
      db/upgrade.php
  3. 4
      edit_form.php
  4. 23
      lang/en/enrol_apply.php
  5. 14
      lib.php
  6. 102
      settings.php
  7. 2
      version.php

7
apply_form.php

@ -72,14 +72,11 @@ class enrol_apply_apply_form extends moodleform {
$apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'"); $apply_setting = $DB->get_records_sql("select name,value from ".$CFG->prefix."config_plugins where plugin='enrol_apply'");
($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false; if($instance->customint1){
($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false;
if($show_standard_user_profile){
useredit_shared_definition($mform, $editoroptions, $filemanageroptions,$user); useredit_shared_definition($mform, $editoroptions, $filemanageroptions,$user);
} }
if($show_extra_user_profile){ if($instance->customint2){
profile_definition($mform, $user->id); profile_definition($mform, $user->id);
} }

16
db/upgrade.php

@ -51,6 +51,22 @@ function xmldb_enrol_apply_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2016012801, 'enrol', 'apply'); upgrade_plugin_savepoint(true, 2016012801, 'enrol', 'apply');
} }
if ($oldversion < 2016042202) {
// Invert settings for showing standard and extra user profile fields.
$enrolapply = enrol_get_plugin('apply');
$showstandarduserprofile = $enrolapply->get_config('show_standard_user_profile') == 0 ? true : false;
$enrolapply->set_config('show_standard_user_profile', $showstandarduserprofile);
$showextrauserprofile = $enrolapply->get_config('show_extra_user_profile') == 0 ? true : false;
$enrolapply->set_config('show_extra_user_profile', $showextrauserprofile);
$instances = $DB->get_records('enrol', array('enrol' => 'apply'));
foreach ($instances as $instance) {
$instance->customint1 = !$instance->customint1;
$instance->customint2 = !$instance->customint2;
$DB->update_record('enrol', $instance, true);
}
}
return true; return true;
} }

4
edit_form.php

@ -26,8 +26,8 @@ class enrol_self_edit_form extends moodleform {
$mform->addElement('text', 'name', get_string('custominstancename', 'enrol')); $mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
$mform->setType('name', PARAM_TEXT); $mform->setType('name', PARAM_TEXT);
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), $options = array(1 => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); 0 => get_string('no'));
$mform->addElement('select', 'status', get_string('status', 'enrol_apply'), $options); $mform->addElement('select', 'status', get_string('status', 'enrol_apply'), $options);
//$mform->addHelpButton('status', 'status', 'enrol_apply'); //$mform->addHelpButton('status', 'status', 'enrol_apply');
$mform->setDefault('status', $plugin->get_config('status')); $mform->setDefault('status', $plugin->get_config('status'));

23
lang/en/enrol_apply.php

@ -14,16 +14,32 @@ $string['enrolname'] = 'Course enrol confirmation';
$string['pluginname'] = 'Course enrol confirmation'; $string['pluginname'] = 'Course enrol confirmation';
$string['pluginname_desc'] = 'With this plug-in users can apply to be enrolled in a course. A teacher or site manager will then have to approve the enrolment before the user gets enroled.'; $string['pluginname_desc'] = 'With this plug-in users can apply to be enrolled in a course. A teacher or site manager will then have to approve the enrolment before the user gets enroled.';
$string['confirmmail_heading'] = 'Confirmation email';
$string['confirmmail_desc'] = '';
$string['confirmmailsubject'] = 'Confirmation email subject'; $string['confirmmailsubject'] = 'Confirmation email subject';
$string['confirmmailsubject_desc'] = '';
$string['confirmmailcontent'] = 'Confirmation email content'; $string['confirmmailcontent'] = 'Confirmation email content';
$string['confirmmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username';
$string['waitmail_heading'] = 'Waiting list email';
$string['waitmail_desc'] = '';
$string['waitmailsubject'] = 'Waiting list mail subject'; $string['waitmailsubject'] = 'Waiting list mail subject';
$string['waitmailsubject_desc'] = '';
$string['waitmailcontent'] = 'Waiting list mail content'; $string['waitmailcontent'] = 'Waiting list mail content';
$string['waitmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username';
$string['cancelmail_heading'] = 'Cancelation email';
$string['cancelmail_desc'] = '';
$string['cancelmailsubject'] = 'Cancelation email subject'; $string['cancelmailsubject'] = 'Cancelation email subject';
$string['cancelmailsubject_desc'] = '';
$string['cancelmailcontent'] = 'Cancelation email content'; $string['cancelmailcontent'] = 'Cancelation email content';
$string['confirmmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username';
$string['waitmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username';
$string['cancelmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username'; $string['cancelmailcontent_desc'] = 'Please use the following special marks to replace email content with data from Moodle.<br/>{firstname}:The first name of the user; {content}:The course name;{lastname}:The last name of the user;{username}:The users registration username';
$string['notify_heading'] = 'Notification settings';
$string['notify_desc'] = 'Define who gets notified about new enrolment applications.';
$string['sendmailtoteacher'] = 'Send email notification to teachers';
$string['sendmailtomanager'] = 'Send email notification to managers';
$string['confirmusers'] = 'Enrol Confirm'; $string['confirmusers'] = 'Enrol Confirm';
$string['confirmusers_desc'] = 'Users in gray colored rows are on the waiting list.'; $string['confirmusers_desc'] = 'Users in gray colored rows are on the waiting list.';
@ -49,8 +65,7 @@ $string['apply:unenrolself'] = 'Cancel self from the course';
$string['notification'] = '<b>Enrolment application successfully sent</b>. <br/><br/>You will be informed by email when your enrolment has been confirmed.'; $string['notification'] = '<b>Enrolment application successfully sent</b>. <br/><br/>You will be informed by email when your enrolment has been confirmed.';
$string['sendmailtoteacher'] = 'Send email notification to teachers';
$string['sendmailtomanager'] = 'Send email notification to managers';
$string['mailtoteacher_suject'] = 'New Enrolment request!'; $string['mailtoteacher_suject'] = 'New Enrolment request!';
$string['editdescription'] = 'Textarea description'; $string['editdescription'] = 'Textarea description';
$string['comment'] = 'Comment'; $string['comment'] = 'Comment';

14
lib.php

@ -295,9 +295,6 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){
$courseid = $instance->courseid; $courseid = $instance->courseid;
$instanceid = $instance->id; $instanceid = $instance->id;
($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false;
($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false;
if($instance->customint3 == 1){ if($instance->customint3 == 1){
$course = get_course($courseid); $course = get_course($courseid);
$context = context_course::instance($courseid, MUST_EXIST); $context = context_course::instance($courseid, MUST_EXIST);
@ -309,7 +306,7 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){
$body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>'; $body .= '<p>'. get_string('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>'; $body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($show_standard_user_profile){ if($instance->customint1){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>'; $body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>'; $body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>'; $body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
@ -337,7 +334,7 @@ function sendConfirmMailToTeachers($instance,$info,$applydescription){
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>'; $body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
} }
if($show_extra_user_profile){ if($instance->customint2){
require_once($CFG->dirroot.'/user/profile/lib.php'); 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); profile_load_custom_fields($user);
@ -362,9 +359,6 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){
$courseid = $instance->courseid; $courseid = $instance->courseid;
($instance->customint1 == 0)?$show_standard_user_profile = true:$show_standard_user_profile = false;
($instance->customint2 == 0)?$show_extra_user_profile = true:$show_extra_user_profile = false;
if(get_config('enrol_apply', 'sendmailtomanager') == 1){ if(get_config('enrol_apply', 'sendmailtomanager') == 1){
$course = get_course($courseid); $course = get_course($courseid);
$context = context_system::instance(); $context = context_system::instance();
@ -375,7 +369,7 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){
$body = '<p>'. get_string('coursename', 'enrol_apply') .': '.format_string($course->fullname).'</p>'; $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('applyuser', 'enrol_apply') .': '.$USER->firstname.' '.$USER->lastname.'</p>';
$body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>'; $body .= '<p>'. get_string('comment', 'enrol_apply') .': '.$applydescription.'</p>';
if($show_standard_user_profile){ if($instance->customint1){
$body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>'; $body .= '<p><strong>'. get_string('user_profile', 'enrol_apply').'</strong></p>';
$body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>'; $body .= '<p>'. get_string('firstname') .': '.$info->firstname.'</p>';
$body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>'; $body .= '<p>'. get_string('lastname') .': '.$info->lastname.'</p>';
@ -403,7 +397,7 @@ function sendConfirmMailToManagers($instance,$info,$applydescription){
$body .= '<p>'. get_string('address') .': '.$info->address.'</p>'; $body .= '<p>'. get_string('address') .': '.$info->address.'</p>';
} }
if($show_extra_user_profile){ if($instance->customint2){
require_once($CFG->dirroot.'/user/profile/lib.php'); 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); profile_load_custom_fields($user);

102
settings.php

@ -13,48 +13,102 @@ defined('MOODLE_INTERNAL') || die();
if ($ADMIN->fulltree) { if ($ADMIN->fulltree) {
//--- general settings -----------------------------------------------------------------------------------
$settings->add(new admin_setting_heading('enrol_apply_enrolname','',get_string('pluginname_desc', 'enrol_apply'))); $settings->add(new admin_setting_heading('enrol_apply_enrolname','',get_string('pluginname_desc', 'enrol_apply')));
$settings->add(new admin_setting_configtext('enrol_apply/confirmmailsubject','',get_string('confirmmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); // Confirm mail settings.
$settings->add(new admin_setting_heading(
'enrol_apply_confirmmail',
get_string('confirmmail_heading', 'enrol_apply'),
get_string('confirmmail_desc', 'enrol_apply')));
$settings->add(new admin_setting_configtext(
'enrol_apply/confirmmailsubject',
get_string('confirmmailsubject', 'enrol_apply'),
get_string('confirmmailsubject_desc', 'enrol_apply'),
null,
PARAM_TEXT,
60));
$settings->add(new admin_setting_confightmleditor(
'enrol_apply/confirmmailcontent',
get_string('confirmmailcontent', 'enrol_apply'),
get_string('confirmmailcontent_desc', 'enrol_apply'),
null,
PARAM_TEXT));
$settings->add(new admin_setting_heading('enrol_apply_confirmmailcontent', '', get_string('confirmmailcontent_desc', 'enrol_apply'))); // Wait mail settings.
$settings->add(new admin_setting_confightmleditor('enrol_apply/confirmmailcontent', get_string('confirmmailcontent', 'enrol_apply'),'utf-8','')); $settings->add(new admin_setting_heading(
'enrol_apply_waitmail',
$settings->add(new admin_setting_configtext('enrol_apply/waitmailsubject','',get_string('waitmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); get_string('waitmail_heading', 'enrol_apply'),
get_string('waitmail_desc', 'enrol_apply')));
$settings->add(new admin_setting_configtext(
'enrol_apply/waitmailsubject',
get_string('waitmailsubject', 'enrol_apply'),
get_string('waitmailsubject_desc', 'enrol_apply'),
null,
PARAM_TEXT,
60));
$settings->add(new admin_setting_confightmleditor(
'enrol_apply/waitmailcontent',
get_string('waitmailcontent', 'enrol_apply'),
get_string('waitmailcontent_desc', 'enrol_apply'),
null,
PARAM_TEXT));
$settings->add(new admin_setting_heading('enrol_apply_waitmailcontent', '', get_string('waitmailcontent_desc', 'enrol_apply'))); // Cancel mail settings
$settings->add(new admin_setting_confightmleditor('enrol_apply/waitmailcontent', get_string('waitmailcontent', 'enrol_apply'),'utf-8','')); $settings->add(new admin_setting_heading(
'enrol_apply_cancelmail',
get_string('cancelmail_heading', 'enrol_apply'),
get_string('cancelmail_desc', 'enrol_apply')));
$settings->add(new admin_setting_configtext(
'enrol_apply/cancelmailsubject',
get_string('cancelmailsubject', 'enrol_apply'),
get_string('cancelmailsubject_desc', 'enrol_apply'),
null,
PARAM_TEXT,
60));
$settings->add(new admin_setting_confightmleditor(
'enrol_apply/cancelmailcontent',
get_string('cancelmailcontent', 'enrol_apply'),
get_string('cancelmailcontent_desc', 'enrol_apply'),
null,
PARAM_TEXT));
$settings->add(new admin_setting_configtext('enrol_apply/cancelmailsubject','',get_string('cancelmailsubject', 'enrol_apply'),null,PARAM_TEXT,60)); // Notification settings.
$settings->add(new admin_setting_heading(
'enrol_apply_notify',
get_string('notify_heading', 'enrol_apply'),
get_string('notify_desc', 'enrol_apply')));
$settings->add(new admin_setting_configcheckbox(
'enrol_apply/sendmailtoteacher',
get_string('sendmailtoteacher', 'enrol_apply'),
'',
0));
$settings->add(new admin_setting_configcheckbox(
'enrol_apply/sendmailtomanager',
get_string('sendmailtomanager', 'enrol_apply'),
'',
0));
$settings->add(new admin_setting_heading('enrol_apply_cancelmailcontent', '', get_string('cancelmailcontent_desc', 'enrol_apply'))); // Enrol instance defaults.
$settings->add(new admin_setting_confightmleditor('enrol_apply/cancelmailcontent', get_string('cancelmailcontent', 'enrol_apply'),'utf-8',''));
$settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher', get_string('sendmailtoteacher', 'enrol_apply'), '', 0));
$settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtomanager', get_string('sendmailtomanager', 'enrol_apply'), '', 0));
//--- enrol instance defaults ----------------------------------------------------------------------------
$settings->add(new admin_setting_heading('enrol_manual_defaults', $settings->add(new admin_setting_heading('enrol_manual_defaults',
get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin'))); get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));
$settings->add(new admin_setting_configcheckbox('enrol_apply/defaultenrol', $settings->add(new admin_setting_configcheckbox('enrol_apply/defaultenrol',
get_string('defaultenrol', 'enrol'), get_string('defaultenrol_desc', 'enrol'), 0)); get_string('defaultenrol', 'enrol'), get_string('defaultenrol_desc', 'enrol'), 0));
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); ENROL_INSTANCE_DISABLED => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/status', $settings->add(new admin_setting_configselect('enrol_apply/status',
get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), ENROL_INSTANCE_ENABLED, $options)); get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), ENROL_INSTANCE_ENABLED, $options));
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), $options = array(1 => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); 0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/show_standard_user_profile', $settings->add(new admin_setting_configselect('enrol_apply/show_standard_user_profile',
get_string('show_standard_user_profile', 'enrol_apply'), '', ENROL_INSTANCE_ENABLED, $options)); get_string('show_standard_user_profile', 'enrol_apply'), '', 1, $options));
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), $options = array(1 => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); 0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/show_extra_user_profile', $settings->add(new admin_setting_configselect('enrol_apply/show_extra_user_profile',
get_string('show_extra_user_profile', 'enrol_apply'), '', ENROL_INSTANCE_ENABLED, $options)); get_string('show_extra_user_profile', 'enrol_apply'), '', 1, $options));
if (!during_initial_install()) { if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance()); $options = get_default_enrol_roles(context_system::instance());

2
version.php

@ -19,7 +19,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016042201; $plugin->version = 2016042202;
$plugin->requires = 2011080100; $plugin->requires = 2011080100;
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Enrolment upon approval plugin Version 3.0-d'; $plugin->release = 'Enrolment upon approval plugin Version 3.0-d';

Loading…
Cancel
Save