MDL-49439 enrol: Allow quick adding several instances
This commit is contained in:
@@ -29,6 +29,7 @@ require_once("$CFG->dirroot/group/lib.php");
|
||||
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$instanceid = optional_param('id', 0, PARAM_INT);
|
||||
$message = optional_param('message', null, PARAM_TEXT);
|
||||
|
||||
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
|
||||
$context = context_course::instance($course->id, MUST_EXIST);
|
||||
@@ -91,6 +92,10 @@ if ($mform->is_cancelled()) {
|
||||
$DB->update_record('enrol', $instance);
|
||||
} else {
|
||||
$enrol->add_instance($course, array('name'=>$data->name, 'status'=>$data->status, 'customint1'=>$data->customint1, 'roleid'=>$data->roleid, 'customint2'=>$data->customint2));
|
||||
if (!empty($data->submitbuttonnext)) {
|
||||
$returnurl = new moodle_url($PAGE->url);
|
||||
$returnurl->param('message', 'added');
|
||||
}
|
||||
}
|
||||
$trace = new null_progress_trace();
|
||||
enrol_cohort_sync($trace, $course->id);
|
||||
@@ -102,5 +107,8 @@ $PAGE->set_heading($course->fullname);
|
||||
$PAGE->set_title(get_string('pluginname', 'enrol_cohort'));
|
||||
|
||||
echo $OUTPUT->header();
|
||||
if ($message === 'added') {
|
||||
echo $OUTPUT->notification(get_string('instanceadded', 'enrol'), 'notifysuccess');
|
||||
}
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -31,7 +31,7 @@ class enrol_cohort_edit_form extends moodleform {
|
||||
function definition() {
|
||||
global $CFG, $DB;
|
||||
|
||||
$mform = $this->_form;
|
||||
$mform = $this->_form;
|
||||
|
||||
list($instance, $plugin, $course) = $this->_customdata;
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
@@ -97,12 +97,25 @@ class enrol_cohort_edit_form extends moodleform {
|
||||
if ($instance->id) {
|
||||
$this->add_action_buttons(true);
|
||||
} else {
|
||||
$this->add_action_buttons(true, get_string('addinstance', 'enrol'));
|
||||
$this->add_add_buttons();
|
||||
}
|
||||
|
||||
$this->set_data($instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds buttons on create new method form
|
||||
*/
|
||||
protected function add_add_buttons() {
|
||||
$mform = $this->_form;
|
||||
$buttonarray = array();
|
||||
$buttonarray[0] = $mform->createElement('submit', 'submitbutton', get_string('addinstance', 'enrol'));
|
||||
$buttonarray[1] = $mform->createElement('submit', 'submitbuttonnext', get_string('addinstanceanother', 'enrol'));
|
||||
$buttonarray[2] = $mform->createElement('cancel');
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
$mform->closeHeaderBefore('buttonar');
|
||||
}
|
||||
|
||||
function validation($data, $files) {
|
||||
global $DB;
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ require_once("$CFG->dirroot/enrol/meta/addinstance_form.php");
|
||||
require_once("$CFG->dirroot/enrol/meta/locallib.php");
|
||||
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$message = optional_param('message', null, PARAM_TEXT);
|
||||
|
||||
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
|
||||
$context = context_course::instance($course->id, MUST_EXIST);
|
||||
@@ -52,7 +53,12 @@ if ($mform->is_cancelled()) {
|
||||
} else if ($data = $mform->get_data()) {
|
||||
$eid = $enrol->add_instance($course, array('customint1'=>$data->link));
|
||||
enrol_meta_sync($course->id);
|
||||
redirect(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
|
||||
if (!empty($data->submitbuttonnext)) {
|
||||
redirect(new moodle_url('/enrol/meta/addinstance.php',
|
||||
array('id' => $course->id, 'message' => 'added')));
|
||||
} else {
|
||||
redirect(new moodle_url('/enrol/instances.php', array('id' => $course->id)));
|
||||
}
|
||||
}
|
||||
|
||||
$PAGE->set_heading($course->fullname);
|
||||
@@ -60,6 +66,10 @@ $PAGE->set_title(get_string('pluginname', 'enrol_meta'));
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if ($message === 'added') {
|
||||
echo $OUTPUT->notification(get_string('instanceadded', 'enrol'), 'notifysuccess');
|
||||
}
|
||||
|
||||
$mform->display();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -72,11 +72,24 @@ class enrol_meta_addinstance_form extends moodleform {
|
||||
$mform->addElement('hidden', 'id', null);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$this->add_action_buttons(true, get_string('addinstance', 'enrol'));
|
||||
$this->add_add_buttons();
|
||||
|
||||
$this->set_data(array('id'=>$course->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds buttons on create new method form
|
||||
*/
|
||||
protected function add_add_buttons() {
|
||||
$mform = $this->_form;
|
||||
$buttonarray = array();
|
||||
$buttonarray[0] = $mform->createElement('submit', 'submitbutton', get_string('addinstance', 'enrol'));
|
||||
$buttonarray[1] = $mform->createElement('submit', 'submitbuttonnext', get_string('addinstanceanother', 'enrol'));
|
||||
$buttonarray[2] = $mform->createElement('cancel');
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
$mform->closeHeaderBefore('buttonar');
|
||||
}
|
||||
|
||||
function validation($data, $files) {
|
||||
global $DB, $CFG;
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
$string['actenrolshhdr'] = 'Available course enrolment plugins';
|
||||
$string['addinstance'] = 'Add method';
|
||||
$string['addinstanceanother'] = 'Add method and create another';
|
||||
$string['ajaxoneuserfound'] = '1 user found';
|
||||
$string['ajaxxusersfound'] = '{$a} users found';
|
||||
$string['ajaxnext25'] = 'Next 25...';
|
||||
@@ -83,6 +84,7 @@ $string['expirythreshold'] = 'Notification threshold';
|
||||
$string['expirythreshold_help'] = 'How long before enrolment expiry should users be notified?';
|
||||
$string['finishenrollingusers'] = 'Finish enrolling users';
|
||||
$string['foundxcohorts'] = 'Found {$a} cohorts';
|
||||
$string['instanceadded'] = 'Method added';
|
||||
$string['instanceeditselfwarning'] = 'Warning:';
|
||||
$string['instanceeditselfwarningtext'] = 'You are enrolled into this course through this enrolment method, changes may affect your access to this course.';
|
||||
$string['invalidenrolinstance'] = 'Invalid enrolment instance';
|
||||
|
||||
Reference in New Issue
Block a user