MDL-52979 tool_lp: Fix user_competency_course summaries
Only show ratings from the course on course competency pages.
This commit is contained in:
committed by
Frederic Massart
parent
3baf704ddb
commit
96f4d771bf
@@ -1212,7 +1212,7 @@ class api {
|
||||
* @param int $courseid The id of the course to check.
|
||||
* @param int $userid The id of the course to check.
|
||||
* @param int $competencyid The id of the competency.
|
||||
* @return user_competency
|
||||
* @return user_competency_course
|
||||
*/
|
||||
public static function get_user_competency_in_course($courseid, $userid, $competencyid) {
|
||||
static::require_enabled();
|
||||
@@ -1229,17 +1229,17 @@ class api {
|
||||
// This will throw an exception if the competency does not belong to the course.
|
||||
$competency = course_competency::get_competency($courseid, $competencyid);
|
||||
|
||||
$existing = user_competency::get_multiple($userid, array($competencyid));
|
||||
$params = array('courseid' => $courseid, 'userid' => $userid, 'competencyid' => $competencyid);
|
||||
$exists = user_competency_course::get_record($params);
|
||||
// Create missing.
|
||||
$found = count($existing);
|
||||
if ($found) {
|
||||
$uc = array_pop($existing);
|
||||
if ($exists) {
|
||||
$ucc = $exists;
|
||||
} else {
|
||||
$uc = user_competency::create_relation($userid, $competency->get_id());
|
||||
$uc->create();
|
||||
$ucc = user_competency_course::create_relation($userid, $competency->get_id(), $courseid);
|
||||
$ucc->create();
|
||||
}
|
||||
|
||||
return $uc;
|
||||
return $ucc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1247,7 +1247,7 @@ class api {
|
||||
*
|
||||
* @param int $courseid The id of the course to check.
|
||||
* @param int $userid The id of the course to check.
|
||||
* @return array of competencies
|
||||
* @return array of user_competency_course objects
|
||||
*/
|
||||
public static function list_user_competencies_in_course($courseid, $userid) {
|
||||
static::require_enabled();
|
||||
@@ -1265,28 +1265,28 @@ class api {
|
||||
// OK - all set.
|
||||
$competencylist = course_competency::list_competencies($courseid, false);
|
||||
|
||||
$existing = user_competency::get_multiple($userid, $competencylist);
|
||||
$existing = user_competency_course::get_multiple($userid, $courseid, $competencylist);
|
||||
// Create missing.
|
||||
$orderedusercompetencies = array();
|
||||
$orderedusercompetencycourses = array();
|
||||
|
||||
$somemissing = false;
|
||||
foreach ($competencylist as $coursecompetency) {
|
||||
$found = false;
|
||||
foreach ($existing as $usercompetency) {
|
||||
if ($usercompetency->get_competencyid() == $coursecompetency->get_id()) {
|
||||
foreach ($existing as $usercompetencycourse) {
|
||||
if ($usercompetencycourse->get_competencyid() == $coursecompetency->get_id()) {
|
||||
$found = true;
|
||||
$orderedusercompetencies[$usercompetency->get_id()] = $usercompetency;
|
||||
$orderedusercompetencycourses[$usercompetencycourse->get_id()] = $usercompetencycourse;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$uc = user_competency::create_relation($userid, $coursecompetency->get_id());
|
||||
$uc->create();
|
||||
$orderedusercompetencies[$uc->get_id()] = $uc;
|
||||
$ucc = user_competency_course::create_relation($userid, $coursecompetency->get_id(), $courseid);
|
||||
$ucc->create();
|
||||
$orderedusercompetencycourses[$ucc->get_id()] = $ucc;
|
||||
}
|
||||
}
|
||||
|
||||
return $orderedusercompetencies;
|
||||
return $orderedusercompetencycourses;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3530,25 +3530,21 @@ class api {
|
||||
* @param int $courseid The course ID
|
||||
* @return bool
|
||||
*/
|
||||
public static function user_competency_viewed_in_course($usercompetencyorid, $courseid) {
|
||||
public static function user_competency_viewed_in_course($usercoursecompetencyorid) {
|
||||
static::require_enabled();
|
||||
$uc = $usercompetencyorid;
|
||||
if (!is_object($uc)) {
|
||||
$uc = new user_competency($uc);
|
||||
$ucc = $usercoursecompetencyorid;
|
||||
if (!is_object($ucc)) {
|
||||
$ucc = new user_competency_course($ucc);
|
||||
}
|
||||
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
$capabilities = array('tool/lp:coursecompetencyview', 'tool/lp:coursecompetencymanage');
|
||||
if (!has_any_capability($capabilities, $coursecontext)) {
|
||||
throw new required_capability_exception($context, 'tool/lp:coursecompetencyview', 'nopermissions', '');
|
||||
} else if (!user_competency::can_read_user_in_course($uc->get_userid(), $courseid)) {
|
||||
throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
|
||||
if (!$ucc || !user_competency::can_read_user_in_course($ucc->get_userid(), $ucc->get_courseid())) {
|
||||
throw new required_capability_exception($ucc->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', '');
|
||||
}
|
||||
|
||||
// Validate the course, this will throw an exception if not valid.
|
||||
self::validate_course($courseid);
|
||||
self::validate_course($ucc->get_courseid());
|
||||
|
||||
\tool_lp\event\user_competency_viewed_in_course::create_from_user_competency_viewed_in_course($uc, $courseid)->trigger();
|
||||
\tool_lp\event\user_competency_viewed_in_course::create_from_user_competency_viewed_in_course($ucc)->trigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
namespace tool_lp\event;
|
||||
|
||||
use core\event\base;
|
||||
use tool_lp\user_competency;
|
||||
use tool_lp\user_competency_course;
|
||||
use context_course;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -48,27 +48,26 @@ class user_competency_viewed_in_course extends base {
|
||||
/**
|
||||
* Convenience method to instantiate the event in course.
|
||||
*
|
||||
* @param user_competency $usercompetency The user competency.
|
||||
* @param int $courseid The course ID
|
||||
* @param user_competency_course $usercompetencycourse The user competency for the course.
|
||||
* @return self
|
||||
*/
|
||||
public static function create_from_user_competency_viewed_in_course(user_competency $usercompetency, $courseid) {
|
||||
if (!$usercompetency->get_id()) {
|
||||
throw new \coding_exception('The user competency ID must be set.');
|
||||
public static function create_from_user_competency_viewed_in_course(user_competency_course $usercompetencycourse) {
|
||||
if (!$usercompetencycourse->get_id()) {
|
||||
throw new \coding_exception('The user competency course ID must be set.');
|
||||
}
|
||||
$params = array(
|
||||
'objectid' => $usercompetency->get_id(),
|
||||
'relateduserid' => $usercompetency->get_userid(),
|
||||
'objectid' => $usercompetencycourse->get_id(),
|
||||
'relateduserid' => $usercompetencycourse->get_userid(),
|
||||
'other' => array(
|
||||
'competencyid' => $usercompetency->get_competencyid()
|
||||
'competencyid' => $usercompetencycourse->get_competencyid()
|
||||
)
|
||||
);
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
$coursecontext = context_course::instance($usercompetencycourse->get_courseid());
|
||||
$params['contextid'] = $coursecontext->id;
|
||||
$params['courseid'] = $courseid;
|
||||
$params['courseid'] = $usercompetencycourse->get_courseid();
|
||||
|
||||
$event = static::create($params);
|
||||
$event->add_record_snapshot(user_competency::TABLE, $usercompetency->to_record());
|
||||
$event->add_record_snapshot(user_competency_course::TABLE, $usercompetencycourse->to_record());
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -78,7 +77,7 @@ class user_competency_viewed_in_course extends base {
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with id '$this->userid' viewed the user competency with id '$this->objectid' "
|
||||
return "The user with id '$this->userid' viewed the user course competency with id '$this->objectid' "
|
||||
. "in course with id '$this->courseid'";
|
||||
}
|
||||
|
||||
@@ -112,7 +111,7 @@ class user_competency_viewed_in_course extends base {
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'r';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = user_competency::TABLE;
|
||||
$this->data['objecttable'] = user_competency_course::TABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1882,8 +1882,8 @@ class external extends external_api {
|
||||
* @return \external_description
|
||||
*/
|
||||
public static function data_for_course_competencies_page_returns() {
|
||||
$uc = user_competency_exporter::get_read_structure();
|
||||
$uc->required = VALUE_OPTIONAL;
|
||||
$ucc = user_competency_course_exporter::get_read_structure();
|
||||
$ucc->required = VALUE_OPTIONAL;
|
||||
|
||||
return new external_single_structure(array (
|
||||
'courseid' => new external_value(PARAM_INT, 'The current course id'),
|
||||
@@ -1898,7 +1898,7 @@ class external extends external_api {
|
||||
'competency' => competency_exporter::get_read_structure(),
|
||||
'coursecompetency' => course_competency_exporter::get_read_structure(),
|
||||
'coursemodules' => new external_multiple_structure(course_module_summary_exporter::get_read_structure()),
|
||||
'usercompetency' => $uc,
|
||||
'usercompetencycourse' => $ucc,
|
||||
'ruleoutcomeoptions' => new external_multiple_structure(
|
||||
new external_single_structure(array(
|
||||
'value' => new external_value(PARAM_INT, 'The option value'),
|
||||
@@ -5366,8 +5366,8 @@ class external extends external_api {
|
||||
'userid' => $userid,
|
||||
'courseid' => $courseid
|
||||
));
|
||||
$uc = api::get_user_competency_in_course($params['courseid'], $params['userid'], $params['competencyid']);
|
||||
$result = api::user_competency_viewed_in_course($uc, $params['courseid']);
|
||||
$ucc = api::get_user_competency_in_course($params['courseid'], $params['userid'], $params['competencyid']);
|
||||
$result = api::user_competency_viewed_in_course($ucc);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Class for exporting user competency course data.
|
||||
*
|
||||
* @package tool_lp
|
||||
* @copyright 2016 Damyon Wiese
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_lp\external;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core_user;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class for exporting user competency course data.
|
||||
*
|
||||
* @copyright 2016 Damyon Wiese
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class user_competency_course_exporter extends persistent_exporter {
|
||||
|
||||
protected static function define_class() {
|
||||
return 'tool_lp\\user_competency_course';
|
||||
}
|
||||
|
||||
protected static function define_related() {
|
||||
// We cache the scale so it does not need to be retrieved from the framework every time.
|
||||
return array('scale' => 'grade_scale');
|
||||
}
|
||||
|
||||
protected function get_other_values(renderer_base $output) {
|
||||
$result = new stdClass();
|
||||
|
||||
if ($this->persistent->get_grade() === null) {
|
||||
$gradename = '-';
|
||||
} else {
|
||||
$gradename = $this->related['scale']->scale_items[$this->persistent->get_grade() - 1];
|
||||
}
|
||||
$result->gradename = $gradename;
|
||||
|
||||
if ($this->persistent->get_proficiency() === null) {
|
||||
$proficiencyname = get_string('no');
|
||||
} else {
|
||||
$proficiencyname = get_string($this->persistent->get_proficiency() ? 'yes' : 'no');
|
||||
}
|
||||
$result->proficiencyname = $proficiencyname;
|
||||
|
||||
return (array) $result;
|
||||
}
|
||||
|
||||
protected static function define_other_properties() {
|
||||
return array(
|
||||
'gradename' => array(
|
||||
'type' => PARAM_TEXT
|
||||
),
|
||||
'proficiencyname' => array(
|
||||
'type' => PARAM_RAW
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,7 @@ class user_competency_summary_exporter extends exporter {
|
||||
protected function get_other_values(renderer_base $output) {
|
||||
global $DB;
|
||||
$result = new stdClass();
|
||||
|
||||
$result->showrelatedcompetencies = true;
|
||||
|
||||
$competency = $this->related['competency'];
|
||||
|
||||
+27
-3
@@ -42,8 +42,9 @@ class user_competency_summary_in_course_exporter extends exporter {
|
||||
'relatedcompetencies' => '\\tool_lp\\competency[]',
|
||||
'user' => '\\stdClass',
|
||||
'course' => '\\stdClass',
|
||||
'usercompetency' => '\\tool_lp\\user_competency?',
|
||||
'evidence' => '\\tool_lp\\evidence[]');
|
||||
'usercompetencycourse' => '\\tool_lp\\user_competency_course?',
|
||||
'evidence' => '\\tool_lp\\evidence[]',
|
||||
'scale' => '\\grade_scale');
|
||||
}
|
||||
|
||||
protected static function define_other_properties() {
|
||||
@@ -51,6 +52,18 @@ class user_competency_summary_in_course_exporter extends exporter {
|
||||
'usercompetencysummary' => array(
|
||||
'type' => user_competency_summary_exporter::read_properties_definition()
|
||||
),
|
||||
'proficiency' => array(
|
||||
'type' => PARAM_BOOL,
|
||||
),
|
||||
'proficiencyname' => array(
|
||||
'type' => PARAM_TEXT
|
||||
),
|
||||
'grade' => array(
|
||||
'type' => PARAM_INT
|
||||
),
|
||||
'gradename' => array(
|
||||
'type' => PARAM_TEXT
|
||||
),
|
||||
'course' => array(
|
||||
'type' => course_summary_exporter::read_properties_definition(),
|
||||
),
|
||||
@@ -64,13 +77,24 @@ class user_competency_summary_in_course_exporter extends exporter {
|
||||
protected function get_other_values(renderer_base $output) {
|
||||
// Arrays are copy on assign.
|
||||
$related = $this->related;
|
||||
$result = new stdClass();
|
||||
// Remove course from related as it is not wanted by the user_competency_summary_exporter.
|
||||
unset($related['course']);
|
||||
$related['usercompetencyplan'] = null;
|
||||
$related['usercompetency'] = null;
|
||||
$exporter = new user_competency_summary_exporter(null, $related);
|
||||
$result = new stdClass();
|
||||
$result->usercompetencysummary = $exporter->export($output);
|
||||
|
||||
$result->gradename = '-';
|
||||
if ($this->related['usercompetencycourse']) {
|
||||
$result->proficiency = $this->related['usercompetencycourse']->get_proficiency();
|
||||
$result->proficiencyname = $result->proficiency ? get_string('yes') : get_string('no');
|
||||
$result->grade = $this->related['usercompetencycourse']->get_grade();
|
||||
if ($result->grade) {
|
||||
$result->gradename = $this->related['scale']->scale_items[$result->grade - 1];
|
||||
}
|
||||
}
|
||||
|
||||
$context = context_course::instance($this->related['course']->id);
|
||||
$exporter = new course_summary_exporter($this->related['course'], array('context' => $context));
|
||||
$result->course = $exporter->export($output);
|
||||
|
||||
@@ -42,6 +42,7 @@ use tool_lp\external\course_competency_statistics_exporter;
|
||||
use tool_lp\external\course_competency_settings_exporter;
|
||||
use tool_lp\external\course_module_summary_exporter;
|
||||
use tool_lp\external\user_competency_exporter;
|
||||
use tool_lp\external\user_competency_course_exporter;
|
||||
|
||||
/**
|
||||
* Class containing data for course competencies page
|
||||
@@ -114,7 +115,7 @@ class course_competencies_page implements renderable, templatable {
|
||||
|
||||
$gradable = is_enrolled($this->context, $USER, 'tool/lp:coursecompetencygradable');
|
||||
if ($gradable) {
|
||||
$usercompetencies = api::list_user_competencies_in_course($this->courseid, $USER->id);
|
||||
$usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $USER->id);
|
||||
$data->gradableuserid = $USER->id;
|
||||
}
|
||||
|
||||
@@ -162,15 +163,18 @@ class course_competencies_page implements renderable, templatable {
|
||||
'comppath' => $pathexporter->export($output)
|
||||
);
|
||||
if ($gradable) {
|
||||
$foundusercompetency = false;
|
||||
foreach ($usercompetencies as $usercompetency) {
|
||||
if ($usercompetency->get_competencyid() == $competency->get_id()) {
|
||||
$foundusercompetency = $usercompetency;
|
||||
$foundusercompetencycourse = false;
|
||||
foreach ($usercompetencycourses as $usercompetencycourse) {
|
||||
if ($usercompetencycourse->get_competencyid() == $competency->get_id()) {
|
||||
$foundusercompetencycourse = $usercompetencycourse;
|
||||
}
|
||||
}
|
||||
if ($foundusercompetency) {
|
||||
$exporter = new user_competency_exporter($foundusercompetency, array('scale' => $competency->get_scale()));
|
||||
$onerow['usercompetency'] = $exporter->export($output);
|
||||
if ($foundusercompetencycourse) {
|
||||
$related = array(
|
||||
'scale' => $competency->get_scale()
|
||||
);
|
||||
$exporter = new user_competency_course_exporter($foundusercompetencycourse, $related);
|
||||
$onerow['usercompetencycourse'] = $exporter->export($output);
|
||||
}
|
||||
}
|
||||
array_push($data->competencies, $onerow);
|
||||
|
||||
@@ -70,9 +70,9 @@ class user_competency_summary_in_course implements renderable, templatable {
|
||||
public function export_for_template(renderer_base $output) {
|
||||
global $DB;
|
||||
|
||||
$usercompetency = api::get_user_competency_in_course($this->courseid, $this->userid, $this->competencyid);
|
||||
$competency = $usercompetency->get_competency();
|
||||
if (empty($usercompetency) || empty($competency)) {
|
||||
$usercompetencycourse = api::get_user_competency_in_course($this->courseid, $this->userid, $this->competencyid);
|
||||
$competency = $usercompetencycourse->get_competency();
|
||||
if (empty($usercompetencycourse) || empty($competency)) {
|
||||
throw new invalid_parameter_exception('Invalid params. The competency does not belong to the course.');
|
||||
}
|
||||
|
||||
@@ -83,18 +83,16 @@ class user_competency_summary_in_course implements renderable, templatable {
|
||||
|
||||
$params = array(
|
||||
'competency' => $competency,
|
||||
'usercompetency' => $usercompetency,
|
||||
'usercompetencycourse' => $usercompetencycourse,
|
||||
'evidence' => $evidence,
|
||||
'user' => $user,
|
||||
'course' => $course,
|
||||
'scale' => $competency->get_scale(),
|
||||
'relatedcompetencies' => $relatedcompetencies
|
||||
);
|
||||
$exporter = new user_competency_summary_in_course_exporter(null, $params);
|
||||
$data = $exporter->export($output);
|
||||
|
||||
// Some adjustments specific to course.
|
||||
$data->usercompetencysummary->cangrade = user_competency::can_grade_user_in_course($this->userid, $this->courseid);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,11 @@
|
||||
{{#comppath}}
|
||||
<span class="pull-left">{{#str}}path, tool_lp{{/str}} </span>{{> tool_lp/competency_path }}
|
||||
{{/comppath}}
|
||||
{{#usercompetency}}
|
||||
{{#usercompetencycourse}}
|
||||
{{#grade}}
|
||||
<span class="label {{^proficiency}}label-important{{/proficiency}}">{{gradename}}</span>
|
||||
{{/grade}}
|
||||
{{/usercompetency}}
|
||||
{{/usercompetencycourse}}
|
||||
{{#canmanagecoursecompetencies}}
|
||||
<div data-region="coursecompetency-ruleoutcome">
|
||||
<label>
|
||||
|
||||
@@ -57,7 +57,6 @@
|
||||
</ul>
|
||||
</p>
|
||||
</dd>
|
||||
{{#usercompetency}}
|
||||
{{#displayuser}}
|
||||
{{#user}}
|
||||
<dt>{{#str}}user{{/str}}</dt>
|
||||
@@ -66,13 +65,6 @@
|
||||
</dd>
|
||||
{{/user}}
|
||||
{{/displayuser}}
|
||||
<dt>{{#str}}reviewstatus, tool_lp{{/str}}</dt>
|
||||
<dd data-region="user-competency-status">{{statusname}}
|
||||
|
||||
{{#isstatusinreview}}
|
||||
- {{reviewer.fullname}}
|
||||
{{/isstatusinreview}}
|
||||
</dd>
|
||||
<dt>{{#str}}proficient, tool_lp{{/str}}</dt>
|
||||
<dd>
|
||||
<span class="label{{^proficiency}} label-important{{/proficiency}} pull-left">
|
||||
@@ -98,21 +90,6 @@
|
||||
});
|
||||
|
||||
{{/js}}
|
||||
{{/usercompetency}}
|
||||
{{#usercompetencyplan}}
|
||||
<dd>{{gradename}} - {{#str}}plancompleted, tool_lp{{/str}}</dd>
|
||||
{{#cangrade}}
|
||||
{{$gradeform}}
|
||||
<!-- Grading a user competency is specific to the context you are in. -->
|
||||
{{/gradeform}}
|
||||
{{/cangrade}}
|
||||
<dt>{{#str}}proficient, tool_lp{{/str}}</dt>
|
||||
<dd>
|
||||
<span class="label{{^proficiency}} label-important{{/proficiency}} pull-left">
|
||||
{{proficiencyname}}
|
||||
</span>
|
||||
</dd>
|
||||
{{/usercompetencyplan}}
|
||||
</dl>
|
||||
{{#commentarea}}
|
||||
{{#canpostorhascomments}}
|
||||
|
||||
@@ -4014,6 +4014,14 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
|
||||
$user = $dg->create_user();
|
||||
$c1 = $dg->create_course();
|
||||
|
||||
// Enrol the user so they can be rated in the course.
|
||||
$studentarch = get_archetype_roles('student');
|
||||
$studentrole = array_shift($studentarch);
|
||||
$coursecontext = context_course::instance($c1->id);
|
||||
$dg->role_assign($studentrole->id, $user->id, $coursecontext->id);
|
||||
$dg->enrol_user($user->id, $c1->id, $studentrole->id);
|
||||
|
||||
$framework = $lpg->create_framework();
|
||||
$comp1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
|
||||
$comp2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
|
||||
@@ -4021,14 +4029,13 @@ class tool_lp_api_testcase extends advanced_testcase {
|
||||
$lpg->create_course_competency(array('competencyid' => $comp2->get_id(), 'courseid' => $c1->id));
|
||||
|
||||
// Create a user competency for comp1.
|
||||
$lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $comp1->get_id(),
|
||||
'proficiency' => true, 'grade' => 1 ));
|
||||
api::grade_competency_in_course($c1, $user->id, $comp1->get_id(), 3, 'Unit test');
|
||||
|
||||
// Test for competency already exist in user_competency.
|
||||
$uc = api::get_user_competency_in_course($c1->id, $user->id, $comp1->get_id());
|
||||
$this->assertEquals($comp1->get_id(), $uc->get_competencyid());
|
||||
$this->assertEquals($user->id, $uc->get_userid());
|
||||
$this->assertEquals(1, $uc->get_grade());
|
||||
$this->assertEquals(3, $uc->get_grade());
|
||||
$this->assertEquals(true, $uc->get_proficiency());
|
||||
|
||||
// Test for competency does not exist in user_competency.
|
||||
|
||||
@@ -785,11 +785,12 @@ class tool_lp_event_testcase extends advanced_testcase {
|
||||
$fr = $lpg->create_framework();
|
||||
$c = $lpg->create_competency(array('competencyframeworkid' => $fr->get_id()));
|
||||
$pc = $lpg->create_course_competency(array('courseid' => $course->id, 'competencyid' => $c->get_id()));
|
||||
$uc = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c->get_id()));
|
||||
$params = array('userid' => $user->id, 'competencyid' => $c->get_id(), 'courseid' => $course->id);
|
||||
$ucc = $lpg->create_user_competency_course($params);
|
||||
|
||||
// Trigger and capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
api::user_competency_viewed_in_course($uc, $course->id);
|
||||
api::user_competency_viewed_in_course($ucc);
|
||||
|
||||
// Get our event event.
|
||||
$events = $sink->get_events();
|
||||
@@ -797,9 +798,9 @@ class tool_lp_event_testcase extends advanced_testcase {
|
||||
|
||||
// Check that the event data is valid.
|
||||
$this->assertInstanceOf('\tool_lp\event\user_competency_viewed_in_course', $event);
|
||||
$this->assertEquals($uc->get_id(), $event->objectid);
|
||||
$this->assertEquals($ucc->get_id(), $event->objectid);
|
||||
$this->assertEquals(context_course::instance($course->id)->id, $event->contextid);
|
||||
$this->assertEquals($uc->get_userid(), $event->relateduserid);
|
||||
$this->assertEquals($ucc->get_userid(), $event->relateduserid);
|
||||
$this->assertEquals($course->id, $event->courseid);
|
||||
$this->assertEquals($c->get_id(), $event->other['competencyid']);
|
||||
|
||||
@@ -808,8 +809,8 @@ class tool_lp_event_testcase extends advanced_testcase {
|
||||
|
||||
// Test validation.
|
||||
$params = array (
|
||||
'objectid' => $uc->get_id(),
|
||||
'contextid' => $uc->get_context()->id,
|
||||
'objectid' => $ucc->get_id(),
|
||||
'contextid' => $ucc->get_context()->id,
|
||||
'other' => null
|
||||
);
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ use tool_lp\template;
|
||||
use tool_lp\template_cohort;
|
||||
use tool_lp\template_competency;
|
||||
use tool_lp\user_competency;
|
||||
use tool_lp\user_competency_course;
|
||||
use tool_lp\user_competency_plan;
|
||||
use tool_lp\plan_competency;
|
||||
use tool_lp\evidence;
|
||||
@@ -319,6 +320,32 @@ class tool_lp_generator extends component_generator_base {
|
||||
return $plan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user competency course.
|
||||
*
|
||||
* @param array|stdClass $record
|
||||
* @return user_competency_course
|
||||
*/
|
||||
public function create_user_competency_course($record = null) {
|
||||
$record = (object) $record;
|
||||
|
||||
if (!isset($record->userid)) {
|
||||
throw new coding_exception('The userid value is required.');
|
||||
}
|
||||
if (!isset($record->competencyid)) {
|
||||
throw new coding_exception('The competencyid value is required.');
|
||||
}
|
||||
|
||||
if (!isset($record->courseid)) {
|
||||
throw new coding_exception('The courseid value is required.');
|
||||
}
|
||||
|
||||
$usercompetencycourse = new user_competency_course(0, $record);
|
||||
$usercompetencycourse->create();
|
||||
|
||||
return $usercompetencycourse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user competency plan.
|
||||
*
|
||||
|
||||
@@ -64,7 +64,7 @@ $competency = new \tool_lp\competency($competencyid);
|
||||
|
||||
// Does a permissions check for us.
|
||||
if ($userid > 0) {
|
||||
$usercompetencies = \tool_lp\api::list_user_competencies_in_course($courseid, $userid);
|
||||
$usercompetencycourses = \tool_lp\api::list_user_competencies_in_course($courseid, $userid);
|
||||
}
|
||||
$subtitle = $competency->get_shortname() . ' <em>' . $competency->get_idnumber() . '</em>';
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ use external_single_structure;
|
||||
use external_value;
|
||||
use tool_lp\external\competency_summary_exporter;
|
||||
use tool_lp\external\course_summary_exporter;
|
||||
use tool_lp\external\user_competency_exporter;
|
||||
use tool_lp\external\user_competency_course_exporter;
|
||||
use tool_lp\external\user_summary_exporter;
|
||||
|
||||
/**
|
||||
@@ -113,7 +113,7 @@ class external extends external_api {
|
||||
'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'),
|
||||
'usercompetencies' => new external_multiple_structure(
|
||||
new external_single_structure(array(
|
||||
'usercompetency' => user_competency_exporter::get_read_structure(),
|
||||
'usercompetencycourse' => user_competency_course_exporter::get_read_structure(),
|
||||
'competency' => competency_summary_exporter::get_read_structure()
|
||||
))
|
||||
),
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace report_competency\output;
|
||||
use context_course;
|
||||
use tool_lp\external\competency_summary_exporter;
|
||||
use tool_lp\external\course_summary_exporter;
|
||||
use tool_lp\external\user_competency_exporter;
|
||||
use tool_lp\external\user_competency_course_exporter;
|
||||
use tool_lp\external\user_summary_exporter;
|
||||
use tool_lp\user_competency;
|
||||
use renderable;
|
||||
@@ -94,13 +94,13 @@ class report implements renderable, templatable {
|
||||
$data->user = $exporter->export($output);
|
||||
$data->usercompetencies = array();
|
||||
$coursecompetencies = api::list_course_competencies($this->courseid);
|
||||
$usercompetencies = api::list_user_competencies_in_course($this->courseid, $user->id);
|
||||
$usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $user->id);
|
||||
|
||||
foreach ($usercompetencies as $usercompetency) {
|
||||
foreach ($usercompetencycourses as $usercompetencycourse) {
|
||||
$onerow = new stdClass();
|
||||
$competency = null;
|
||||
foreach ($coursecompetencies as $coursecompetency) {
|
||||
if ($coursecompetency['competency']->get_id() == $usercompetency->get_competencyid()) {
|
||||
if ($coursecompetency['competency']->get_id() == $usercompetencycourse->get_competencyid()) {
|
||||
$competency = $coursecompetency['competency'];
|
||||
break;
|
||||
}
|
||||
@@ -127,9 +127,9 @@ class report implements renderable, templatable {
|
||||
}
|
||||
$scale = $scalecache[$competency->get_scaleid()];
|
||||
|
||||
$exporter = new user_competency_exporter($usercompetency, array('scale' => $scale));
|
||||
$exporter = new user_competency_course_exporter($usercompetencycourse, array('scale' => $scale));
|
||||
$record = $exporter->export($output);
|
||||
$onerow->usercompetency = $record;
|
||||
$onerow->usercompetencycourse = $record;
|
||||
$exporter = new competency_summary_exporter(null, array('competency' => $competency,
|
||||
'framework' => $framework,
|
||||
'context' => $framework->get_context(),
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</a>
|
||||
</td>
|
||||
{{/competency}}
|
||||
{{#usercompetency}}
|
||||
{{#usercompetencycourse}}
|
||||
<td class="alert {{#proficiency}}alert-success{{/proficiency}}"
|
||||
data-user-competency="true"
|
||||
data-userid="{{user.id}}"
|
||||
@@ -42,7 +42,7 @@
|
||||
data-courseid="{{course.id}}">
|
||||
{{> report_competency/user_competency_summary}}
|
||||
</td>
|
||||
{{/usercompetency}}
|
||||
{{/usercompetencycourse}}
|
||||
</tr>
|
||||
{{/usercompetencies}}
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user