MDL-23502 refactoring towards separate instance config forms
This commit is contained in:
+15
-13
@@ -165,54 +165,56 @@ foreach ($instances as $instance) {
|
||||
|
||||
$users = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id));
|
||||
|
||||
$updown = '';
|
||||
$edit = '';
|
||||
$updown = array();
|
||||
$edit = array();
|
||||
|
||||
if ($canconfig) {
|
||||
// up/down link
|
||||
$updown = '';
|
||||
if ($updowncount > 1) {
|
||||
$aurl = new moodle_url($url, array('action'=>'up', 'instance'=>$instance->id));
|
||||
$updown .= html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/up'), 'alt'=>$strup, 'class'=>'smallicon'))).' ';
|
||||
$updown[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/up'), 'alt'=>$strup, 'class'=>'smallicon')));
|
||||
} else {
|
||||
$updown .= html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('spacer'), 'alt'=>'', 'class'=>'smallicon')).' ';
|
||||
$updown[] = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('spacer'), 'alt'=>'', 'class'=>'smallicon'));
|
||||
}
|
||||
if ($updowncount < $icount) {
|
||||
$aurl = new moodle_url($url, array('action'=>'down', 'instance'=>$instance->id));
|
||||
$updown .= html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/down'), 'alt'=>$strdown, 'class'=>'smallicon'))).' ';
|
||||
$updown[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/down'), 'alt'=>$strdown, 'class'=>'smallicon')));
|
||||
} else {
|
||||
$updown .= html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('spacer'), 'alt'=>'', 'class'=>'smallicon')).' ';
|
||||
$updown[] = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('spacer'), 'alt'=>'', 'class'=>'smallicon'));
|
||||
}
|
||||
++$updowncount;
|
||||
|
||||
// edit links
|
||||
if ($plugin->instance_deleteable($instance)) {
|
||||
$aurl = new moodle_url($url, array('action'=>'delete', 'instance'=>$instance->id));
|
||||
$edit .= html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>$strdelete, 'class'=>'smallicon'))).' ';
|
||||
$edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/delete'), 'alt'=>$strdelete, 'class'=>'smallicon')));
|
||||
}
|
||||
|
||||
if (enrol_is_enabled($instance->enrol)) {
|
||||
if ($instance->status == ENROL_INSTANCE_ENABLED) {
|
||||
$aurl = new moodle_url($url, array('action'=>'disable', 'instance'=>$instance->id));
|
||||
$edit .= html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/hide'), 'alt'=>$strdisable, 'class'=>'smallicon'))).' ';
|
||||
$edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/hide'), 'alt'=>$strdisable, 'class'=>'smallicon')));
|
||||
} else if ($instance->status == ENROL_INSTANCE_DISABLED) {
|
||||
$aurl = new moodle_url($url, array('action'=>'enable', 'instance'=>$instance->id));
|
||||
$edit .= html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>$strenable, 'class'=>'smallicon'))).' ';
|
||||
$edit[] = html_writer::link($aurl, html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>$strenable, 'class'=>'smallicon')));
|
||||
} else {
|
||||
// plugin specific state - do not mess with it!
|
||||
$edit .= html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>'', 'class'=>'smallicon')).' ';
|
||||
$edit[] = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('t/show'), 'alt'=>'', 'class'=>'smallicon'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// link to instance management
|
||||
if ($managelink = $plugin->get_manage_link($instance)) {
|
||||
$displayname = html_writer::link($managelink, $displayname);
|
||||
if (enrol_is_enabled($instance->enrol)) {
|
||||
if ($icons = $plugin->get_action_icons($instance)) {
|
||||
$edit = array_merge($edit, $icons);
|
||||
}
|
||||
}
|
||||
|
||||
// add a row to the table
|
||||
$table->data[] = array($displayname, $users, $updown, $edit);
|
||||
$table->data[] = array($displayname, $users, implode(' ', $updown), implode(' ', $edit));
|
||||
|
||||
}
|
||||
echo html_writer::table($table);
|
||||
|
||||
+47
-4
@@ -60,10 +60,6 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
throw new coding_exception('invalid enrol instance!');
|
||||
}
|
||||
|
||||
if ($instance->courseid == SITEID) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!enrol_is_enabled($name)) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -77,6 +73,53 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
return new moodle_url('/enrol/manual/manage.php', array('enrolid'=>$instance->id, 'id'=>$instance->courseid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns enrolment instance manage link.
|
||||
*
|
||||
* By defaults looks for manage.php file and tests for manage capability.
|
||||
*
|
||||
* @param object $instance
|
||||
* @return moodle_url;
|
||||
*/
|
||||
public function add_course_navigation($instancesnode, stdClass $instance) {
|
||||
$name = $this->get_name();
|
||||
|
||||
if ($instance->enrol !== $name) {
|
||||
throw new coding_exception('Invalid enrol instance type!');
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
|
||||
if (!has_capability('enrol/manual:manage', $context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$managelink = new moodle_url("/enrol/$name/manage.php", array('enrolid'=>$instance->id));
|
||||
$instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns edit icons for the page with list of instances
|
||||
* @param stdClass $instance
|
||||
* @return array
|
||||
*/
|
||||
public function get_action_icons(stdClass $instance) {
|
||||
global $OUTPUT;
|
||||
|
||||
$name = $this->get_name();
|
||||
if ($instance->enrol !== $name) {
|
||||
throw new coding_exception('invalid enrol instance!');
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
|
||||
if (!has_capability('enrol/manual:manage', $context)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$managelink = new moodle_url("/enrol/$name/manage.php", array('enrolid'=>$instance->id));
|
||||
$icon = $OUTPUT->action_icon($managelink, new pix_icon('i/users', get_string('enrolusers', 'enrol_manual'), 'core', array('class'=>'iconsmall')));
|
||||
return array($icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns link to page which may be used to add new instance of enrolment plugin in course.
|
||||
* @param int $courseid
|
||||
|
||||
+7
-34
@@ -1254,46 +1254,19 @@ abstract class enrol_plugin {
|
||||
*
|
||||
* @param navigation_node $instancesnode
|
||||
* @param object $instance
|
||||
* @return moodle_url;
|
||||
* @return void
|
||||
*/
|
||||
public function add_course_navigation($instancesnode, stdClass $instance) {
|
||||
if ($managelink = $this->get_manage_link($instance)) {
|
||||
$instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
// usually adds manage users
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns enrolment instance manage link.
|
||||
*
|
||||
* By defaults looks for manage.php file and tests for manage capability.
|
||||
*
|
||||
* @param object $instance
|
||||
* @return moodle_url;
|
||||
* Returns edit icons for the page with list of instances
|
||||
* @param stdClass $instance
|
||||
* @return array
|
||||
*/
|
||||
public function get_manage_link($instance) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$name = $this->get_name();
|
||||
|
||||
if ($instance->enrol !== $name) {
|
||||
throw new coding_exception('Invalid enrol instance type!');
|
||||
}
|
||||
|
||||
if (!file_exists("$CFG->dirroot/enrol/$name/manage.php")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($instance->courseid == SITEID) {
|
||||
// no enrolments on the frontpage, only roles there allowed
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $instance->courseid);
|
||||
if (!has_capability('enrol/'.$name.':manage', $context)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new moodle_url("/enrol/$name/manage.php", array('enrolid'=>$instance->id));
|
||||
public function get_action_icons(stdClass $instance) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user