Browse Source

Merge pull request #3 from emeneo/dev-defaultenrol

default enrol and role options
develop_fields
Johannes Burk 11 years ago
parent
commit
bd548d79c3
  1. 9
      edit.php
  2. 12
      edit_form.php
  3. 1
      lang/de/enrol_apply.php
  4. 3
      lang/en/enrol_apply.php
  5. 13
      lib.php
  6. 19
      settings.php

9
edit.php

@ -66,10 +66,11 @@ if ($mform->is_cancelled()) {
$DB->update_record('enrol', $instance); $DB->update_record('enrol', $instance);
} else { } else {
// $fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2, $fields = array(
// 'customint3'=>$data->customint3, 'customint4'=>$data->customint4, 'customtext1'=>$data->customtext1, 'status' =>$data->status,
// 'roleid'=>$data->roleid, 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate); 'name' =>$data->name,
$fields = array('status'=>$data->status, 'name'=>$data->name, 'customtext1'=>$data->customtext1); 'roleid' => $data->roleid,
'customtext1' =>$data->customtext1);
$plugin->add_instance($course, $fields); $plugin->add_instance($course, $fields);
} }

12
edit_form.php

@ -25,9 +25,21 @@ 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(ENROL_INSTANCE_ENABLED => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no')); ENROL_INSTANCE_DISABLED => 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->setDefault('status', $plugin->get_config('status'));
if ($instance->id) {
$roles = get_default_enrol_roles($context, $instance->roleid);
} else {
$roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
}
$mform->addElement('select', 'roleid', get_string('defaultrole', 'role'), $roles);
$mform->setDefault('roleid', $plugin->get_config('roleid'));
$mform->addElement('textarea', 'customtext1', get_string('editdescription', 'enrol_apply')); $mform->addElement('textarea', 'customtext1', get_string('editdescription', 'enrol_apply'));

1
lang/de/enrol_apply.php

@ -36,4 +36,5 @@ $string['apply:unenrolapply'] = 'Sich selbst aus dem Kurs entfernen';
$string['description'] = ''; $string['description'] = '';
$string['notification'] = '<b>Einschreibungsantrag wurde erfolgreich gesendet.</b>. <br/><br/>Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde. Wenn Sie sich in andere Kurse einschreiben wollen, klicken Sie bitte den "Kurskatalog" im Hauptmenu an.'; $string['notification'] = '<b>Einschreibungsantrag wurde erfolgreich gesendet.</b>. <br/><br/>Sie werden via Mail informiert, sobald Ihre Einschreibung bestätigt wurde. Wenn Sie sich in andere Kurse einschreiben wollen, klicken Sie bitte den "Kurskatalog" im Hauptmenu an.';
$string['status_desc'] = 'Kurszugriff für intern eingeschriebene Nutzer/innen erlauben.';
?> ?>

3
lang/en/enrol_apply.php

@ -50,4 +50,7 @@ $string['mailtoteacher_suject'] = 'New Enrollment request!';
$string['setting_edit'] = 'Edit'; $string['setting_edit'] = 'Edit';
$string['editdescription'] = 'Textarea description'; $string['editdescription'] = 'Textarea description';
$string['applymanage'] = 'Manage enrolment applications'; $string['applymanage'] = 'Manage enrolment applications';
$string['status_desc'] = 'Allow course access of internally enrolled users.';
?> ?>

13
lib.php

@ -11,6 +11,19 @@
*/ */
class enrol_apply_plugin extends enrol_plugin { class enrol_apply_plugin extends enrol_plugin {
/**
* Add new instance of enrol plugin with default settings.
* @param object $course
* @return int id of new instance
*/
public function add_default_instance($course) {
$fields = array(
'status' => $this->get_config('status'),
'roleid' => $this->get_config('roleid', 0)
);
return $this->add_instance($course, $fields);
}
public function allow_unenrol(stdClass $instance) { public function allow_unenrol(stdClass $instance) {
// users with unenrol cap may unenrol other users manually manually // users with unenrol cap may unenrol other users manually manually
return true; return true;

19
settings.php

@ -27,6 +27,25 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher', $settings->add(new admin_setting_configcheckbox('enrol_apply/sendmailtoteacher',
get_string('sendmailtoteacher', 'enrol_apply'), '', 0)); get_string('sendmailtoteacher', 'enrol_apply'), '', 0));
//--- enrol instance defaults ----------------------------------------------------------------------------
$settings->add(new admin_setting_heading('enrol_manual_defaults',
get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));
$settings->add(new admin_setting_configcheckbox('enrol_apply/defaultenrol',
get_string('defaultenrol', 'enrol'), get_string('defaultenrol_desc', 'enrol'), 0));
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
ENROL_INSTANCE_DISABLED => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/status',
get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), ENROL_INSTANCE_ENABLED, $options));
if (!during_initial_install()) {
$options = get_default_enrol_roles(context_system::instance());
$student = get_archetype_roles('student');
$student = reset($student);
$settings->add(new admin_setting_configselect('enrol_apply/roleid',
get_string('defaultrole', 'role'), '', $student->id, $options));
}
} }
if ($hassiteconfig) { // needs this condition or there is error on login page if ($hassiteconfig) { // needs this condition or there is error on login page

Loading…
Cancel
Save