MDL-63876 competencies: Skip enabled check

Allow rendering a competency summary if competencies are disabled, but do not include
links to competencies pages.
This commit is contained in:
Damyon Wiese 2019-03-15 16:06:32 +08:00
parent 8aff6f6f14
commit 6bdaf20462
8 changed files with 73 additions and 15 deletions

View File

@ -76,6 +76,9 @@ class competency_path_exporter extends \core\external\exporter {
],
'pagecontextid' => [
'type' => PARAM_INT
],
'showlinks' => [
'type' => PARAM_BOOL
]
];
}
@ -91,6 +94,7 @@ class competency_path_exporter extends \core\external\exporter {
$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'),

View File

@ -141,6 +141,7 @@ class competency_summary_exporter extends \core\external\exporter {
]);
$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;
}

View File

@ -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;
}

View File

@ -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>

View File

@ -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'>

View File

@ -56,17 +56,16 @@ class award_criteria_competency extends award_criteria {
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">' .

View File

@ -46,6 +46,9 @@ use required_capability_exception;
*/
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.
*
@ -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;
}
/**

View File

@ -53,9 +53,15 @@ class competency_framework_exporter extends \core\external\persistent_exporter {
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)
);