Skip to content

Commit

Permalink
MDL-23502 refactoring towards separate instance config forms
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jul 31, 2010
1 parent 983fe83 commit 2d4b1f3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 51 deletions.
28 changes: 15 additions & 13 deletions enrol/instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,54 +165,56 @@

$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'))).'&nbsp;';
$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')).'&nbsp;';
$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'))).'&nbsp;';
$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'))).'&nbsp;';
$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'))).'&nbsp;';
$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')).'&nbsp;';
$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('&nbsp;', $updown), implode('&nbsp;', $edit));

}
echo html_writer::table($table);
Expand Down
51 changes: 47 additions & 4 deletions enrol/manual/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ public function get_manual_enrol_link($instance) {
throw new coding_exception('invalid enrol instance!');
}

if ($instance->courseid == SITEID) {
return NULL;
}

if (!enrol_is_enabled($name)) {
return NULL;
}
Expand All @@ -77,6 +73,53 @@ public function get_manual_enrol_link($instance) {
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
Expand Down
41 changes: 7 additions & 34 deletions lib/enrollib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,46 +1254,19 @@ public function enrol_page_hook(stdClass $instance) {
*
* @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();
}

/**
Expand Down

0 comments on commit 2d4b1f3

Please sign in to comment.