Skip to content

Commit

Permalink
MDL-63876 competencies: Skip enabled check
Browse files Browse the repository at this point in the history
Allow rendering a competency summary if competencies are disabled, but do not include
links to competencies pages.
  • Loading branch information
Damyon Wiese committed Mar 29, 2019
1 parent 8aff6f6 commit 6bdaf20
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 15 deletions.
4 changes: 4 additions & 0 deletions admin/tool/lp/classes/external/competency_path_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ protected static function define_other_properties() {
],
'pagecontextid' => [
'type' => PARAM_INT
],
'showlinks' => [
'type' => PARAM_BOOL
]
];
}
Expand All @@ -91,6 +94,7 @@ protected function get_other_values(renderer_base $output) {
$ancestors = [];
$nodescount = count($this->related['ancestors']);
$i = 1;
$result->showlinks = \core_competency\api::show_links();
foreach ($this->related['ancestors'] as $competency) {
$exporter = new path_node_exporter([
'id' => $competency->get('id'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ protected function get_other_values(renderer_base $output) {
]);
$result->comppath = $exporter->export($output);
$result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$result->showlinks = \core_competency\api::show_links();

return (array) $result;
}
Expand Down
5 changes: 3 additions & 2 deletions admin/tool/lp/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,11 @@ function tool_lp_get_fontawesome_icon_map() {
function tool_lp_render_competency_summary(\core_competency\competency $competency,
\core_competency\competency_framework $framework,
$includerelated,
$includecourses) {
$includecourses,
$skipenabled = false) {
global $PAGE;

if (!get_config('core_competency', 'enabled')) {
if (!$skipenabled && !get_config('core_competency', 'enabled')) {
return;
}

Expand Down
18 changes: 16 additions & 2 deletions admin/tool/lp/templates/competency_path.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,24 @@
}}
<nav id="competency-path-{{uniqid}}">
<small>
<a href="{{pluginbaseurl}}/competencies.php?competencyframeworkid={{framework.id}}&pagecontextid={{pagecontextid}}" >{{{framework.name}}}</a>
{{#showlinks}}
<a href="{{pluginbaseurl}}/competencies.php?competencyframeworkid={{framework.id}}&pagecontextid={{pagecontextid}}" >
{{{framework.name}}}
</a>
{{/showlinks}}
{{^showlinks}}
{{{framework.name}}}
{{/showlinks}}
/
{{#ancestors}}
<a href="{{pluginbaseurl}}/competencies.php?competencyid={{id}}">{{{name}}}</a>
{{#showlinks}}
<a href="{{pluginbaseurl}}/competencies.php?competencyid={{id}}">
{{{name}}}
</a>
{{/showlinks}}
{{^showlinks}}
{{{name}}}
{{/showlinks}}
{{^last}}<span> / </span>{{/last}}
{{/ancestors}}
</small>
Expand Down
9 changes: 8 additions & 1 deletion admin/tool/lp/templates/competency_summary.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@
}}
<div class='competency-heading'>
<h4 id="competency_link_{{competency.id}}">{{{competency.shortname}}}
<small><a href="{{pluginbaseurl}}/competencies.php?competencyid={{competency.id}}">{{competency.idnumber}}</a></small>
<small>
{{#showlinks}}
<a href="{{pluginbaseurl}}/competencies.php?competencyid={{competency.id}}">{{competency.idnumber}}</a>
{{/showlinks}}
{{^showlinks}}
{{competency.idnumber}}
{{/showlinks}}
</small>
</h4>
{{#framework}}
<div class='competency-origin'>
Expand Down
15 changes: 7 additions & 8 deletions badges/criteria/award_criteria_competency.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ public function get_details($short = '') {
if ($short) {
$competency->set('description', '');
}
if (!self::is_enabled()) {
$output[] = get_string('competenciesarenotenabled', 'core_competency');
} else {
if ($pluginsfunction = get_plugins_with_function('render_competency_summary')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$output[] = $pluginfunction($competency, $competency->get_framework(), !$short, !$short);
}
// Render the competency even if competencies are not currently enabled.
\core_competency\api::skip_enabled();
if ($pluginsfunction = get_plugins_with_function('render_competency_summary')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginfunction) {
$output[] = $pluginfunction($competency, $competency->get_framework(), false, false, true);
}
}
}
\core_competency\api::check_enabled();
}

return '<dl><dd class="p-3 mb-2 bg-light text-dark border">' .
Expand Down
28 changes: 27 additions & 1 deletion competency/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
*/
class api {

/** @var boolean Allow api functions even if competencies are not enabled for the site. */
private static $skipenabled = false;

/**
* Returns whether competencies are enabled.
*
Expand All @@ -56,7 +59,30 @@ class api {
* @return boolean True when enabled.
*/
public static function is_enabled() {
return get_config('core_competency', 'enabled');
return self::$skipenabled || get_config('core_competency', 'enabled');
}

/**
* When competencies used to be enabled, we can show the text but do not include links.
*
* @return boolean True means show links.
*/
public static function show_links() {
return isloggedin() && !isguestuser() && get_config('core_competency', 'enabled');
}

/**
* Allow calls to competency api functions even if competencies are not currently enabled.
*/
public static function skip_enabled() {
self::$skipenabled = true;
}

/**
* Restore the checking that competencies are enabled with any api function.
*/
public static function check_enabled() {
self::$skipenabled = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ protected static function define_class() {
protected function get_other_values(renderer_base $output) {
$filters = array('competencyframeworkid' => $this->persistent->get('id'));
$context = $this->persistent->get_context();
$competenciescount = 0;
try {
api::count_competencies($filters);
} catch (\required_capability_exception $re) {
$competenciescount = 0;
}
return array(
'canmanage' => has_capability('moodle/competency:competencymanage', $context),
'competenciescount' => api::count_competencies($filters),
'competenciescount' => $competenciescount,
'contextname' => $context->get_context_name(),
'contextnamenoprefix' => $context->get_context_name(false)
);
Expand Down

0 comments on commit 6bdaf20

Please sign in to comment.