MDL-53473 tool_lp: Improvement to navigation flow of templates
This commit is contained in:
@@ -3188,7 +3188,8 @@ class external extends external_api {
|
||||
$context = self::get_context_from_params($params['pagecontext']);
|
||||
self::validate_context($context);
|
||||
|
||||
$renderable = new output\template_competencies_page($params['templateid'], $context);
|
||||
$template = api::read_template($params['templateid']);
|
||||
$renderable = new output\template_competencies_page($template, $context);
|
||||
$renderer = $PAGE->get_renderer('tool_lp');
|
||||
|
||||
$data = $renderable->export_for_template($renderer);
|
||||
@@ -3203,7 +3204,7 @@ class external extends external_api {
|
||||
*/
|
||||
public static function data_for_template_competencies_page_returns() {
|
||||
return new external_single_structure(array (
|
||||
'templateid' => new external_value(PARAM_INT, 'The current template id'),
|
||||
'template' => template_exporter::get_read_structure(),
|
||||
'pagecontextid' => new external_value(PARAM_INT, 'Context ID'),
|
||||
'canmanagecompetencyframeworks' => new external_value(PARAM_BOOL, 'User can manage competency frameworks'),
|
||||
'canmanagetemplatecompetencies' => new external_value(PARAM_BOOL, 'User can manage learning plan templates'),
|
||||
@@ -3211,6 +3212,7 @@ class external extends external_api {
|
||||
competency_summary_exporter::get_read_structure()
|
||||
),
|
||||
'manageurl' => new external_value(PARAM_LOCALURL, 'Url to the manage competencies page.'),
|
||||
'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Base URL of the plugin.'),
|
||||
'statistics' => template_statistics_exporter::get_read_structure()
|
||||
));
|
||||
|
||||
|
||||
@@ -33,7 +33,9 @@ use context_system;
|
||||
use moodle_url;
|
||||
use tool_lp\api;
|
||||
use tool_lp\external\competency_summary_exporter;
|
||||
use tool_lp\template;
|
||||
use tool_lp\template_statistics;
|
||||
use tool_lp\external\template_exporter;
|
||||
use tool_lp\external\template_statistics_exporter;
|
||||
|
||||
/**
|
||||
@@ -44,8 +46,8 @@ use tool_lp\external\template_statistics_exporter;
|
||||
*/
|
||||
class template_competencies_page implements renderable, templatable {
|
||||
|
||||
/** @var int $templateid Template id for this page. */
|
||||
protected $templateid = null;
|
||||
/** @var template $template Template for this page. */
|
||||
protected $template = null;
|
||||
|
||||
/** @var \tool_lp\competency[] $competencies List of competencies. */
|
||||
protected $competencies = array();
|
||||
@@ -68,14 +70,14 @@ class template_competencies_page implements renderable, templatable {
|
||||
/**
|
||||
* Construct this renderable.
|
||||
*
|
||||
* @param int $templateid The learning plan template id for this page.
|
||||
* @param template $template The learning plan template.
|
||||
* @param context $pagecontext The page context.
|
||||
*/
|
||||
public function __construct($templateid, context $pagecontext) {
|
||||
public function __construct(template $template, context $pagecontext) {
|
||||
$this->pagecontext = $pagecontext;
|
||||
$this->templateid = $templateid;
|
||||
$this->templatestatistics = new template_statistics($templateid);
|
||||
$this->competencies = api::list_competencies_in_template($templateid);
|
||||
$this->template = $template;
|
||||
$this->templatestatistics = new template_statistics($template->get_id());
|
||||
$this->competencies = api::list_competencies_in_template($template);
|
||||
$this->canmanagecompetencyframeworks = has_capability('tool/lp:competencymanage', $this->pagecontext);
|
||||
$this->canmanagetemplatecompetencies = has_capability('tool/lp:templatemanage', $this->pagecontext);
|
||||
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php',
|
||||
@@ -90,8 +92,8 @@ class template_competencies_page implements renderable, templatable {
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
$data = new stdClass();
|
||||
$data->template = (new template_exporter($this->template))->export($output);
|
||||
$data->pagecontextid = $this->pagecontext->id;
|
||||
$data->templateid = $this->templateid;
|
||||
$data->competencies = array();
|
||||
$contextcache = array();
|
||||
$frameworkcache = array();
|
||||
@@ -120,6 +122,8 @@ class template_competencies_page implements renderable, templatable {
|
||||
|
||||
array_push($data->competencies, $record);
|
||||
}
|
||||
|
||||
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(false);
|
||||
$data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks;
|
||||
$data->canmanagetemplatecompetencies = $this->canmanagetemplatecompetencies;
|
||||
$data->manageurl = $this->manageurl->out(true);
|
||||
|
||||
@@ -100,12 +100,14 @@ class page_helper {
|
||||
* @param moodle_url $url The current page.
|
||||
* @param \tool_lp\template $template The template, if any.
|
||||
* @param string $subtitle The title of the subpage, if any.
|
||||
* @param string $returntype The desired return page.
|
||||
* @return array With the following:
|
||||
* - Page title
|
||||
* - Page sub title
|
||||
* - Return URL (main templates page)
|
||||
* - Return URL
|
||||
*/
|
||||
public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '') {
|
||||
public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '',
|
||||
$returntype = null) {
|
||||
global $PAGE, $SITE;
|
||||
|
||||
$pagecontext = context::instance_by_id($pagecontextid);
|
||||
@@ -115,6 +117,18 @@ class page_helper {
|
||||
}
|
||||
|
||||
$templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
|
||||
$templateurl = null;
|
||||
if ($template) {
|
||||
$templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
|
||||
'templateid' => $template->get_id(),
|
||||
'pagecontextid' => $pagecontextid
|
||||
]);
|
||||
}
|
||||
|
||||
$returnurl = $templatesurl;
|
||||
if ($returntype != 'templates' && $templateurl) {
|
||||
$returnurl = $templateurl;
|
||||
}
|
||||
|
||||
$PAGE->navigation->override_active_url($templatesurl);
|
||||
$PAGE->set_context($pagecontext);
|
||||
@@ -139,15 +153,17 @@ class page_helper {
|
||||
$PAGE->set_heading($heading);
|
||||
|
||||
if (!empty($template)) {
|
||||
$PAGE->navbar->add($title);
|
||||
$PAGE->navbar->add($subtitle, $url);
|
||||
$PAGE->navbar->add($title, $templateurl);
|
||||
if (!empty($subtitle)) {
|
||||
$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);
|
||||
return array($title, $subtitle, $returnurl);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$id = optional_param('id', 0, PARAM_INT);
|
||||
$returntype = optional_param('return', null, PARAM_ALPHA);
|
||||
$pagecontextid = required_param('pagecontextid', PARAM_INT); // Reference to where we can from.
|
||||
|
||||
$template = null;
|
||||
@@ -43,15 +44,21 @@ 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));
|
||||
$url = new moodle_url("/admin/tool/lp/edittemplate.php", [
|
||||
'id' => $id,
|
||||
'pagecontextid' => $pagecontextid,
|
||||
'return' => $returntype
|
||||
]);
|
||||
|
||||
if (empty($id)) {
|
||||
$pagetitle = get_string('addnewtemplate', 'tool_lp');
|
||||
list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, null, $pagetitle);
|
||||
list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, null, $pagetitle,
|
||||
$returntype);
|
||||
} 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);
|
||||
list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template,
|
||||
$pagetitle, $returntype);
|
||||
}
|
||||
|
||||
$form = new \tool_lp\form\template($url->out(false), array('persistent' => $template, 'context' => $context));
|
||||
|
||||
@@ -44,14 +44,11 @@ if (!$template->can_read()) {
|
||||
// Set up the page.
|
||||
$url = new moodle_url('/admin/tool/lp/templatecompetencies.php', array('templateid' => $template->get_id(),
|
||||
'pagecontextid' => $pagecontextid));
|
||||
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template,
|
||||
get_string('templatecompetencies', 'tool_lp'));
|
||||
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template);
|
||||
|
||||
// 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);
|
||||
$page = new \tool_lp\output\template_competencies_page($template, $pagecontext);
|
||||
echo $output->render($page);
|
||||
echo $output->footer();
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<a href="#">{{#str}}edit{{/str}}</a><b class="caret"></b>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<a href="{{pluginbaseurl}}/edittemplate.php?id={{id}}&pagecontextid={{pagecontextid}}">
|
||||
<a href="{{pluginbaseurl}}/edittemplate.php?id={{id}}&pagecontextid={{pagecontextid}}&return=templates">
|
||||
{{#pix}}t/edit{{/pix}} {{#str}}edit{{/str}}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
Template competencies template.
|
||||
}}
|
||||
<div data-region="templatecompetenciespage">
|
||||
<h2>
|
||||
{{template.shortname}}
|
||||
{{#template.canmanage}}
|
||||
<a href="{{pluginbaseurl}}/edittemplate.php?id={{template.id}}&pagecontextid={{pagecontextid}}">{{#pix}}t/edit, core, {{#str}}edittemplate, tool_lp{{/str}}{{/pix}}</a>
|
||||
{{/template.canmanage}}
|
||||
</h2>
|
||||
<h3>{{#str}}templatecompetencies, tool_lp{{/str}}</h3>
|
||||
{{#statistics}}
|
||||
{{> tool_lp/template_statistics }}
|
||||
{{/statistics}}
|
||||
@@ -76,6 +83,6 @@
|
||||
</div>
|
||||
{{#js}}
|
||||
require(['tool_lp/competencies'], function(mod) {
|
||||
(new mod({{templateid}}, 'template', {{pagecontextid}}));
|
||||
(new mod({{template.id}}, 'template', {{pagecontextid}}));
|
||||
});
|
||||
{{/js}}
|
||||
|
||||
Reference in New Issue
Block a user