MDL-51040 cbe: Fixes from peer review

No logic changes here - only small refactorings based on feedback from
peer review.
This commit is contained in:
Damyon Wiese
2016-04-18 10:58:48 +08:00
committed by Frederic Massart
parent 9f422dc2e9
commit 65a67e238d
19 changed files with 360 additions and 154 deletions
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/notification","core/ajax","core/templates","core/log"],function(a,b,c,d,e){var f=function(a,b,c,d,f){this._rootElement=a,this._competencyId=b,this._userId=c,this._planId=d,this._courseId=f,this._valid=!0,this._planId?(this._methodName="tool_lp_data_for_user_competency_summary_in_plan",this._args={userid:this._userId,competencyid:this._competencyId,planid:this._planId},this._templateName="tool_lp/user_competency_summary_in_plan"):this._courseId?(this._methodName="tool_lp_data_for_user_competency_summary_in_course",this._args={userid:this._userId,competencyid:this._competencyId,courseid:this._courseId},this._templateName="tool_lp/user_competency_summary_in_course"):(e.error("Plan id or course id is required."),this._valid=!1)};return f.prototype.reload=function(){var a=this,e=[];this._valid&&(e=c.call([{methodname:this._methodName,args:this._args}]),e[0].done(function(c){d.render(a._templateName,c).done(function(b,c){d.replaceNode(a._rootElement,b,c)}).fail(b.exception)}).fail(b.exception))},f.prototype._rootElement=null,f.prototype._courseId=null,f.prototype._valid=null,f.prototype._planId=null,f.prototype._competencyId=null,f.prototype._userId=null,f.prototype._methodName=null,f.prototype._args=null,f.prototype._templateName=null,f});
define(["jquery","core/notification","core/ajax","core/templates","core/log"],function(a,b,c,d,e){var f=function(a,b,c,d,f){this._rootElement=a,this._competencyId=b,this._userId=c,this._planId=d,this._courseId=f,this._valid=!0,this._planId?(this._methodName="tool_lp_data_for_user_competency_summary_in_plan",this._args={competencyid:this._competencyId,planid:this._planId},this._templateName="tool_lp/user_competency_summary_in_plan"):this._courseId?(this._methodName="tool_lp_data_for_user_competency_summary_in_course",this._args={userid:this._userId,competencyid:this._competencyId,courseid:this._courseId},this._templateName="tool_lp/user_competency_summary_in_course"):(e.error("Plan id or course id is required."),this._valid=!1)};return f.prototype.reload=function(){var a=this,e=[];this._valid&&(e=c.call([{methodname:this._methodName,args:this._args}]),e[0].done(function(c){d.render(a._templateName,c).done(function(b,c){d.replaceNode(a._rootElement,b,c)}).fail(b.exception)}).fail(b.exception))},f.prototype._rootElement=null,f.prototype._courseId=null,f.prototype._valid=null,f.prototype._planId=null,f.prototype._competencyId=null,f.prototype._userId=null,f.prototype._methodName=null,f.prototype._args=null,f.prototype._templateName=null,f});
@@ -42,7 +42,7 @@ define(['jquery', 'core/notification', 'core/ajax', 'core/templates', 'core/log'
if (this._planId) {
this._methodName = 'tool_lp_data_for_user_competency_summary_in_plan';
this._args = { userid: this._userId, competencyid: this._competencyId, planid: this._planId };
this._args = { competencyid: this._competencyId, planid: this._planId };
this._templateName = 'tool_lp/user_competency_summary_in_plan';
} else if (this._courseId) {
this._methodName = 'tool_lp_data_for_user_competency_summary_in_course';
+152 -46
View File
@@ -699,6 +699,49 @@ class api {
return course_competency::count_competencies($courseid);
}
/**
* Get a single competency associated to a course.
*
* @param mixed $courseorid The course, or its ID.
* @param int $competencyid The competency id
* @return array( array(
* 'competency' => \tool_lp\competency,
* 'coursecompetency' => \tool_lp\course_competency
* ))
*/
public static function get_course_comptency($courseorid) {
$course = $courseorid;
if (!is_object($courseorid)) {
$course = get_course($courseorid);
}
// Check the user have access to the course.
self::validate_course($course);
$context = context_course::instance($course->id);
$onlyvisible = 1;
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', '');
}
$result = array();
// TODO We could improve the performance of this into one single query.
$coursecompetencies = course_competency::list_course_competencies($course->id, false);
$competencies = course_competency::list_competencies($course->id, false);
// Build the return values.
foreach ($coursecompetencies as $key => $coursecompetency) {
$result[] = array(
'competency' => $competencies[$coursecompetency->get_competencyid()],
'coursecompetency' => $coursecompetency
);
}
return $result;
}
/**
* List the competencies associated to a course.
*
@@ -740,6 +783,39 @@ class api {
return $result;
}
/**
* Get a user competency in a course.
*
* @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
*/
public static function get_user_competency_in_course($courseid, $userid, $competencyid) {
// First we do a permissions check.
$context = context_course::instance($courseid);
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', '');
}
// 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));
// Create missing.
$found = count($existing);
if ($found) {
$uc = array_pop($existing);
} else {
$uc = user_competency::create_relation($userid, $coursecompetency->get_id());
$uc->create();
}
return $uc;
}
/**
* List all the user competencies in a course.
*
@@ -757,15 +833,12 @@ class api {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', '');
}
if (has_capability('tool/lp:coursecompetencymanage', $context)) {
$onlyvisible = 0;
}
// OK - all set.
$competencylist = course_competency::list_competencies($courseid, $onlyvisible);
$competencylist = course_competency::list_competencies($courseid, false);
$existing = user_competency::get_multiple($userid, $competencylist);
// Create missing.
$orderedusercompetencies = array();
$somemissing = false;
foreach ($competencylist as $coursecompetency) {
@@ -773,22 +846,18 @@ class api {
foreach ($existing as $usercompetency) {
if ($usercompetency->get_competencyid() == $coursecompetency->get_id()) {
$found = true;
$orderedusercompetencies[$usercompetency->get_id()] = $usercompetency;
break;
}
}
if (!$found) {
$somemissing = true;
$uc = user_competency::create_relation($userid, $coursecompetency->get_id());
$uc->create();
$orderedusercompetencies[$uc->get_id()] = $uc;
}
}
if ($somemissing) {
// Fetch again.
$all = user_competency::get_multiple($userid, $competencylist);
} else {
$all = $existing;
}
return $all;
return $orderedusercompetencies;
}
/**
@@ -1867,6 +1936,63 @@ class api {
return $success;
}
/**
* Get a single competency from the user plan.
*
* @param int $planorid The plan, or its ID.
* @param int $competencyid The competency id.
* @return (object) array(
* 'competency' => \tool_lp\competency,
* 'usercompetency' => \tool_lp\user_competency
* 'usercompetencyplan' => \tool_lp\user_competency_plan
* )
* The values of of keys usercompetency and usercompetencyplan cannot be defined at the same time.
*/
public static function get_plan_competency($planorid, $competencyid) {
$plan = $planorid;
if (!is_object($planorid)) {
$plan = new plan($planorid);
}
if (!$plan->can_read()) {
$context = context_user::instance($plan->get_userid());
throw new required_capability_exception($context, 'tool/lp:planview', 'nopermissions', '');
}
$competency = $plan->get_competency($competencyid);
// Get user competencies from user_competency_plan if the plan status is set to complete.
$iscompletedplan = $plan->get_status() == plan::STATUS_COMPLETE;
if ($iscompletedplan) {
$usercompetencies = user_competency_plan::get_multiple($plan->get_userid(), $plan->get_id(), array($competencyid));
$ucresultkey = 'usercompetencyplan';
} else {
$usercompetencies = user_competency::get_multiple($plan->get_userid(), array($competencyid));
$ucresultkey = 'usercompetency';
}
$found = count($usercompetencies);
if ($found) {
$uc = array_pop($usercompetencies);
} else {
if ($iscompletedplan) {
throw new coding_exception('A user competency plan is missing');
} else {
$uc = user_competency::create_relation($plan->get_userid(), $competency->get_id());
}
}
$plancompetency = (object) array(
'competency' => $competency,
'usercompetency' => null,
'usercompetencyplan' => null
);
$plancompetency->$ucresultkey = $uc;
return $plancompetency;
}
/**
* List the competencies in a user plan.
*
@@ -2455,15 +2581,10 @@ class api {
$order = 'DESC',
$skip = 0,
$limit = 0) {
global $USER;
$context = context_user::instance($userid);
if ($userid == $USER->id) {
if (!has_any_capability(array('tool/lp:planview', 'tool/lp:planviewown'), $context)) {
throw new required_capability_exception($context, 'tool/lp:planviewown', 'nopermissions', '');
}
} else {
require_capability('tool/lp:planview', $context);
if (!plan::can_read_user($userid)) {
$context = context_user::instance($userid);
throw new required_capability_exception($context, 'tool/lp:planview', 'nopermissions', '');
}
// TODO - handle archived plans.
@@ -2796,19 +2917,11 @@ class api {
require_capability('tool/lp:competencysuggestgrade', $context);
}
// Verify the data.
$userplancompetencies = self::list_plan_competencies($plan);
$competency = null;
foreach ($userplancompetencies as $userplancompetency) {
if ($userplancompetency->competency->get_id() == $competencyid) {
$competency = $userplancompetency->competency;
}
}
if (!$competency) {
throw new coding_exception('The competency does not belong to this plan: ' . $competencyid . ', ' . $planid);
// Throws exception if competency not in plan.
$competency = $plan->get_competency($competencyid);
$competencycontext = $competency->get_context();
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $competencycontext)) {
throw new required_capability_exception($competencycontext, 'tool/lp:competencyread', 'nopermissions', '');
}
$action = evidence::ACTION_OVERRIDE;
@@ -2855,18 +2968,11 @@ class api {
require_capability('tool/lp:competencysuggestgrade', $context);
}
$coursecompetencies = self::list_course_competencies($course);
// Verify the data.
$competency = null;
foreach ($coursecompetencies as $coursecompetency) {
if ($coursecompetency['competency']->get_id() == $competencyid) {
$competency = $coursecompetency['competency'];
}
}
if (!$competency) {
throw new coding_exception('The competency does not belong to this course: ' . $competencyid . ', ' . $courseid);
// Throws exception if competency not in course.
$competency = course_competency::get_competency($course->id, $competencyid);
$competencycontext = $competency->get_context();
if (!has_any_capability(array('tool/lp:competencyread', 'tool/lp:competencymanage'), $competencycontext)) {
throw new required_capability_exception($competencycontext, 'tool/lp:competencyread', 'nopermissions', '');
}
$action = evidence::ACTION_OVERRIDE;
@@ -245,6 +245,31 @@ class course_competency extends persistent {
return $instances;
}
/**
* Get a single competency from the course (only if it is really in the course).
*
* @param int $courseid The course id
* @param int $competencyid The competency id
* @return competency
*/
public static function get_competency($courseid, $competencyid) {
global $DB;
$sql = 'SELECT comp.*
FROM {' . competency::TABLE . '} comp
JOIN {' . self::TABLE . '} crscomp
ON crscomp.competencyid = comp.id
WHERE crscomp.courseid = ? AND crscomp.competencyid = ?';
$params = array($courseid, $competencyid);
$result = $DB->get_record_sql($sql, $params);
if (!$result) {
throw new coding_exception('The competency does not belong to this course: ' . $competencyid . ', ' . $courseid);
}
return new competency(0, $result);
}
/**
* Hook to execute after delete.
*
@@ -262,6 +287,29 @@ class course_competency extends persistent {
$DB->execute($sql, array($this->get_courseid(), $this->get_sortorder()));
}
/**
* Get the specified course_competency in this course.
*
* @param int $courseid The course id
* @param int $competencyid The competency id
* @return course_competency
*/
public static function get_course_competency($courseid, $competencyid) {
global $DB;
$sql = 'SELECT crscomp.*
FROM {' . self::TABLE . '} crscomp
WHERE crscomp.courseid = ? AND crscomp.competencyid = ?';
$params = array($courseid, $competencyid);
$result = $DB->get_record_sql($sql, $params);
if (!$result) {
throw new coding_exception('The competency does not belong to this course: ' . $competencyid . ', ' . $courseid);
}
return new course_competency(0, $result);
}
/**
* List the course_competencies in this course.
*
+12 -79
View File
@@ -58,6 +58,8 @@ use tool_lp\external\course_summary_exporter;
use tool_lp\external\plan_exporter;
use tool_lp\external\template_exporter;
use tool_lp\external\evidence_exporter;
use tool_lp\output\user_competency_summary_in_plan;
use tool_lp\output\user_competency_summary_in_course;
/**
* This is the external API for this tool.
@@ -4213,11 +4215,6 @@ class external extends external_api {
* @return \external_function_parameters
*/
public static function data_for_user_competency_summary_in_plan_parameters() {
$userid = new external_value(
PARAM_INT,
'Data base record id for the user',
VALUE_REQUIRED
);
$competencyid = new external_value(
PARAM_INT,
'Data base record id for the competency',
@@ -4230,7 +4227,6 @@ class external extends external_api {
);
$params = array(
'userid' => $userid,
'competencyid' => $competencyid,
'planid' => $planid,
);
@@ -4240,60 +4236,25 @@ class external extends external_api {
/**
* Read a user competency summary.
*
* @param int $userid The user id
* @param int $competencyid The competency id
* @param int $planid The plan id
* @return \stdClass
*/
public static function data_for_user_competency_summary_in_plan($userid, $competencyid, $planid) {
global $PAGE, $DB, $CFG;
public static function data_for_user_competency_summary_in_plan($competencyid, $planid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_user_competency_summary_in_plan_parameters(),
array(
'userid' => $userid,
'competencyid' => $competencyid,
'planid' => $planid
));
$context = context_user::instance($params['userid']);
$plan = api::read_plan($params['planid']);
$context = $plan->get_context();
self::validate_context($context);
$output = $PAGE->get_renderer('tool_lp');
$plan = api::read_plan($params['planid']);
if ($plan->get_userid() != $params['userid']) {
throw new invalid_parameter_exception('Invalid params. The plan does not belong to the user.');
}
$records = api::list_plan_competencies($planid);
$competency = $usercompetency = $usercompetencyplan = null;
foreach ($records as $record) {
if ($record->competency->get_id() == $params['competencyid']) {
$competency = $record->competency;
$usercompetency = $record->usercompetency;
$usercompetencyplan = $record->usercompetencyplan;
break;
}
}
if (empty($competency)) {
throw new invalid_parameter_exception('Invalid params. The competency does not belong to the plan.');
}
$relatedcompetencies = api::list_related_competencies($competency->get_id());
$userid = $params['userid'];
$user = $DB->get_record('user', array('id' => $userid));
$evidence = api::list_evidence($params['userid'], $params['competencyid'], $plan->get_id());
$params = array(
'competency' => $competency,
'usercompetency' => $usercompetency,
'usercompetencyplan' => $usercompetencyplan,
'evidence' => $evidence,
'user' => $user,
'plan' => $plan,
'relatedcompetencies' => $relatedcompetencies
);
$exporter = new user_competency_summary_in_plan_exporter(null, $params);
$data = $exporter->export($output);
return $data;
$renderable = new user_competency_summary_in_plan($params['competencyid'], $params['planid']);
return $renderable->export_for_template($output);
}
/**
@@ -4344,7 +4305,7 @@ class external extends external_api {
* @return \stdClass
*/
public static function data_for_user_competency_summary_in_course($userid, $competencyid, $courseid) {
global $PAGE, $DB, $CFG;
global $PAGE;
$params = self::validate_parameters(self::data_for_user_competency_summary_in_course_parameters(),
array(
'userid' => $userid,
@@ -4355,36 +4316,8 @@ class external extends external_api {
self::validate_context($context);
$output = $PAGE->get_renderer('tool_lp');
$competencies = api::list_user_competencies_in_course($params['courseid'], $params['userid']);
$usercompetency = false;
$competency = false;
foreach ($competencies as $usercoursecompetency) {
if ($usercoursecompetency->get_competencyid() == $params['competencyid']) {
$usercompetency = $usercoursecompetency;
$competency = $usercompetency->get_competency();
}
}
if (empty($usercompetency) || empty($competency)) {
throw new invalid_parameter_exception('Invalid params. The competency does not belong to the course.');
}
$relatedcompetencies = api::list_related_competencies($competency->get_id());
$user = $DB->get_record('user', array('id' => $params['userid']));
$evidence = api::list_evidence($params['userid'], $params['competencyid']);
$course = $DB->get_record('course', array('id' => $params['courseid']));
$params = array(
'competency' => $competency,
'usercompetency' => $usercompetency,
'evidence' => $evidence,
'user' => $user,
'course' => $course,
'relatedcompetencies' => $relatedcompetencies
);
$exporter = new user_competency_summary_in_course_exporter(null, $params);
$data = $exporter->export($output);
return $data;
$renderable = new user_competency_summary_in_course($params['userid'], $params['competencyid'], $params['courseid']);
return $renderable->export_for_template($output);
}
/**
+1 -1
View File
@@ -34,7 +34,7 @@ use renderer_base;
class evidence_exporter extends persistent_exporter {
protected static function define_related() {
return array('actionuser' => '\\stdClass',
return array('actionuser' => 'stdClass',
'scale' => 'grade_scale');
}
+2 -2
View File
@@ -137,7 +137,7 @@ class renderer extends plugin_renderer_base {
* @param renderable $page
* @return string
*/
public function render_user_competency_summary_in_course_page(user_competency_summary_in_course_page $page) {
public function render_user_competency_summary_in_course(user_competency_summary_in_course $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_competency_summary_in_course', $data);
}
@@ -148,7 +148,7 @@ class renderer extends plugin_renderer_base {
* @param renderable $page
* @return string
*/
public function render_user_competency_summary_in_plan_page(user_competency_summary_in_plan_page $page) {
public function render_user_competency_summary_in_plan(user_competency_summary_in_plan $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_competency_summary_in_plan', $data);
}
@@ -83,7 +83,7 @@ class user_competency_course_navigation implements renderable, templatable {
$data->courseid = $this->courseid;
$data->baseurl = $this->baseurl;
if (has_capability('tool/lp:coursecompetencyread', $context)) {
if (has_capability('tool/lp:coursecompetencymanage', $context)) {
$course = $DB->get_record('course', array('id' => $this->courseid));
$currentgroup = optional_param('group', null, PARAM_INT);
$select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
@@ -116,8 +116,14 @@ class user_competency_course_navigation implements renderable, templatable {
$coursecompetencies = \tool_lp\api::list_course_competencies($this->courseid);
$data->competencies = array();
$contextcache = array();
foreach ($coursecompetencies as $coursecompetency) {
$coursecompetencycontext = $coursecompetency['competency']->get_context();
$frameworkid = $coursecompetency['competency']->get_competencyframeworkid();
if (!isset($contextcache[$frameworkid])) {
$contextcache[$frameworkid] = $coursecompetency['competency']->get_context();
}
$context = $contextcache[$frameworkid];
$coursecompetencycontext = $context;
$exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext));
$competency = $exporter->export($output);
if ($competency->id == $this->competencyid) {
@@ -26,6 +26,8 @@ namespace tool_lp\output;
use renderable;
use renderer_base;
use templatable;
use tool_lp\api;
use tool_lp\external\user_competency_summary_in_course_exporter;
/**
* User competency page class.
@@ -34,7 +36,7 @@ use templatable;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_course_page implements renderable, templatable {
class user_competency_summary_in_course implements renderable, templatable {
/** @var userid */
protected $userid;
@@ -65,6 +67,30 @@ class user_competency_summary_in_course_page implements renderable, templatable
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
return \tool_lp\external::data_for_user_competency_summary_in_course($this->userid, $this->competencyid, $this->courseid);
global $DB;
$usercompetency = api::get_user_competency_in_course($this->courseid, $this->userid, $this->competencyid);
$competency = $usercompetency->get_competency();
if (empty($usercompetency) || empty($competency)) {
throw new invalid_parameter_exception('Invalid params. The competency does not belong to the course.');
}
$relatedcompetencies = api::list_related_competencies($competency->get_id());
$user = $DB->get_record('user', array('id' => $this->userid));
$evidence = api::list_evidence($this->userid, $this->competencyid);
$course = $DB->get_record('course', array('id' => $this->courseid));
$params = array(
'competency' => $competency,
'usercompetency' => $usercompetency,
'evidence' => $evidence,
'user' => $user,
'course' => $course,
'relatedcompetencies' => $relatedcompetencies
);
$exporter = new user_competency_summary_in_course_exporter(null, $params);
$data = $exporter->export($output);
return $data;
}
}
@@ -24,12 +24,9 @@
namespace tool_lp\output;
use renderable;
use context_user;
use templatable;
use stdClass;
use tool_lp\api;
use tool_lp\external\user_competency_summary_exporter;
use tool_lp\external\plan_exporter;
use tool_lp\external\user_competency_summary_in_plan_exporter;
/**
* User competency page class.
@@ -38,10 +35,7 @@ use tool_lp\external\plan_exporter;
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_plan_page implements renderable, templatable {
/** @var userid */
protected $userid;
class user_competency_summary_in_plan implements renderable, templatable {
/** @var competencyid */
protected $competencyid;
@@ -52,12 +46,10 @@ class user_competency_summary_in_plan_page implements renderable, templatable {
/**
* Construct.
*
* @param $userid
* @param $competencyid
* @param $planid
*/
public function __construct($userid, $competencyid, $planid) {
$this->userid = $userid;
public function __construct($competencyid, $planid) {
$this->competencyid = $competencyid;
$this->planid = $planid;
}
@@ -69,6 +61,35 @@ class user_competency_summary_in_plan_page implements renderable, templatable {
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
return \tool_lp\external::data_for_user_competency_summary_in_plan($this->userid, $this->competencyid, $this->planid);
global $DB;
$plan = api::read_plan($this->planid);
$pc = api::get_plan_competency($this->planid, $this->competencyid);
$competency = $pc->competency;
$usercompetency = $pc->usercompetency;
$usercompetencyplan = $pc->usercompetencyplan;
if (empty($competency)) {
throw new invalid_parameter_exception('Invalid params. The competency does not belong to the plan.');
}
$relatedcompetencies = api::list_related_competencies($competency->get_id());
$userid = $plan->get_userid();
$user = $DB->get_record('user', array('id' => $userid));
$evidence = api::list_evidence($userid, $this->competencyid, $plan->get_id());
$params = array(
'competency' => $competency,
'usercompetency' => $usercompetency,
'usercompetencyplan' => $usercompetencyplan,
'evidence' => $evidence,
'user' => $user,
'plan' => $plan,
'relatedcompetencies' => $relatedcompetencies
);
$exporter = new user_competency_summary_in_plan_exporter(null, $params);
$data = $exporter->export($output);
return $data;
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ class page_helper {
$title = get_string('coursecompetencies', 'tool_lp');
}
$returnurl = new moodle_url('/admin/tool/lp/coursecompetencies.php', array('courseid' => 2));
$returnurl = new moodle_url('/admin/tool/lp/coursecompetencies.php', array('courseid' => $course->id));
$heading = $context->get_context_name();
$PAGE->set_pagelayout('incourse');
+17
View File
@@ -137,6 +137,23 @@ class plan extends persistent {
return $competencies;
}
/**
* Get a single competency from this plan
*
* @return competency
*/
public function get_competency($competencyid) {
$competencies = array();
if ($this->get_templateid()) {
// Get the competency from the template.
$competency = template_competency::get_competency($this->get_templateid(), $competencyid);
} else {
// Get the competency from the plan.
$competency = plan_competency::get_competency($this->get_id(), $competencyid);
}
return $competency;
}
/**
* Get the context in which the plan is attached.
*
+25
View File
@@ -85,6 +85,31 @@ class plan_competency extends persistent {
return $instances;
}
/**
* Get a single competency from the plan (only if it is really in the plan).
*
* @param int $planid The plan id
* @param int $competencyid The competency id
* @return competency
*/
public static function get_competency($planid, $competencyid) {
global $DB;
$sql = 'SELECT comp.*
FROM {' . competency::TABLE . '} comp
JOIN {' . self::TABLE . '} plncomp
ON plncomp.competencyid = comp.id
WHERE plncomp.planid = ? AND plncomp.competencyid = ?';
$params = array($planid, $competencyid);
$result = $DB->get_record_sql($sql, $params);
if (!$result) {
throw new coding_exception('The competency does not belong to this plan: ' . $competencyid . ', ' . $planid);
}
return new competency(0, $result);
}
/**
* Hook to execute before validate.
*
@@ -138,6 +138,31 @@ class template_competency extends persistent {
return $results;
}
/**
* Get a single competency from the template (only if it is really in the template).
*
* @param int $templateid The template id
* @param int $competencyid The competency id
* @return competency
*/
public static function get_competency($templateid, $competencyid) {
global $DB;
$sql = 'SELECT comp.*
FROM {' . competency::TABLE . '} comp
JOIN {' . self::TABLE . '} tplcomp
ON tplcomp.competencyid = comp.id
WHERE tplcomp.templateid = ? AND tplcomp.competencyid = ?';
$params = array($templateid, $competencyid);
$result = $DB->get_record_sql($sql, $params);
if (!$result) {
throw new coding_exception('The competency does not belong to this template: ' . $competencyid . ', ' . $templateid);
}
return new competency(0, $result);
}
/**
* List the competencies in this template.
*
+1 -1
View File
@@ -2678,7 +2678,7 @@ class tool_lp_external_testcase extends externallib_advanced_testcase {
$evidence = external::grade_competency_in_plan($plan->get_id(), $c1->get_id(), 1, false);
$evidence = external::grade_competency_in_plan($plan->get_id(), $c1->get_id(), 2, true);
$summary = external::data_for_user_competency_summary_in_plan($this->user->id, $c1->get_id(), $plan->get_id());
$summary = external::data_for_user_competency_summary_in_plan($c1->get_id(), $plan->get_id());
$this->assertTrue($summary->usercompetencysummary->cangrade);
$this->assertTrue($summary->usercompetencysummary->cansuggest);
$this->assertEquals('Evil', $summary->plan->name);
+1 -1
View File
@@ -69,7 +69,7 @@ echo $OUTPUT->context_header($userheading, 3);
$baseurl = new moodle_url('/admin/tool/lp/user_competency_in_course.php');
$nav = new \tool_lp\output\user_competency_course_navigation($userid, $competencyid, $courseid, $baseurl);
echo $output->render($nav);
$page = new \tool_lp\output\user_competency_summary_in_course_page($userid, $competencyid, $courseid);
$page = new \tool_lp\output\user_competency_summary_in_course($userid, $competencyid, $courseid);
echo $output->render($page);
echo $output->footer();
+1 -1
View File
@@ -49,7 +49,7 @@ echo $output->header();
echo $output->heading($title);
echo $output->heading($subtitle, 3);
$page = new \tool_lp\output\user_competency_summary_in_plan_page($userid, $competencyid, $planid);
$page = new \tool_lp\output\user_competency_summary_in_plan($competencyid, $planid);
echo $output->render($page);
echo $output->footer();
+3 -1
View File
@@ -28,4 +28,6 @@ defined('MOODLE_INTERNAL') || die();
$plugin->version = 2015111020; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2014110400; // Requires this Moodle version.
$plugin->component = 'report_competency'; // Full name of the plugin (used for diagnostics).
$plugin->dependencies = array(
'tool_lp' => ANY_VERSION
);
-3
View File
@@ -22,9 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->libdir . "/externallib.php");
/**
* Creates a user
*