mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 17:02:03 +02:00
MDL-53346 competencies: Show user learning plans
On the course competencies page, show the user their learning plans that contain each of the course competencies.
This commit is contained in:
parent
c092f75791
commit
c0417b04ff
@ -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.'),
|
||||
));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -15,9 +15,13 @@
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@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.
|
||||
}}
|
||||
<div data-region="coursecompetenciespage">
|
||||
<div data-region="actions" class="clearfix">
|
||||
@ -66,7 +70,7 @@
|
||||
<div class="clearfix"></div>
|
||||
{{/canmanagecoursecompetencies}}
|
||||
{{#competency}}
|
||||
<a href="{{pluginbaseurl}}user_competency_in_course.php?courseid={{courseid}}&competencyid={{competency.id}}&userid={{gradableuserid}}"
|
||||
<a href="{{pluginbaseurl}}/user_competency_in_course.php?courseid={{courseid}}&competencyid={{competency.id}}&userid={{gradableuserid}}"
|
||||
id="competency-info-link-{{competency.id}}"
|
||||
title="{{#str}}viewdetails, tool_lp{{/str}}">
|
||||
<p><strong>{{{competency.shortname}}} <em>{{competency.idnumber}}</em></strong></p>
|
||||
@ -95,16 +99,30 @@
|
||||
{{/canmanagecoursecompetencies}}
|
||||
<div data-region="coursecompetencyactivities">
|
||||
<p>
|
||||
<ul class="inline list-inline">
|
||||
<strong>{{#str}}activities{{/str}}</strong>
|
||||
<ul class="inline list-inline p-2">
|
||||
{{#coursemodules}}
|
||||
<li class="list-inline-item"><a href="{{url}}"><img src="{{iconurl}}"> {{name}} </a></li>
|
||||
{{/coursemodules}}
|
||||
{{^coursemodules}}
|
||||
<li class="list-inline-item"><span class="alert">{{#str}}noactivities, tool_lp{{/str}}</span></li>
|
||||
<li class="list-inline-item">{{#str}}noactivities, tool_lp{{/str}}</li>
|
||||
{{/coursemodules}}
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
<div data-region="learningplans">
|
||||
<p>
|
||||
<strong>{{#str}}userplans, core_competency{{/str}}</strong>
|
||||
<ul class="inline list-inline p-2">
|
||||
{{#plans}}
|
||||
<li class="list-inline-item"><a href="{{pluginbaseurl}}/plan.php?id={{id}}">{{{name}}}</a></li>
|
||||
{{/plans}}
|
||||
{{^plans}}
|
||||
<li class="list-inline-item">{{#str}}nouserplanswithcompetency, core_competency{{/str}}</li>
|
||||
{{/plans}}
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{/competencies}}
|
||||
|
@ -65,6 +65,19 @@
|
||||
</dd>
|
||||
{{/user}}
|
||||
{{/displayuser}}
|
||||
<dt>{{#str}}userplans, competency{{/str}}</dt>
|
||||
<dd>
|
||||
<p>
|
||||
<ul class="inline list-inline">
|
||||
{{#plans}}
|
||||
<li class="list-inline-item"><a href="{{pluginbaseurl}}/plan.php?id={{id}}">{{{name}}}</a></li>
|
||||
{{/plans}}
|
||||
{{^plans}}
|
||||
<li>{{#str}}nouserplanswithcompetency, competency{{/str}}</li>
|
||||
{{/plans}}
|
||||
</ul>
|
||||
</p>
|
||||
</dd>
|
||||
{{#usercompetencycourse}}
|
||||
<dt>{{#str}}proficient, tool_lp{{/str}}</dt>
|
||||
<dd>
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user