*/
public function definition() {
$mform = $this->_form;
- $id = $this->_customdata['id'];
+ $template = $this->_customdata['template'];
+ if (empty($template)) {
+ $id = 0;
+ } else {
+ $id = $template->get_id();
+ }
$context = $this->_customdata['context'];
$mform->addElement('hidden', 'id');
$this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
- if (!empty($id)) {
- if (!$this->is_submitted()) {
- $template = api::read_template($id);
- $record = $template->to_record();
- // Massage for editor API.
- $record->description = array('text' => $record->description, 'format' => $record->descriptionformat);
- $this->set_data($record);
- }
+ if (!$this->is_submitted() && !empty($template)) {
+ $record = $template->to_record();
+ // Massage for editor API.
+ $record->description = array('text' => $record->description, 'format' => $record->descriptionformat);
+ $this->set_data($record);
}
}
return parent::render_from_template('tool_lp/related_competencies', $data);
}
+ /**
+ * Render the template plans page.
+ *
+ * @param renderable $page
+ * @return string
+ */
+ public function render_template_plans_page(renderable $page) {
+ return $page->table->out(50, true);
+ }
+
}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Template plans renderable.
+ *
+ * @package tool_lp
+ * @copyright 2015 Frédéric Massart - FMCorz.net
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_lp\output;
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Template plans renderable.
+ *
+ * @package tool_lp
+ * @copyright 2015 Frédéric Massart - FMCorz.net
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class template_plans_page implements \renderable {
+
+ public function __construct(\tool_lp\template $template, \moodle_url $url) {
+ $this->template = $template;
+ $this->url = $url;
+ $this->table = new template_plans_table('tplplans', $template);
+ $this->table->define_baseurl($url);
+ }
+
+}
--- /dev/null
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page helper.
+ *
+ * @package tool_lp
+ * @copyright 2015 Frédéric Massart - FMCorz.net
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_lp;
+defined('MOODLE_INTERNAL') || die();
+
+use coding_exception;
+use context;
+use moodle_url;
+
+/**
+ * Page helper.
+ *
+ * @package tool_lp
+ * @copyright 2015 Frédéric Massart - FMCorz.net
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class page_helper {
+
+ /**
+ * Set-up a template page.
+ *
+ * Example:
+ * list($title, $subtitle) = page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle);
+ * echo $OUTPUT->heading($title);
+ * echo $OUTPUT->heading($subtitle, 3);
+ *
+ * @param int $pagecontextid The page context ID.
+ * @param moodle_url $url The current page.
+ * @param \tool_lp\template $template The template, if any.
+ * @param string $subpage The title of the subpage, if any.
+ * @return array With the following:
+ * - Page title
+ * - Page sub title
+ * - Return URL (main templates page)
+ */
+ public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '') {
+ global $PAGE, $SITE;
+
+ $pagecontext = context::instance_by_id($pagecontextid);
+ $context = $pagecontext;
+ if (!empty($template)) {
+ $context = $template->get_context();
+ }
+
+ $templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
+
+ $PAGE->navigation->override_active_url($templatesurl);
+ $PAGE->set_context($pagecontext);
+
+ if (!empty($template)) {
+ $title = format_string($template->get_shortname(), true, array('context' => $context));
+ } else {
+ $title = get_string('templates', 'tool_lp');
+ }
+
+ if ($pagecontext->contextlevel == CONTEXT_SYSTEM) {
+ $heading = $SITE->fullname;
+ } else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) {
+ $heading = $pagecontext->get_context_name();
+ } else {
+ throw new coding_exception('Unexpected context!');
+ }
+
+ $PAGE->set_pagelayout('admin');
+ $PAGE->set_url($url);
+ $PAGE->set_title($title);
+ $PAGE->set_heading($heading);
+
+ if (!empty($template)) {
+ $PAGE->navbar->add($title);
+ $PAGE->navbar->add($subtitle, $url);
+
+ } else if (!empty($subtitle)) {
+ // We're in a sub page without a specific template.
+ $PAGE->navbar->add($subtitle, $url);
+ }
+
+ return array($title, $subtitle, $templatesurl);
+ }
+}
$id = optional_param('id', 0, PARAM_INT);
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to where we can from.
+$template = null;
if (!empty($id)) {
// Always use the context from the framework when it exists.
$template = new \tool_lp\template($id);
}
// We check that we have the permission to edit this framework, in its own context.
-require_login();
+require_login(0, false);
require_capability('tool/lp:templatemanage', $context);
// We keep the original context in the URLs, so that we remain in the same context.
$url = new moodle_url("/admin/tool/lp/edittemplate.php", array('id' => $id, 'pagecontextid' => $pagecontextid));
-$templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
$formurl = new moodle_url("/admin/tool/lp/edittemplate.php", array('pagecontextid' => $pagecontextid));
-$title = get_string('templates', 'tool_lp');
if (empty($id)) {
$pagetitle = get_string('addnewtemplate', 'tool_lp');
+ list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, null, $pagetitle);
} else {
+ $template = \tool_lp\api::read_template($id);
$pagetitle = get_string('edittemplate', 'tool_lp');
+ list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle);
}
-// Set up the page.
-$PAGE->navigation->override_active_url($templatesurl);
-$PAGE->set_context(context::instance_by_id($pagecontextid));
-$PAGE->set_pagelayout('admin');
-$PAGE->set_url($url);
-$PAGE->set_title($title);
-$PAGE->set_heading($title);
-$output = $PAGE->get_renderer('tool_lp');
-
-$form = new \tool_lp\form\template($formurl->out(false), array('id' => $id, 'context' => $context));
+$form = new \tool_lp\form\template($formurl->out(false), array('template' => $template, 'context' => $context));
if ($form->is_cancelled()) {
- redirect($templatesurl);
+ redirect($returnurl);
}
+$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
-echo $output->heading($pagetitle);
+echo $output->heading($title);
+if (!empty($subtitle)) {
+ echo $output->heading($subtitle, 3);
+}
$data = $form->get_data();
if ($data) {
$data->contextid = $context->id;
\tool_lp\api::create_template($data);
echo $output->notification(get_string('templatecreated', 'tool_lp'), 'notifysuccess');
- echo $output->continue_button($templatesurl);
+ echo $output->continue_button($returnurl);
} else {
require_sesskey();
\tool_lp\api::update_template($data);
echo $output->notification(get_string('templateupdated', 'tool_lp'), 'notifysuccess');
- echo $output->continue_button($templatesurl);
+ echo $output->continue_button($returnurl);
}
} else {
$form->display();
$pagecontextid = required_param('pagecontextid', PARAM_INT);
$context = context::instance_by_id($pagecontextid);
-$url = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
-
-require_login();
+require_login(0, false);
require_capability('tool/lp:templatemanage', $context);
-$title = get_string('learningplans', 'tool_lp');
-$pagetitle = get_string('templates', 'tool_lp');
+$url = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
+list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url);
-// Set up the page.
-$PAGE->set_context($context);
-$PAGE->set_pagelayout('admin');
-$PAGE->set_url($url);
-$PAGE->set_title($title);
-$PAGE->set_heading($title);
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
-echo $output->heading($pagetitle);
-
+echo $output->heading($title);
$page = new \tool_lp\output\manage_templates_page($context);
echo $output->render($page);
-
echo $output->footer();
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from.
require_login(0, false);
-if (isguestuser()) {
- throw new require_login_exception('Guests are not allowed here.');
-}
-$pagecontext = context::instance_by_id($pagecontextid);
$template = \tool_lp\api::read_template($id);
$context = $template->get_context();
require_capability('tool/lp:templatemanage', $context);
'id' => $id,
'pagecontextid' => $pagecontextid
));
-$templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
-
-$PAGE->navigation->override_active_url($templatesurl);
-$PAGE->set_context($pagecontext);
-
-$title = get_string('userplans', 'tool_lp');
-$templatename = format_string($template->get_shortname(), true, array('context' => $context));
-
-$PAGE->set_pagelayout('admin');
-$PAGE->set_url($url);
-$PAGE->set_title($title);
-$PAGE->set_heading($templatename);
-$PAGE->navbar->add($templatename, $url);
+list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, get_string('userplans', 'tool_lp'));
// Display the page.
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
-
-$tpl = new \tool_lp\output\template_plans_table('tplplans', $template);
-$tpl->define_baseurl($url);
-echo $tpl->out(50, true);
-
+echo $output->heading($subtitle, 3);
+$page = new \tool_lp\output\template_plans_page($template, $url);
+echo $output->render($page);
echo $output->footer();
$templateid = required_param('templateid', PARAM_INT);
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to the context we came from.
-require_login();
+require_login(0, false);
$pagecontext = context::instance_by_id($pagecontextid);
$template = \tool_lp\api::read_template($templateid);
// Set up the page.
$url = new moodle_url('/admin/tool/lp/templatecompetencies.php', array('templateid' => $template->get_id(),
'pagecontextid' => $pagecontextid));
-$templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
-
-$PAGE->navigation->override_active_url($templatesurl);
-$PAGE->set_context($pagecontext);
-
-$title = get_string('templatecompetencies', 'tool_lp');
-$templatename = format_text($template->get_shortname());
-
-$PAGE->set_pagelayout('admin');
-$PAGE->set_url($url);
-$PAGE->set_title($title);
-$PAGE->set_heading($templatename);
-$PAGE->navbar->add($templatename, $url);
+list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template,
+ get_string('templatecompetencies', 'tool_lp'));
// Display the page.
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
+echo $output->heading($subtitle, 3);
$page = new \tool_lp\output\template_competencies_page($template->get_id(), $pagecontext);
echo $output->render($page);
echo $output->footer();