Skip to content

Commit

Permalink
MDL-53700 competency: Implementing a URL resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 18, 2016
1 parent d837090 commit 07fc0ec
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 59 deletions.
105 changes: 105 additions & 0 deletions admin/tool/lp/classes/url_resolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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/>.

/**
* URL resolver.
*
* @package tool_lp
* @copyright 2016 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 moodle_url;

/**
* URL resolver class.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class url_resolver {

/**
* The URL where the frameworks can be found.
*
* @param int $pagecontextid The ID of the context that we are browsing.
* @return moodle_url
*/
public function frameworks($pagecontextid) {
return new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid));
}

/**
* The URL where the plan can be found.
*
* @param int $planid The plan ID.
* @return moodle_url
*/
public function plan($planid) {
return new moodle_url('/admin/tool/lp/plan.php', array('id' => $planid));
}

/**
* The URL where the plans of a user can be found.
*
* @param int $userid The user ID.
* @return moodle_url
*/
public function plans($userid) {
return new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
}

/**
* The URL where the user competency can be found.
*
* @param int $usercompetency The user competency ID
* @return moodle_url
*/
public function user_competency($usercompetencyid) {
return new moodle_url('/admin/tool/lp/user_competency.php', array('id' => $usercompetencyid));
}

/**
* The URL where the user competency can be found in the context of a plan.
*
* @param int $userid The user ID
* @param int $competencyid The competency ID.
* @param int $planid The plan ID.
* @return moodle_url
*/
public function user_competency_in_plan($userid, $competencyid, $planid) {
return new moodle_url('/admin/tool/lp/user_competency_in_plan.php', array(
'userid' => $userid,
'competencyid' => $competencyid,
'planid' => $planid
));
}

/**
* The URL where the user evidence (of prior learning) can be found.
*
* @param int $usercompetency The user evidence ID
* @return moodle_url
*/
public function user_evidence($userevidenceid) {
return new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $userevidenceid));
}

}
4 changes: 2 additions & 2 deletions admin/tool/lp/user_evidence.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
}
\core_competency\api::require_enabled();

$id = optional_param('id', null, PARAM_INT);
$id = required_param('id', PARAM_INT);

$userevidence = \core_competency\api::read_user_evidence($id);
$url = new moodle_url('/admin/tool/lp/user_evidence_list.php', array('id' => $id));
$url = new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $id));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_user_evidence($userevidence->get_userid(), $url, $userevidence);

$output = $PAGE->get_renderer('tool_lp');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use core_competency\competency_framework;
use core_competency\external\competency_exporter;
use core_competency\external\competency_framework_exporter;
use core_competency\url;
use tool_lpmigrate\framework_processor;

/**
Expand Down Expand Up @@ -147,7 +148,7 @@ public function export_for_template(\renderer_base $output) {
}

$data->pluginbaseurl = (new moodle_url('/admin/tool/lpmigrate'))->out(false);
$data->cbebaseurl = (new moodle_url('/admin/tool/lp'))->out(false);
$data->frameworksurl = url::frameworks($this->pagecontext->id)->out(false);

return $data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<div>
<p>
<a href="{{pluginbaseurl}}/frameworks.php" class="btn btn-primary">{{#str}}migratemore, tool_lpmigrate{{/str}}</a>
<a href="{{cbebaseurl}}/competencyframeworks.php?pagecontextid={{frameworkto.contextid}}" class="btn">{{#str}}continuetoframeworks, tool_lpmigrate{{/str}}</a>
<a href="{{frameworksurl}}" class="btn">{{#str}}continuetoframeworks, tool_lpmigrate{{/str}}</a>
</p>
</div>
{{#js}}
Expand Down
1 change: 0 additions & 1 deletion blocks/lp/classes/output/competencies_to_review_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function export_for_template(renderer_base $output) {

$data = array(
'competencies' => $compstoreview,
'cbebaseurl' => (new moodle_url('/admin/tool/lp'))->out(false),
'pluginbaseurl' => (new moodle_url('/blocks/lp'))->out(false),
);

Expand Down
1 change: 0 additions & 1 deletion blocks/lp/classes/output/plans_to_review_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function export_for_template(renderer_base $output) {

$data = array(
'plans' => $planstoreview,
'cbebaseurl' => (new moodle_url('/admin/tool/lp'))->out(false),
'pluginbaseurl' => (new moodle_url('/blocks/lp'))->out(false),
);

Expand Down
3 changes: 2 additions & 1 deletion blocks/lp/classes/output/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use core_competency\external\user_competency_exporter;
use core_competency\external\user_summary_exporter;
use core_competency\plan;
use core_competency\url;
use renderable;
use renderer_base;
use templatable;
Expand Down Expand Up @@ -130,7 +131,7 @@ public function export_for_template(renderer_base $output) {
'hasplanstoreview' => $this->planstoreview['count'] > 0,
'hasmoreplanstoreview' => $this->planstoreview['count'] > 3,

'cbebaseurl' => (new \moodle_url('/admin/tool/lp'))->out(false),
'plansurl' => url::plans($this->user->id)->out(false),
'pluginbaseurl' => (new \moodle_url('/blocks/lp'))->out(false),
'userid' => $this->user->id,
);
Expand Down
2 changes: 1 addition & 1 deletion blocks/lp/templates/competencies_to_review_page.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<tbody>
{{#competencies}}
<tr>
<td><a href="{{cbebaseurl}}/user_competency.php?id={{usercompetency.id}}">{{competency.shortname}}</a></td>
<td><a href="{{usercompetency.url}}">{{competency.shortname}}</a></td>
<td>{{user.fullname}}</td>
<td>{{usercompetency.statusname}}</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion blocks/lp/templates/plans_to_review_page.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<tbody>
{{#plans}}
<tr>
<td><a href="{{cbebaseurl}}/plan.php?id={{plan.id}}">{{plan.name}}</a></td>
<td><a href="{{plan.url}}">{{plan.name}}</a></td>
<td>{{user.fullname}}</td>
<td>{{plan.statusname}}</td>
</tr>
Expand Down
10 changes: 5 additions & 5 deletions blocks/lp/templates/summary.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
{{#hasactiveplans}}
<ul>
{{#activeplans}}
<li><a href="{{cbebaseurl}}/plan.php?id={{id}}">{{name}}</a></li>
<li><a href="{{url}}">{{name}}</a></li>
{{/activeplans}}
{{#hasmoreplans}}
<li class="more"><a href="{{cbebaseurl}}/plans.php?userid={{userid}}">{{#str}}viewmore, block_lp{{/str}}</a></li>
<li class="more"><a href="{{plansurl}}">{{#str}}viewmore, block_lp{{/str}}</a></li>
{{/hasmoreplans}}
</ul>
{{/hasactiveplans}}
{{^hasactiveplans}}
<p>No active plans at the moment. <a href="{{cbebaseurl}}/plans.php?userid={{userid}}">{{#str}}viewotherplans, block_lp{{/str}}</a></p>
<p>No active plans at the moment. <a href="{{plansurl}}">{{#str}}viewotherplans, block_lp{{/str}}</a></p>
{{/hasactiveplans}}
</div>
{{/hasplans}}
Expand All @@ -60,7 +60,7 @@
<ul>
{{#compstoreview}}
<li>
<a href="{{cbebaseurl}}/user_competency.php?id={{usercompetency.id}}">{{competency.shortname}}</a> ({{user.fullname}}) - {{usercompetency.statusname}}
<a href="{{usercompetency.url}}">{{competency.shortname}}</a> ({{user.fullname}}) - {{usercompetency.statusname}}
</li>
{{/compstoreview}}
{{#hasmorecompstoreview}}
Expand All @@ -75,7 +75,7 @@
<ul>
{{#planstoreview}}
<li>
<a href="{{cbebaseurl}}/plan.php?id={{plan.id}}">{{plan.name}}</a> ({{user.fullname}}) - {{plan.statusname}}
<a href="{{plan.url}}">{{plan.name}}</a> ({{user.fullname}}) - {{plan.statusname}}
</li>
{{/planstoreview}}
{{#hasmoreplanstoreview}}
Expand Down
2 changes: 1 addition & 1 deletion competency/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3822,7 +3822,7 @@ public static function create_user_evidence_competency($userevidenceorid, $compe
if (!$relation->get_id()) {
$relation->create();

$link = new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $userevidence->get_id()));
$link = url::user_evidence($userevidence->get_id());
self::add_evidence(
$userevidence->get_userid(),
$competency,
Expand Down
5 changes: 3 additions & 2 deletions competency/classes/external/plan_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use renderer_base;
use stdClass;
use moodle_url;
use core_competency\url;

/**
* Class for exporting plan data.
Expand Down Expand Up @@ -99,7 +100,7 @@ protected function get_other_values(renderer_base $output) {

$commentareaexporter = new comment_area_exporter($this->persistent->get_comment_object());
$values->commentarea = $commentareaexporter->export($output);
$values->url = new moodle_url('/admin/tool/lp/plan.php', array('id' => $this->persistent->get_id()));
$values->url = url::plan($this->persistent->get_id())->out(false);

return (array) $values;
}
Expand Down Expand Up @@ -181,7 +182,7 @@ public static function define_other_properties() {
'optional' => true,
),
'url' => array(
'type' => PARAM_TEXT
'type' => PARAM_URL
)
);
}
Expand Down
6 changes: 6 additions & 0 deletions competency/classes/external/user_competency_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use core_user;
use renderer_base;
use stdClass;
use core_competency\url;
use core_competency\user_competency;

/**
Expand Down Expand Up @@ -87,6 +88,8 @@ protected function get_other_values(renderer_base $output) {
$result->reviewer = $userexporter->export($output);
}

$result->url = url::user_competency($this->persistent->get_id())->out(false);

return (array) $result;
}

Expand Down Expand Up @@ -132,6 +135,9 @@ protected static function define_other_properties() {
'statusname' => array(
'type' => PARAM_RAW
),
'url' => array(
'type' => PARAM_URL
),
);
}
}
Loading

0 comments on commit 07fc0ec

Please sign in to comment.