diff --git a/admin/tool/lp/classes/external.php b/admin/tool/lp/classes/external.php
index 77cf8935733..f798e7d5025 100644
--- a/admin/tool/lp/classes/external.php
+++ b/admin/tool/lp/classes/external.php
@@ -420,6 +420,9 @@ class external extends external_api {
))
),
'comppath' => competency_path_exporter::get_read_structure(),
+ 'plans' => new external_multiple_structure(
+ plan_exporter::get_read_structure()
+ ),
))),
'manageurl' => new external_value(PARAM_LOCALURL, 'Url to the manage competencies page.'),
));
diff --git a/admin/tool/lp/classes/external/user_competency_summary_in_course_exporter.php b/admin/tool/lp/classes/external/user_competency_summary_in_course_exporter.php
index d1b7b7f3300..78ea24a7927 100644
--- a/admin/tool/lp/classes/external/user_competency_summary_in_course_exporter.php
+++ b/admin/tool/lp/classes/external/user_competency_summary_in_course_exporter.php
@@ -26,11 +26,13 @@ defined('MOODLE_INTERNAL') || die();
use core_competency\api;
use core_competency\user_competency;
+use core_competency\external\plan_exporter;
use core_course\external\course_module_summary_exporter;
use core_course\external\course_summary_exporter;
use context_course;
use renderer_base;
use stdClass;
+use moodle_url;
/**
* Class for exporting user competency data with additional related data in a plan.
@@ -62,7 +64,14 @@ class user_competency_summary_in_course_exporter extends \core\external\exporter
'coursemodules' => array(
'type' => course_module_summary_exporter::read_properties_definition(),
'multiple' => true
- )
+ ),
+ 'plans' => array(
+ 'type' => plan_exporter::read_properties_definition(),
+ 'multiple' => true
+ ),
+ 'pluginbaseurl' => [
+ 'type' => PARAM_URL
+ ],
);
}
@@ -95,6 +104,16 @@ class user_competency_summary_in_course_exporter extends \core\external\exporter
}
$result->coursemodules = $exportedmodules;
+ // User learning plans.
+ $plans = api::list_plans_with_competency($this->related['user']->id, $this->related['competency']);
+ $exportedplans = array();
+ foreach ($plans as $plan) {
+ $planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
+ $exportedplans[] = $planexporter->export($output);
+ }
+ $result->plans = $exportedplans;
+ $result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
+
return (array) $result;
}
}
diff --git a/admin/tool/lp/classes/output/course_competencies_page.php b/admin/tool/lp/classes/output/course_competencies_page.php
index eaf7d340c9a..218d8a5f267 100644
--- a/admin/tool/lp/classes/output/course_competencies_page.php
+++ b/admin/tool/lp/classes/output/course_competencies_page.php
@@ -41,6 +41,7 @@ use core_competency\external\course_competency_exporter;
use core_competency\external\course_competency_settings_exporter;
use core_competency\external\user_competency_course_exporter;
use core_competency\external\user_competency_exporter;
+use core_competency\external\plan_exporter;
use tool_lp\external\competency_path_exporter;
use tool_lp\external\course_competency_statistics_exporter;
use core_course\external\course_module_summary_exporter;
@@ -113,6 +114,7 @@ class course_competencies_page implements renderable, templatable {
$data->courseid = $this->courseid;
$data->pagecontextid = $this->context->id;
$data->competencies = array();
+ $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$gradable = is_enrolled($this->context, $USER, 'moodle/competency:coursecompetencygradable');
if ($gradable) {
@@ -154,12 +156,21 @@ class course_competencies_page implements renderable, templatable {
'context' => $context
]);
+ // User learning plans.
+ $plans = api::list_plans_with_competency($USER->id, $competency);
+ $exportedplans = array();
+ foreach ($plans as $plan) {
+ $planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
+ $exportedplans[] = $planexporter->export($output);
+ }
+
$onerow = array(
'competency' => $compexporter->export($output),
'coursecompetency' => $ccexporter->export($output),
'ruleoutcomeoptions' => $ccoutcomeoptions,
'coursemodules' => $exportedmodules,
- 'comppath' => $pathexporter->export($output)
+ 'comppath' => $pathexporter->export($output),
+ 'plans' => $exportedplans
);
if ($gradable) {
$foundusercompetencycourse = false;
diff --git a/admin/tool/lp/templates/course_competencies_page.mustache b/admin/tool/lp/templates/course_competencies_page.mustache
index eaa0f435fa1..6d89b202e40 100644
--- a/admin/tool/lp/templates/course_competencies_page.mustache
+++ b/admin/tool/lp/templates/course_competencies_page.mustache
@@ -15,9 +15,13 @@
along with Moodle. If not, see .
}}
{{!
+ @template tool_lp/course_competencies_page
+
Course competencies template.
For a full list of the context for this template see the course_competencies_page renderable.
+
+ This template includes ajax functionality, so it cannot be shown in the template library.
}}
@@ -66,7 +70,7 @@
{{/canmanagecoursecompetencies}}
{{#competency}}
-
{{{competency.shortname}}} {{competency.idnumber}}
@@ -95,16 +99,30 @@
{{/canmanagecoursecompetencies}}
-
+ {{#str}}activities{{/str}}
+
{{#coursemodules}}
{{name}}
{{/coursemodules}}
{{^coursemodules}}
- - {{#str}}noactivities, tool_lp{{/str}}
+ - {{#str}}noactivities, tool_lp{{/str}}
{{/coursemodules}}
+
+
+ {{#str}}userplans, core_competency{{/str}}
+
+ {{#plans}}
+ - {{{name}}}
+ {{/plans}}
+ {{^plans}}
+ - {{#str}}nouserplanswithcompetency, core_competency{{/str}}
+ {{/plans}}
+
+
+
{{/competencies}}
diff --git a/admin/tool/lp/templates/user_competency_summary_in_course.mustache b/admin/tool/lp/templates/user_competency_summary_in_course.mustache
index 22cf96d6005..ce80bbbd5a4 100644
--- a/admin/tool/lp/templates/user_competency_summary_in_course.mustache
+++ b/admin/tool/lp/templates/user_competency_summary_in_course.mustache
@@ -65,6 +65,19 @@
{{/user}}
{{/displayuser}}
+ {{#str}}userplans, competency{{/str}}
+
+
+
+ {{#plans}}
+ - {{{name}}}
+ {{/plans}}
+ {{^plans}}
+ - {{#str}}nouserplanswithcompetency, competency{{/str}}
+ {{/plans}}
+
+
+
{{#usercompetencycourse}}
{{#str}}proficient, tool_lp{{/str}}
diff --git a/admin/tool/lp/tests/behat/plan_crud.feature b/admin/tool/lp/tests/behat/plan_crud.feature
index d2ca869842c..0fbbfd183a0 100644
--- a/admin/tool/lp/tests/behat/plan_crud.feature
+++ b/admin/tool/lp/tests/behat/plan_crud.feature
@@ -130,3 +130,35 @@ Feature: Manage plearning plan
When I click on "Delete" "button" in the "Confirm" "dialogue"
And I wait until the page is ready
Then I should not see "Science plan Year-4"
+
+ Scenario: See a learning plan from a course
+ Given the following lp "plans" exist:
+ | name | user | description |
+ | Science plan Year-manage | admin | science plan description |
+ And the following lp "frameworks" exist:
+ | shortname | idnumber |
+ | Framework 1 | sc-y-2 |
+ And the following lp "competencies" exist:
+ | shortname | framework |
+ | comp1 | sc-y-2 |
+ | comp2 | sc-y-2 |
+ And I follow "Learning plans"
+ And I should see "Science plan Year-manage"
+ And I follow "Science plan Year-manage"
+ And I should see "Add competency"
+ And I press "Add competency"
+ And "Competency picker" "dialogue" should be visible
+ And I select "comp1" of the competency tree
+ When I click on "Add" "button" in the "Competency picker" "dialogue"
+ Then "comp1" "table_row" should exist
+ And I create a course with:
+ | Course full name | New course fullname |
+ | Course short name | New course shortname |
+ And I follow "New course fullname"
+ And I follow "Competencies"
+ And I press "Add competencies to course"
+ And "Competency picker" "dialogue" should be visible
+ And I select "comp1" of the competency tree
+ And I click on "Add" "button" in the "Competency picker" "dialogue"
+ And I should see "Learning plans"
+ And I should see "Science plan Year-manage"
diff --git a/competency/classes/api.php b/competency/classes/api.php
index 9d04083bf49..97edf6390c9 100644
--- a/competency/classes/api.php
+++ b/competency/classes/api.php
@@ -3191,6 +3191,34 @@ class api {
return $plancompetency;
}
+ /**
+ * List the plans with a competency.
+ *
+ * @param int $userid The user id we want the plans for.
+ * @param int $competencyorid The competency, or its ID.
+ * @return array[plan] Array of learning plans.
+ */
+ public static function list_plans_with_competency($userid, $competencyorid) {
+ global $USER;
+
+ static::require_enabled();
+ $competencyid = $competencyorid;
+ $competency = null;
+ if (is_object($competencyid)) {
+ $competency = $competencyid;
+ $competencyid = $competency->get('id');
+ }
+
+ $plans = plan::get_by_user_and_competency($userid, $competencyid);
+ foreach ($plans as $index => $plan) {
+ // Filter plans we cannot read.
+ if (!$plan->can_read()) {
+ unset($plans[$index]);
+ }
+ }
+ return $plans;
+ }
+
/**
* List the competencies in a user plan.
*
diff --git a/competency/tests/api_test.php b/competency/tests/api_test.php
index 705a32a65fa..3ecf3e9942d 100644
--- a/competency/tests/api_test.php
+++ b/competency/tests/api_test.php
@@ -4631,4 +4631,38 @@ class core_competency_api_testcase extends advanced_testcase {
$this->assertEquals($uc1b->get('id'), $result['competencies'][0]->usercompetency->get('id'));
$this->assertEquals($uc1c->get('id'), $result['competencies'][1]->usercompetency->get('id'));
}
+
+ /**
+ * Test we can get all of a users plans with a competency.
+ */
+ public function test_list_plans_with_competency() {
+ $this->resetAfterTest(true);
+ $this->setAdminUser();
+ $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
+
+ $u1 = $this->getDataGenerator()->create_user();
+ $tpl = $this->getDataGenerator()->get_plugin_generator('core_competency')->create_template();
+
+ // Create a framework and assign competencies.
+ $framework = $lpg->create_framework();
+ $c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get('id')));
+
+ // Create two plans and assign the competency to each.
+ $plan1 = $lpg->create_plan(array('userid' => $u1->id));
+ $plan2 = $lpg->create_plan(array('userid' => $u1->id));
+
+ $lpg->create_plan_competency(array('planid' => $plan1->get('id'), 'competencyid' => $c1->get('id')));
+ $lpg->create_plan_competency(array('planid' => $plan2->get('id'), 'competencyid' => $c1->get('id')));
+
+ // Create one more plan without the competency.
+ $plan3 = $lpg->create_plan(array('userid' => $u1->id));
+
+ $plans = api::list_plans_with_competency($u1->id, $c1);
+
+ $this->assertEquals(2, count($plans));
+
+ $this->assertEquals(reset($plans)->get('id'), $plan1->get('id'));
+ $this->assertEquals(end($plans)->get('id'), $plan2->get('id'));
+ }
+
}
diff --git a/lang/en/competency.php b/lang/en/competency.php
index 42377c73682..404798791d3 100644
--- a/lang/en/competency.php
+++ b/lang/en/competency.php
@@ -107,6 +107,7 @@ $string['invalidpersistenterror'] = 'Error: {$a}';
$string['invalidplan'] = 'Invalid learning plan';
$string['invalidtaxonomy'] = 'Invalid taxonomy: {$a}';
$string['invalidurl'] = 'The URL is not valid. Make sure it starts with \'http://\' or \'https://\'.';
+$string['nouserplanswithcompetency'] = 'No learning plans contain this competency.';
$string['planstatusactive'] = 'Active';
$string['planstatuscomplete'] = 'Complete';
$string['planstatusdraft'] = 'Draft';