Show a link to manage templates

This commit is contained in:
Mark Nelson 2016-08-25 18:44:52 +08:00
parent 99a4c4578b
commit e341d28853
2 changed files with 23 additions and 12 deletions

View file

@ -38,15 +38,29 @@ class load_template_form extends \moodleform {
$mform =& $this->_form;
// Get the context.
$context = $this->_customdata['context'];
$mform->addElement('header', 'loadtemplateheader', get_string('loadtemplate', 'customcert'));
// Display a link to the manage templates page.
if ($context->contextlevel != CONTEXT_SYSTEM && has_capability('mod/customcert:manage', \context_system::instance())) {
$link = \html_writer::link(new \moodle_url('/mod/customcert/manage_templates.php'),
get_string('managetemplates', 'customcert'));
$mform->addElement('static', 'managetemplates', '', $link);
}
$templates = $DB->get_records_menu('customcert_templates',
array('contextid' => \context_system::instance()->id), 'name ASC', 'id, name');
$group = array();
$group[] = $mform->createElement('select', 'ltid', '', $templates);
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
$mform->setType('ltid', PARAM_INT);
if ($templates) {
$group = array();
$group[] = $mform->createElement('select', 'ltid', '', $templates);
$group[] = $mform->createElement('submit', 'loadtemplatesubmit', get_string('load', 'customcert'));
$mform->addElement('group', 'loadtemplategroup', '', $group, '', false);
$mform->setType('ltid', PARAM_INT);
} else {
$msg = \html_writer::tag('div', get_string('notemplates', 'customcert'), array('class' => 'alert'));
$mform->addElement('static', 'notemplates', '', $msg);
}
}
}

View file

@ -66,11 +66,6 @@ if ($context->contextlevel == CONTEXT_SYSTEM) {
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'));
}
// The form for loading a customcert templates.
if ($tid && $DB->count_records('customcert_templates', array('contextid' => context_system::instance()->id)) > 0) {
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl);
}
// Flag to determine if we are deleting anything.
$deleting = false;
@ -225,7 +220,9 @@ if ($data = $mform->get_data()) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
$mform->display();
if (isset($loadtemplateform)) {
if ($tid) {
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context));
$loadtemplateform->display();
}
echo $OUTPUT->footer();