MDL-53186 tool_lp: Send competencies in review from evidence interface

This commit is contained in:
Serge Gauthier 2016-03-15 17:05:43 -04:00 committed by Frederic Massart
parent e821c94799
commit 71cb304ad8
18 changed files with 565 additions and 43 deletions

View File

@ -1 +1 @@
define(["jquery","core/notification","core/ajax","core/templates","core/str","tool_lp/tree","tool_lp/competencypicker"],function(a,b,c,d,e,f,g){var h=function(a,b,c){g.prototype.constructor.apply(this,[1,!1,"self",c]),this._userId=a,this._plans=[],b&&(this._planId=b,this._singlePlan=!0)};return h.prototype=Object.create(g.prototype),h.prototype._plans=null,h.prototype._planId=null,h.prototype._singlePlan=!1,h.prototype._userId=null,h.prototype._afterRender=function(){var b=this;g.prototype._afterRender.apply(b,arguments),b._singlePlan||b._find('[data-action="chooseplan"]').change(function(c){b._planId=a(c.target).val(),b._loadCompetencies().then(b._refresh.bind(b))}.bind(b))},h.prototype._fetchCompetencies=function(a,d){var e=this;return c.call([{methodname:"tool_lp_list_plan_competencies",args:{id:a}}])[0].done(function(a){var b,c,f=[];for(b=0;b<a.length;b++)c=a[b].competency,c.shortname.toLowerCase().indexOf(d.toLowerCase())<0||(c.children=[],c.haschildren=0,f.push(c));e._competencies=f}).fail(b.exception)},h.prototype._getPlan=function(b){var c;return a.each(this._plans,function(a,d){return d.id==b?(c=d,!1):void 0}),c},h.prototype._loadCompetencies=function(){return this._fetchCompetencies(this._planId,this._searchText)},h.prototype._loadPlans=function(){var d,e=this;return e._plans.length>0?a.when():(d=e._singlePlan?c.call([{methodname:"tool_lp_read_plan",args:{id:this._planId}}])[0].then(function(a){return[a]}):c.call([{methodname:"tool_lp_list_user_plans",args:{userid:e._userId}}])[0],d.done(function(a){e._plans=a}).fail(b.exception))},h.prototype._preRender=function(){var b=this;return b._loadPlans().then(function(){return!b._planId&&b._plans.length>0&&(b._planId=b._plans[0].id),b._planId?b._loadCompetencies():(b._plans=[],a.when())}.bind(b))},h.prototype._render=function(){var b=this;return b._preRender().then(function(){b._singlePlan||a.each(b._plans,function(a,c){c.id==b._planId?c.selected=!0:c.selected=!1});var c={competencies:b._competencies,plan:b._getPlan(b._planId),plans:b._plans,search:b._searchText,singlePlan:b._singlePlan};return d.render("tool_lp/competency_picker_user_plans",c)}.bind(b))},h});
define(["jquery","core/notification","core/ajax","core/templates","core/str","tool_lp/tree","tool_lp/competencypicker"],function(a,b,c,d,e,f,g){var h=function(a,b,c){g.prototype.constructor.apply(this,[1,!1,"self",c]),this._userId=a,this._plans=[],b&&(this._planId=b,this._singlePlan=!0)};return h.prototype=Object.create(g.prototype),h.prototype._plans=null,h.prototype._planId=null,h.prototype._singlePlan=!1,h.prototype._userId=null,h.prototype._requestReview=!1,h.prototype._afterRender=function(){var b=this;g.prototype._afterRender.apply(b,arguments),b._singlePlan||b._find('[data-action="chooseplan"]').change(function(c){b._planId=a(c.target).val(),b._loadCompetencies().then(b._refresh.bind(b))}.bind(b)),b._find('[data-action="request-review"]').change(function(c){b._requestReview=a(c.target).is(":checked"),b._refresh.bind(b)}.bind(b))},h.prototype._fetchCompetencies=function(a,d){var e=this;return c.call([{methodname:"tool_lp_list_plan_competencies",args:{id:a}}])[0].done(function(a){var b,c,f=[];for(b=0;b<a.length;b++)c=a[b].competency,c.shortname.toLowerCase().indexOf(d.toLowerCase())<0||(c.children=[],c.haschildren=0,f.push(c));e._competencies=f}).fail(b.exception)},h.prototype._getPlan=function(b){var c;return a.each(this._plans,function(a,d){return d.id==b?(c=d,!1):void 0}),c},h.prototype._loadCompetencies=function(){return this._fetchCompetencies(this._planId,this._searchText)},h.prototype._loadPlans=function(){var d,e=this;return e._plans.length>0?a.when():(d=e._singlePlan?c.call([{methodname:"tool_lp_read_plan",args:{id:this._planId}}])[0].then(function(a){return[a]}):c.call([{methodname:"tool_lp_list_user_plans",args:{userid:e._userId}}])[0],d.done(function(a){e._plans=a}).fail(b.exception))},h.prototype._preRender=function(){var b=this;return b._loadPlans().then(function(){return!b._planId&&b._plans.length>0&&(b._planId=b._plans[0].id),b._planId?b._loadCompetencies():(b._plans=[],a.when())}.bind(b))},h.prototype._render=function(){var b=this;return b._preRender().then(function(){b._singlePlan||a.each(b._plans,function(a,c){c.id==b._planId?c.selected=!0:c.selected=!1});var c={competencies:b._competencies,plan:b._getPlan(b._planId),plans:b._plans,search:b._searchText,singlePlan:b._singlePlan};return d.render("tool_lp/competency_picker_user_plans",c)}.bind(b))},h.prototype._trigger=function(a,b){var c=this;return"save"===a&&(b.requestReview=c._requestReview),g.prototype._trigger.apply(c,arguments)},h});

File diff suppressed because one or more lines are too long

View File

@ -63,6 +63,8 @@ define(['jquery',
Picker.prototype._singlePlan = false;
/** @type {Number} The user the plans belongs to. */
Picker.prototype._userId = null;
/** @type {Boolean} Whether user want to send competencies to review. */
Picker.prototype._requestReview = false;
/**
* Hook to executed after the view is rendered.
@ -81,6 +83,12 @@ define(['jquery',
}.bind(self));
}
// Add listener for checkbox change.
self._find('[data-action="request-review"]').change(function(e) {
self._requestReview = $(e.target).is(":checked");
self._refresh.bind(self);
}.bind(self));
};
/**
@ -236,6 +244,22 @@ define(['jquery',
}.bind(self));
};
/**
* Trigger an event.
*
* @param {String} type The type of event.
* @param {Object} The data to pass to the listeners.
* @method _reset
*/
Picker.prototype._trigger = function(type, args) {
var self = this;
if (type === 'save') {
args.requestReview = self._requestReview;
}
return PickerBase.prototype._trigger.apply(self, arguments);
};
return /** @alias module:tool_lp/competencypicker_user_plans */ Picker;
});

View File

@ -196,8 +196,9 @@ define(['jquery',
*
* @param {Object} evidenceData Evidence data from evidence node.
* @param {Number} competencyIds The competency IDs.
* @param {Boolean} requestReview Send competencies to review.
*/
UserEvidenceActions.prototype._doCreateUserEvidenceCompetency = function(evidenceData, competencyIds) {
UserEvidenceActions.prototype._doCreateUserEvidenceCompetency = function(evidenceData, competencyIds, requestReview) {
var self = this,
calls = [];
@ -209,6 +210,16 @@ define(['jquery',
competencyid: competencyId,
}
});
if (requestReview) {
calls.push({
methodname: 'tool_lp_user_competency_request_review',
args: {
userid: evidenceData.userid,
competencyid: competencyId,
checkstatus: false
}
});
}
});
self._callAndRefresh(calls, evidenceData);
@ -225,7 +236,7 @@ define(['jquery',
picker.on('save', function(e, data) {
var competencyIds = data.competencyIds;
self._doCreateUserEvidenceCompetency(evidenceData, competencyIds);
self._doCreateUserEvidenceCompetency(evidenceData, competencyIds, data.requestReview);
}.bind(self));
picker.display();
@ -285,6 +296,66 @@ define(['jquery',
this.deleteUserEvidenceCompetency(data, competencyId);
};
/**
* Send request review for user evidence competencies and reload the region.
*
* @param {Object} evidenceData Evidence data from evidence node.
*/
UserEvidenceActions.prototype._doReviewUserEvidenceCompetencies = function(evidenceData) {
var self = this,
calls = [{
methodname: 'tool_lp_request_review_of_user_evidence_linked_competencies',
args: { id: evidenceData.id }
}];
self._callAndRefresh(calls, evidenceData);
};
/**
* Send request review for user evidence competencies.
*
* @param {Object} evidenceData Evidence data from evidence node.
*/
UserEvidenceActions.prototype.reviewUserEvidenceCompetencies = function(evidenceData) {
var self = this,
requests;
requests = ajax.call([{
methodname: 'tool_lp_read_user_evidence',
args: { id: evidenceData.id }
}]);
requests[0].done(function(evidence) {
str.get_strings([
{ key: 'confirm', component: 'moodle' },
{ key: 'sendallcompetenciestoreview', component: 'tool_lp', param: evidence.name },
{ key: 'confirm', component: 'moodle' },
{ key: 'cancel', component: 'moodle' }
]).done(function (strings) {
notification.confirm(
strings[0], // Confirm.
strings[1], // Send all competencies in review for X?
strings[2], // Confirm.
strings[3], // Cancel.
function() {
self._doReviewUserEvidenceCompetencies(evidenceData);
}.bind(self)
);
}).fail(notification.exception);
}).fail(notification.exception);
};
/**
* Send request review for user evidence competencies handler.
*
* @param {Event} e The event.
*/
UserEvidenceActions.prototype._reviewUserEvidenceCompetenciesHandler = function(e) {
e.preventDefault();
var data = this._findEvidenceData($(e.target));
this.reviewUserEvidenceCompetencies(data);
};
/**
* Find the evidence data from the evidence node.
*
@ -317,6 +388,7 @@ define(['jquery',
Menubar.enhance(selector, {
'[data-action="user-evidence-delete"]': self._deleteEvidenceHandler.bind(self),
'[data-action="link-competency"]': self._createUserEvidenceCompetencyHandler.bind(self),
'[data-action="send-competencies-review"]': self._reviewUserEvidenceCompetenciesHandler.bind(self),
});
};
@ -333,6 +405,7 @@ define(['jquery',
wrapper.find('[data-action="user-evidence-delete"]').click(self._deleteEvidenceHandler.bind(self));
wrapper.find('[data-action="link-competency"]').click(self._createUserEvidenceCompetencyHandler.bind(self));
wrapper.find('[data-action="delete-competency-link"]').click(self._deleteUserEvidenceCompetencyHandler.bind(self));
wrapper.find('[data-action="send-competencies-review"]').click(self._reviewUserEvidenceCompetenciesHandler.bind(self));
};
return /** @alias module:tool_lp/user_evidence_actions */ UserEvidenceActions;

View File

@ -3346,9 +3346,10 @@ class api {
*
* @param int $userid The user ID.
* @param int $competencyid The competency ID.
* @param bool $onlyidle Return exception if status is not idle.
* @return bool
*/
public static function user_competency_request_review($userid, $competencyid) {
public static function user_competency_request_review($userid, $competencyid, $onlyidle = true) {
static::require_enabled();
$uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$uc) {
@ -3359,7 +3360,11 @@ class api {
if (!$uc->can_read()) {
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyread', 'nopermissions', '');
} else if ($uc->get_status() != user_competency::STATUS_IDLE) {
throw new coding_exception('The competency can not be sent for review at this stage.');
if ($onlyidle) {
throw new coding_exception('The competency can not be sent for review at this stage.');
} else {
return true;
}
} else if (!$uc->can_request_review()) {
throw new required_capability_exception($uc->get_context(), 'tool/lp:usercompetencyrequestreview', 'nopermissions', '');
}
@ -3840,6 +3845,32 @@ class api {
return $success;
}
/**
* Send request review for user evidence competencies.
*
* @param int $id The user evidence ID.
* @return bool
*/
public static function request_review_of_user_evidence_linked_competencies($id) {
$onlyidle = false;
$userevidence = new user_evidence($id);
$context = $userevidence->get_context();
$userid = $userevidence->get_userid();
if (!$userevidence->can_manage()) {
throw new required_capability_exception($context, 'tool/lp:userevidencemanage', 'nopermissions', '');
}
$usercompetencies = user_evidence_competency::get_user_competencies_by_userevidenceid($id);
foreach ($usercompetencies as $usercompetency) {
if ($usercompetency->get_status() == user_competency::STATUS_IDLE) {
static::user_competency_request_review($userid, $usercompetency->get_competencyid());
}
}
return true;
}
/**
* Recursively duplicate competencies from a tree, we start duplicating from parents to children to have a correct path.
* This method does not copy the related competencies.

View File

@ -53,6 +53,7 @@ use tool_lp\external\user_competency_summary_exporter;
use tool_lp\external\user_competency_summary_in_course_exporter;
use tool_lp\external\user_competency_summary_in_plan_exporter;
use tool_lp\external\user_evidence_exporter;
use tool_lp\external\user_evidence_summary_exporter;
use tool_lp\external\user_evidence_competency_exporter;
use tool_lp\external\competency_exporter;
use tool_lp\external\course_competency_exporter;
@ -2940,7 +2941,7 @@ class external extends external_api {
* @return boolean
*/
public static function user_competency_cancel_review_request($userid, $competencyid) {
$params = self::validate_parameters(self::user_competency_request_review_parameters(), array(
$params = self::validate_parameters(self::user_competency_cancel_review_request_parameters(), array(
'userid' => $userid,
'competencyid' => $competencyid
));
@ -2969,6 +2970,7 @@ class external extends external_api {
return new external_function_parameters(array(
'userid' => new external_value(PARAM_INT, 'The user ID'),
'competencyid' => new external_value(PARAM_INT, 'The competency ID'),
'checkstatus' => new external_value(PARAM_BOOL, 'Check status request', VALUE_DEFAULT, true)
));
}
@ -2977,18 +2979,20 @@ class external extends external_api {
*
* @param int $userid The user ID.
* @param int $competencyid The competency ID.
* @param boolean $checkstatus True to return exception when status is already in review.
* @return boolean
*/
public static function user_competency_request_review($userid, $competencyid) {
public static function user_competency_request_review($userid, $competencyid, $checkstatus) {
$params = self::validate_parameters(self::user_competency_request_review_parameters(), array(
'userid' => $userid,
'competencyid' => $competencyid
'competencyid' => $competencyid,
'checkstatus' => $checkstatus,
));
$context = context_user::instance($params['userid']);
self::validate_context($context);
return api::user_competency_request_review($userid, $competencyid);
return api::user_competency_request_review($userid, $competencyid, $checkstatus);
}
/**
@ -3020,7 +3024,7 @@ class external extends external_api {
* @return boolean
*/
public static function user_competency_start_review($userid, $competencyid) {
$params = self::validate_parameters(self::user_competency_request_review_parameters(), array(
$params = self::validate_parameters(self::user_competency_start_review_parameters(), array(
'userid' => $userid,
'competencyid' => $competencyid
));
@ -3060,7 +3064,7 @@ class external extends external_api {
* @return boolean
*/
public static function user_competency_stop_review($userid, $competencyid) {
$params = self::validate_parameters(self::user_competency_request_review_parameters(), array(
$params = self::validate_parameters(self::user_competency_stop_review_parameters(), array(
'userid' => $userid,
'competencyid' => $competencyid
));
@ -4063,9 +4067,7 @@ class external extends external_api {
'canmanage' => new external_value(PARAM_BOOL, 'Can the current user manage the user\'s evidence'),
'userid' => new external_value(PARAM_INT, 'The user ID'),
'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'),
'evidence' => new external_multiple_structure(
user_evidence_exporter::get_read_structure()
),
'evidence' => new external_multiple_structure(user_evidence_summary_exporter::get_read_structure()),
'navigation' => new external_multiple_structure(
new external_value(PARAM_RAW, 'HTML for a navigation item that should be on this page')
),
@ -4109,8 +4111,8 @@ class external extends external_api {
*/
public static function data_for_user_evidence_page_returns() {
return new external_single_structure(array(
'userevidence' => user_evidence_exporter::get_read_structure(),
'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'),
'userevidence' => user_evidence_summary_exporter::get_read_structure(),
'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site')
));
}
@ -4197,6 +4199,43 @@ class external extends external_api {
return new external_value(PARAM_BOOL, 'True if the delete was successful');
}
/**
* Returns description of external function parameters.
*
* @return \external_function_parameters
*/
public static function request_review_of_user_evidence_linked_competencies_parameters() {
return new external_function_parameters(array(
'id' => new external_value(PARAM_INT, 'The user evidence ID.')
));
}
/**
* Send user evidence competencies to review.
*
* @param int $id The user evidence id.
* @return boolean
*/
public static function request_review_of_user_evidence_linked_competencies($id) {
$params = self::validate_parameters(self::request_review_of_user_evidence_linked_competencies_parameters(), array(
'id' => $id
));
$userevidence = api::read_user_evidence($id);
self::validate_context($userevidence->get_context());
return api::request_review_of_user_evidence_linked_competencies($id);
}
/**
* Returns description of external function result value.
*
* @return \external_description
*/
public static function request_review_of_user_evidence_linked_competencies_returns() {
return new external_value(PARAM_BOOL, 'True if all competencies were send to review');
}
/**
* Returns the description of the get_scale_values() parameters.
*

View File

@ -0,0 +1,70 @@
<?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 evidence competency data.
*
* @package tool_lp
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
use moodle_url;
use renderer_base;
/**
* Class for exporting user evidence competency data.
*
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_competency_summary_exporter extends exporter {
protected static function define_related() {
return array('competency' => '\\tool_lp\\competency',
'usercompetency' => '\\tool_lp\\user_competency',
'scale' => 'grade_scale',
'context' => '\\context'
);
}
protected static function define_other_properties() {
return array(
'competency' => array(
'type' => competency_exporter::read_properties_definition()
),
'usercompetency' => array(
'type' => user_competency_exporter::read_properties_definition(),
)
);
}
protected function get_other_values(renderer_base $output) {
$competencyexporter = new competency_exporter($this->related['competency'],
array('context' => $this->related['context']));
$usercompetencyexporter = new user_competency_exporter($this->related['usercompetency'],
array('scale' => $this->related['scale']));
$values = array(
'competency' => $competencyexporter->export($output),
'usercompetency' => $usercompetencyexporter->export($output)
);
return $values;
}
}

View File

@ -0,0 +1,137 @@
<?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 evidence with all competencies.
*
* @package tool_lp
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use tool_lp\api;
use moodle_url;
use renderer_base;
use tool_lp\external\user_evidence_competency_summary_exporter;
/**
* Class for exporting user evidence with all competencies.
*
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_summary_exporter extends persistent_exporter {
protected static function define_class() {
return 'tool_lp\\user_evidence';
}
protected static function define_other_properties() {
return array(
'canmanage' => array(
'type' => PARAM_BOOL
),
'filecount' => array(
'type' => PARAM_INT
),
'files' => array(
'type' => stored_file_exporter::read_properties_definition(),
'multiple' => true
),
'hasurlorfiles' => array(
'type' => PARAM_BOOL
),
'urlshort' => array(
'type' => PARAM_TEXT
),
'competencycount' => array(
'type' => PARAM_INT
),
'usercompetencies' => array(
'type' => user_evidence_competency_summary_exporter::read_properties_definition(),
'optional' => true,
'multiple' => true
),
);
}
protected function get_other_values(renderer_base $output) {
$urlshort = '';
$url = $this->persistent->get_url();
if (!empty($url)) {
$murl = new moodle_url($url);
$shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false));
$urlshort = shorten_text($shorturl, 30, true);
}
$files = array();
$storedfiles = $this->persistent->get_files();
if (!empty($storedfiles)) {
foreach ($storedfiles as $storedfile) {
$fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context']));
$files[] = $fileexporter->export($output);
}
}
$userevidencecompetencies = array();
$frameworks = array();
$scales = array();
$usercompetencies = $this->persistent->get_user_competencies();
foreach ($usercompetencies as $usercompetency) {
$competency = $usercompetency->get_competency();
// Get the framework.
if (!isset($frameworks[$competency->get_competencyframeworkid()])) {
$frameworks[$competency->get_competencyframeworkid()] = $competency->get_framework();
}
$framework = $frameworks[$competency->get_competencyframeworkid()];
// Get the scale.
$scaleid = $competency->get_scaleid();
if ($scaleid === null) {
$scaleid = $framework->get_scaleid();
}
if (!isset($scales[$framework->get_scaleid()])) {
$scales[$framework->get_scaleid()] = $framework->get_scale();
}
$scale = $scales[$framework->get_scaleid()];
$related = array('competency' => $competency,
'usercompetency' => $usercompetency,
'scale' => $scale,
'context' => $framework->get_context());
$userevidencecompetencysummaryexporter = new user_evidence_competency_summary_exporter(null, $related);
$userevidencecompetencies[] = $userevidencecompetencysummaryexporter->export($output);
}
$values = array(
'canmanage' => $this->persistent->can_manage(),
'filecount' => count($files),
'files' => $files,
'hasurlorfiles' => !empty($files) || !empty($url),
'urlshort' => $urlshort,
'competencycount' => count($userevidencecompetencies),
'usercompetencies' => $userevidencecompetencies
);
return $values;
}
}

View File

@ -30,7 +30,7 @@ use stdClass;
use single_button;
use moodle_url;
use tool_lp\api;
use tool_lp\external\user_evidence_exporter;
use tool_lp\external\user_evidence_summary_exporter;
use tool_lp\user_evidence;
use context_user;
@ -93,12 +93,10 @@ class user_evidence_list_page implements renderable, templatable {
$data->evidence = array();
if ($this->evidence) {
foreach ($this->evidence as $evidence) {
$evidenceexporter = new user_evidence_exporter($evidence, array(
'context' => $this->context,
'competencies' => $evidence->get_competencies()
$userevidencesummaryexporter = new user_evidence_summary_exporter($evidence, array(
'context' => $this->context
));
$record = $evidenceexporter->export($output);
$data->evidence[] = $record;
$data->evidence[] = $userevidencesummaryexporter->export($output);
}
}

View File

@ -28,8 +28,7 @@ use renderable;
use templatable;
use stdClass;
use tool_lp\api;
use tool_lp\external\competency_exporter;
use tool_lp\external\user_evidence_exporter;
use tool_lp\external\user_evidence_summary_exporter;
/**
* User evidence page class.
@ -64,12 +63,12 @@ class user_evidence_page implements renderable, templatable {
*/
public function export_for_template(\renderer_base $output) {
$data = new stdClass();
$evidenceexporter = new user_evidence_exporter($this->userevidence, array(
'context' => $this->context,
'competencies' => $this->userevidence->get_competencies()
));
$data->userevidence = $evidenceexporter->export($output);
$userevidencesummaryexporter = new user_evidence_summary_exporter($this->userevidence, array(
'context' => $this->context));
$data->userevidence = $userevidencesummaryexporter->export($output);
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
return $data;
}
}

View File

@ -103,6 +103,13 @@ class user_evidence extends persistent {
return user_evidence_competency::get_competencies_by_userevidenceid($this->get_id());
}
/**
* Get link user competencies.
*/
public function get_user_competencies() {
return user_evidence_competency::get_user_competencies_by_userevidenceid($this->get_id());
}
/**
* Return the files associated with this evidence.
*

View File

@ -105,6 +105,33 @@ class user_evidence_competency extends persistent {
return $competencies;
}
/**
* Get user competencies by user evidence ID.
*
* @param int $userevidenceid The user evidence ID.
* @return user_competency[]
*/
public static function get_user_competencies_by_userevidenceid($userevidenceid) {
global $DB;
$sql = "SELECT uc.*
FROM {" . user_competency::TABLE . "} uc
JOIN {" . self::TABLE . "} uec
ON uc.competencyid = uec.competencyid
JOIN {" . user_evidence::TABLE . "} ue
ON uec.userevidenceid = ue.id
AND uc.userid = ue.userid
AND ue.id = ?";
$usercompetencies = array();
$records = $DB->get_recordset_sql($sql, array($userevidenceid));
foreach ($records as $record) {
$usercompetencies[] = new user_competency(0, $record);
}
$records->close();
return $usercompetencies;
}
/**
* Get a relation.
*

View File

@ -890,5 +890,14 @@ $functions = array(
'capabilities' => 'tool/lp:templateread',
'ajax' => true,
),
'tool_lp_request_review_of_user_evidence_linked_competencies' => array(
'classname' => 'tool_lp\external',
'methodname' => 'request_review_of_user_evidence_linked_competencies',
'classpath' => '',
'description' => 'Send user evidence competencies in review',
'type' => 'write',
'capabilities' => 'tool/lp:userevidencemanageown',
'ajax' => true,
),
);

View File

@ -292,6 +292,7 @@ $string['reviewstatus'] = 'Review status';
$string['requestreview'] = 'Request review';
$string['reopenplan'] = 'Reopen this learning plan';
$string['reopenplanconfirm'] = 'Reopen the plan \'{$a}\'? The status of the users competencies that was recorded at the time the plan was previously completed will be deleted, and the plan will become active again.';
$string['reviewer'] = 'Reviewer';
$string['savechanges'] = 'Save changes';
$string['scale'] = 'Scale';
$string['scale_help'] = 'A scale determines how proficiency is measured in a competency. After selecting a scale, configure the scale, setting one of the scale values as default and marking all scale values that are deemed proficient.';
@ -301,6 +302,8 @@ $string['selectcompetencymovetarget'] = 'Select a location to move this competen
$string['selectedcompetency'] = 'Selected competency';
$string['selectcohortstosync'] = 'Select cohorts to sync';
$string['selectuserstocreateplansfor'] = 'Select users to create plans for';
$string['sendcompetenciestoreview'] = 'Send competencies for review';
$string['sendallcompetenciestoreview'] = 'Send all competencies in review for evidence of prior learning \'{$a}\'';
$string['shortname'] = 'Name';
$string['startreview'] = 'Start review';
$string['state'] = 'State';
@ -412,7 +415,7 @@ $string['userevidencecreated'] = 'Evidence of prior learning created';
$string['userevidencedescription'] = 'Description';
$string['userevidencefiles'] = 'Files';
$string['userevidencename'] = 'Name';
$string['userevidenceummary'] = 'Summary';
$string['userevidencesummary'] = 'Summary';
$string['userevidenceupdated'] = 'Evidence of prior learning updated';
$string['userevidenceurl'] = 'URL';
$string['userplans'] = 'User plans';

View File

@ -27,6 +27,10 @@
</ul>
<div data-region="link-buttons">
<div>
<input id="send-for-review-checkbox" type="checkbox" value="true" data-action="request-review">
<label for="send-for-review-checkbox">{{#str}}sendcompetenciestoreview, tool_lp{{/str}}</label>
</div>
<input type="button" data-action="add" value="{{#str}}add{{/str}}"/>
<input type="button" data-action="cancel" value="{{#str}}cancel{{/str}}"/>
</div>

View File

@ -39,8 +39,8 @@
<thead>
<tr>
<th scope="col" width="20%">{{#str}}userevidencename, tool_lp{{/str}}</th>
<th scope="col">{{#str}}userevidenceummary, tool_lp{{/str}}</th>
<th scope="col">{{#str}}linkedcompetencies, tool_lp{{/str}}</th>
<th scope="col">{{#str}}userevidencesummary, tool_lp{{/str}}</th>
<th scope="col">{{#str}}linkedcompetencies, tool_lp{{/str}} ({{#str}}status, tool_lp{{/str}} / {{#str}}reviewer, tool_lp{{/str}})</th>
{{#canmanage}}
<th scope="col">{{#str}}actions, tool_lp{{/str}}</th>
{{/canmanage}}
@ -71,11 +71,11 @@
{{/competencycount}}
{{#competencycount}}
<ul class="user-evidence-competencies">
{{#competencies}}
{{#usercompetencies}}
<li>
{{shortname}} <small><em>{{idnumber}}</em></small>
{{competency.shortname}} <small><em>{{competency.idnumber}}</em></small> ({{usercompetency.statusname}}{{#usercompetency.reviewer.fullname}} / {{usercompetency.reviewer.fullname}}{{/usercompetency.reviewer.fullname}})
</li>
{{/competencies}}
{{/usercompetencies}}
</ul>
{{/competencycount}}
</td>
@ -96,6 +96,11 @@
{{#pix}}t/add{{/pix}} {{#str}}linkcompetencies, tool_lp{{/str}}
</a>
</li>
<li>
<a data-action="send-competencies-review" href="#">
{{#pix}}t/edit{{/pix}} {{#str}}sendcompetenciestoreview, tool_lp{{/str}}
</a>
</li>
<li>
<a data-action="user-evidence-delete" href="#">
{{#pix}}t/delete{{/pix}} {{#str}}deletethisuserevidence, tool_lp{{/str}}

View File

@ -59,26 +59,30 @@
<thead>
<tr>
<th scope="col">{{#str}}shortname, tool_lp{{/str}}</th>
{{#userevidence.canmanage}}
<th scope="col">{{#str}}status, tool_lp{{/str}} / {{#str}}reviewer, tool_lp{{/str}}</th>
{{#canmanage}}
<th scope="col">{{#str}}actions, tool_lp{{/str}}</th>
{{/userevidence.canmanage}}
{{/canmanage}}
</tr>
</thead>
<tbody>
{{#competencies}}
<tr data-id="{{id}}">
{{#usercompetencies}}
<tr data-id="{{competency.id}}">
<td>
<a href="#" data-action="competency-dialogue" data-id="{{id}}">{{shortname}}</a>
<a href="{{pluginbaseurl}}/user_competency.php?id={{usercompetency.id}}" data-id="{{usercompetency.id}}">{{competency.shortname}}</a>
</td>
<td>
{{usercompetency.statusname}} {{#usercompetency.reviewer.fullname}} / {{usercompetency.reviewer.fullname}}{{/usercompetency.reviewer.fullname}}
</td>
{{#userevidence.canmanage}}
<td>
<div class="pull-left">
<a href="#" data-action="delete-competency-link" data-id="{{id}}">{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
<a href="#" data-action="delete-competency-link" data-id="{{competency.id}}">{{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}</a>
</div>
</td>
{{/userevidence.canmanage}}
</tr>
{{/competencies}}
{{/usercompetencies}}
</tbody>
</table>

View File

@ -0,0 +1,92 @@
<?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/>.
/**
* User evidence competency persistent class tests.
*
* @package tool_lp
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use tool_lp\user_evidence_competency;
/**
* User evidence competency persistent testcase.
*
* @package tool_lp
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_user_evidene_competency_testcase extends advanced_testcase {
public function test_get_user_competencies_by_userevidenceid() {
global $CFG, $DB;
$this->resetAfterTest(true);
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('tool_lp');
$u1 = $dg->create_user();
// Create framework with competencies.
$fw = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
$c2 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
$c3 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
$c4 = $lpg->create_competency(array('competencyframeworkid' => $fw->get_id()));
// Create a plan with competencies.
$p1 = $lpg->create_plan(array('userid' => $u1->id));
$lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c1->get_id()));
$lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c2->get_id()));
$lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c3->get_id()));
$lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c4->get_id()));
// Create a prior learning evidence and link competencies.
$ue1 = $lpg->create_user_evidence(array('userid' => $u1->id));
$uec11 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get_id(), 'competencyid' => $c1->get_id()));
$uec12 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get_id(), 'competencyid' => $c2->get_id()));
$uec13 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue1->get_id(), 'competencyid' => $c3->get_id()));
$uc11 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c1->get_id()));
$uc12 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c2->get_id()));
$uc13 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c3->get_id()));
// Create an other prior learning evidence and link competencies.
$ue2 = $lpg->create_user_evidence(array('userid' => $u1->id));
$uec22 = $lpg->create_user_evidence_competency(array('userevidenceid' => $ue2->get_id(), 'competencyid' => $c4->get_id()));
$uc22 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c4->get_id()));
// Check the user competencies associated to the first prior learning evidence.
$ucs = user_evidence_competency::get_user_competencies_by_userevidenceid($ue1->get_id());
$this->assertCount(3, $ucs);
$uc = array_shift($ucs);
$this->assertEquals($uc->get_id(), $uc11->get_id());
$uc = array_shift($ucs);
$this->assertEquals($uc->get_id(), $uc12->get_id());
$uc = array_shift($ucs);
$this->assertEquals($uc->get_id(), $uc13->get_id());
// Check the user competencies associated to the second prior learning evidence.
$ucs = user_evidence_competency::get_user_competencies_by_userevidenceid($ue2->get_id());
$this->assertCount(1, $ucs);
$uc = array_shift($ucs);
$this->assertEquals($uc->get_id(), $uc22->get_id());
}
}