Skip to content

Commit

Permalink
MDL-49439 enrol: Allow quick adding several instances
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Mar 17, 2015
1 parent 06122e4 commit fc77f56
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
8 changes: 8 additions & 0 deletions enrol/cohort/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

$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);
Expand Down Expand Up @@ -91,6 +92,10 @@
$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);
Expand All @@ -102,5 +107,8 @@
$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();
17 changes: 15 additions & 2 deletions enrol/cohort/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -97,12 +97,25 @@ function definition() {
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;

Expand Down
12 changes: 11 additions & 1 deletion enrol/meta/addinstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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);
Expand All @@ -52,14 +53,23 @@
} 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);
$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();
15 changes: 14 additions & 1 deletion enrol/meta/addinstance_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,24 @@ function definition() {
$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;

Expand Down
2 changes: 2 additions & 0 deletions lang/en/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...';
Expand Down Expand Up @@ -83,6 +84,7 @@
$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';
Expand Down

0 comments on commit fc77f56

Please sign in to comment.