Skip to content

Commit

Permalink
MDL-53473 tool_lp: Improvement to navigation flow of templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 18, 2016
1 parent 85a719e commit f864aa4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
6 changes: 4 additions & 2 deletions admin/tool/lp/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -3188,7 +3188,8 @@ public static function data_for_template_competencies_page($templateid, $pagecon
$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);
Expand All @@ -3203,14 +3204,15 @@ public static function data_for_template_competencies_page($templateid, $pagecon
*/
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'),
'competencies' => new external_multiple_structure(
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()
));

Expand Down
20 changes: 12 additions & 8 deletions admin/tool/lp/classes/output/template_competencies_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
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;

/**
Expand All @@ -44,8 +46,8 @@
*/
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();
Expand All @@ -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',
Expand All @@ -90,8 +92,8 @@ public function __construct($templateid, context $pagecontext) {
*/
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();
Expand Down Expand Up @@ -120,6 +122,8 @@ public function export_for_template(renderer_base $output) {

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);
Expand Down
26 changes: 21 additions & 5 deletions admin/tool/lp/classes/page_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ public static function setup_for_course(moodle_url $url, $course, $subtitle = ''
* @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);
Expand All @@ -115,6 +117,18 @@ public static function setup_for_template($pagecontextid, moodle_url $url, $temp
}

$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);
Expand All @@ -139,15 +153,17 @@ public static function setup_for_template($pagecontextid, moodle_url $url, $temp
$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);
}

/**
Expand Down
13 changes: 10 additions & 3 deletions admin/tool/lp/edittemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand All @@ -43,15 +44,21 @@
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));
Expand Down
7 changes: 2 additions & 5 deletions admin/tool/lp/templatecompetencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@
// 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();
2 changes: 1 addition & 1 deletion admin/tool/lp/templates/manage_templates_page.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}&amp;pagecontextid={{pagecontextid}}">
<a href="{{pluginbaseurl}}/edittemplate.php?id={{id}}&amp;pagecontextid={{pagecontextid}}&amp;return=templates">
{{#pix}}t/edit{{/pix}} {{#str}}edit{{/str}}
</a>
</li>
Expand Down
9 changes: 8 additions & 1 deletion admin/tool/lp/templates/template_competencies_page.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
Template competencies template.
}}
<div data-region="templatecompetenciespage">
<h2>
{{template.shortname}}
{{#template.canmanage}}
<a href="{{pluginbaseurl}}/edittemplate.php?id={{template.id}}&amp;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}}
Expand Down Expand Up @@ -76,6 +83,6 @@
</div>
{{#js}}
require(['tool_lp/competencies'], function(mod) {
(new mod({{templateid}}, 'template', {{pagecontextid}}));
(new mod({{template.id}}, 'template', {{pagecontextid}}));
});
{{/js}}

0 comments on commit f864aa4

Please sign in to comment.