MDL-50439 tool_lp: Remove support for user competency review from course

This commit is contained in:
Frederic Massart
2016-04-18 10:58:52 +08:00
parent 7bb5ccbee6
commit 3b11d6386d
6 changed files with 116 additions and 155 deletions
+50 -8
View File
@@ -937,7 +937,7 @@ class api {
$capabilities = array('tool/lp:coursecompetencyread', 'tool/lp:coursecompetencymanage');
if (!has_any_capability($capabilities, $context)) {
throw new required_capability_exception($context, 'tool/lp:coursecompetencyread', 'nopermissions', '');
} else if (!user_competency::can_read_user($userid, $competencyid)) {
} else if (!user_competency::can_read_user_in_course($userid, $courseid)) {
throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
}
@@ -2516,7 +2516,7 @@ class api {
$plan = new plan($planorid);
}
if (!user_competency::can_read_user($plan->get_userid(), $competencyid)) {
if (!user_competency::can_read_user($plan->get_userid())) {
throw new required_capability_exception($plan->get_context(), 'tool/lp:usercompetencyview', 'nopermissions', '');
}
@@ -3277,11 +3277,16 @@ class api {
}
/**
* List all the evidence for a user competency
* List all the evidence for a user competency.
*
* @param int $userid The user id - only used if usercompetencyid is 0.
* @param int $competencyid The competency id - only used it usercompetencyid is 0.
* @param int $planid The plan id - not used yet - but can be used to only list archived evidence if a plan is completed.
* @param string $sort The field to sort the evidence by.
* @param string $order The ordering of the sorting.
* @param int $skip Number of records to skip.
* @param int $limit Number of records to return.
* @return \tool_lp\evidence[]
* @return array of \tool_lp\evidence
*/
public static function list_evidence($userid = 0,
@@ -3292,7 +3297,7 @@ class api {
$skip = 0,
$limit = 0) {
if (!user_competency::can_read_user($userid, $competencyid)) {
if (!user_competency::can_read_user($userid)) {
$context = context_user::instance($userid);
throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
}
@@ -3307,6 +3312,43 @@ class api {
return evidence::get_records(array('usercompetencyid' => $usercompetency->get_id()), $sort, $order, $skip, $limit);
}
/**
* List all the evidence for a user competency in a course.
*
* @param int $userid The user ID.
* @param int $courseid The course ID.
* @param int $competencyid The competency ID.
* @param string $sort The field to sort the evidence by.
* @param string $order The ordering of the sorting.
* @param int $skip Number of records to skip.
* @param int $limit Number of records to return.
* @return \tool_lp\evidence[]
*/
public static function list_evidence_in_course($userid = 0,
$courseid = 0,
$competencyid = 0,
$sort = 'timecreated',
$order = 'DESC',
$skip = 0,
$limit = 0) {
if (!user_competency::can_read_user_in_course($userid, $courseid)) {
$context = context_user::instance($userid);
throw new required_capability_exception($context, 'tool/lp:usercompetencyview', 'nopermissions', '');
}
$usercompetency = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
if (!$usercompetency) {
return array();
}
$params = array(
'usercompetencyid' => $usercompetency->get_id(),
'contextid' => context_course::instance($courseid)->id
);
return evidence::get_records($params, $sort, $order, $skip, $limit);
}
/**
* Create an evidence from a list of parameters.
*
@@ -3623,11 +3665,11 @@ class api {
$context = $plan->get_context();
if ($override) {
if (!user_competency::can_grade_user($plan->get_userid(), $competencyid)) {
if (!user_competency::can_grade_user($plan->get_userid())) {
throw new required_capability_exception($context, 'tool/lp:competencygrade', 'nopermissions', '');
}
} else {
if (!user_competency::can_suggest_grade_user($plan->get_userid(), $competencyid)) {
if (!user_competency::can_suggest_grade_user($plan->get_userid())) {
throw new required_capability_exception($context, 'tool/lp:competencysuggestgrade', 'nopermissions', '');
}
}
@@ -3678,11 +3720,11 @@ class api {
}
$context = context_course::instance($course->id);
if ($override) {
if (!user_competency::can_grade_user($userid, $competencyid)) {
if (!user_competency::can_grade_user_in_course($userid, $course->id)) {
throw new required_capability_exception($context, 'tool/lp:competencygrade', 'nopermissions', '');
}
} else {
if (!user_competency::can_suggest_grade_user($userid, $competencyid)) {
if (!user_competency::can_suggest_grade_user_in_course($userid, $course->id)) {
throw new required_capability_exception($context, 'tool/lp:competencysuggestgrade', 'nopermissions', '');
}
}
@@ -101,8 +101,8 @@ class user_competency_summary_exporter extends exporter {
$result->competency = $exporter->export($output);
$context = context_user::instance($this->related['user']->id);
$result->cangrade = user_competency::can_grade_user($this->related['user']->id, $competency->get_id());
$result->cansuggest = user_competency::can_suggest_grade_user($this->related['user']->id, $competency->get_id());
$result->cangrade = user_competency::can_grade_user($this->related['user']->id);
$result->cansuggest = user_competency::can_suggest_grade_user($this->related['user']->id);
$result->cangradeorsuggest = $result->cangrade || $result->cansuggest;
if ($this->related['user']) {
$exporter = new user_summary_exporter($this->related['user']);
@@ -150,7 +150,7 @@ class user_competency_summary_exporter extends exporter {
$usercompetency = !empty($this->related['usercompetency']) ? $this->related['usercompetency'] : null;
if (!empty($usercompetency)) {
if (!empty($usercompetency) && $usercompetency->can_read_comments()) {
$commentareaexporter = new comment_area_exporter($usercompetency->get_comment_object());
$result->commentarea = $commentareaexporter->export($output);
}
@@ -27,6 +27,7 @@ use renderable;
use renderer_base;
use templatable;
use tool_lp\api;
use tool_lp\user_competency;
use tool_lp\external\user_competency_summary_in_course_exporter;
/**
@@ -77,7 +78,7 @@ class user_competency_summary_in_course implements renderable, templatable {
$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);
$evidence = api::list_evidence_in_course($this->userid, $this->courseid, $this->competencyid);
$course = $DB->get_record('course', array('id' => $this->courseid));
$params = array(
@@ -91,6 +92,13 @@ class user_competency_summary_in_course implements renderable, templatable {
$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);
$data->usercompetencysummary->cansuggest =
user_competency::can_suggest_grade_user_in_course($this->userid, $this->courseid);
$data->usercompetencysummary->cangradeorsuggest = $data->usercompetencysummary->cangrade
|| $data->usercompetencysummary->cansuggest;
return $data;
}
}
+47 -126
View File
@@ -96,7 +96,7 @@ class user_competency extends persistent {
* @return bool
*/
public function can_comment() {
return static::can_comment_user($this->get_userid(), $this->get_competencyid());
return static::can_comment_user($this->get_userid());
}
/**
@@ -105,7 +105,7 @@ class user_competency extends persistent {
* @return bool
*/
public function can_read() {
return static::can_read_user($this->get_userid(), $this->get_competencyid());
return static::can_read_user($this->get_userid());
}
/**
@@ -114,29 +114,25 @@ class user_competency extends persistent {
* @return bool
*/
public function can_read_comments() {
return static::can_read_comments_user($this->get_userid(), $this->get_competencyid());
return static::can_read_comments_user($this->get_userid());
}
/**
* Can the current user send the user competency for review?
*
* This also performs checks in relevant courses.
*
* @return bool
*/
public function can_request_review() {
return static::can_request_review_user($this->get_userid(), $this->get_competencyid());
return static::can_request_review_user($this->get_userid());
}
/**
* Can the current user review the user competency?
*
* This also performs checks in relevant courses.
*
* @return bool
*/
public function can_review() {
return static::can_review_user($this->get_userid(), $this->get_competencyid());
return static::can_review_user($this->get_userid());
}
/**
@@ -333,13 +329,10 @@ class user_competency extends persistent {
/**
* Can the current user comment on a user's competency?
*
* This follows the same philosophy as {@link self::can_read_user()}.
*
* @param int $userid The user ID the competency belongs to.
* @param int $competencyid The competency ID.
* @return bool
*/
public static function can_comment_user($userid, $competencyid) {
public static function can_comment_user($userid) {
global $USER;
$capabilities = array('tool/lp:usercompetencycomment');
@@ -351,128 +344,80 @@ class user_competency extends persistent {
return true;
}
$courses = course_competency::get_courses_with_competency_and_user($competencyid, $userid);
foreach ($courses as $course) {
if (has_any_capability($capabilities, context_course::instance($course->id))) {
return true;
}
}
return false;
}
/**
* Can the current user grade a user's user competency?
*
* This follows the same philosophy as {@link self::can_read_user()}.
*
* @param int $userid The user ID the competency belongs to.
* @param int $competencyid The competency ID.
* @return bool
*/
public static function can_grade_user($userid, $competencyid) {
public static function can_grade_user($userid) {
$ratecap = 'tool/lp:competencygrade';
if (has_capability($ratecap, context_user::instance($userid))) {
return true;
}
return has_capability($ratecap, context_user::instance($userid));
}
$courses = course_competency::get_courses_with_competency_and_user($competencyid, $userid);
foreach ($courses as $course) {
$context = context_course::instance($course->id);
if (has_capability($ratecap, $context) && has_capability('tool/lp:coursecompetencygradable', $context, $userid)) {
// We must be able to grade, and the user must be 'gradable'.
return true;
}
}
return false;
/**
* Can the current user grade a user's user competency in a course?
*
* @param int $userid The user ID the competency belongs to.
* @param int $courseid The course ID.
* @return bool
*/
public static function can_grade_user_in_course($userid, $courseid) {
$ratecap = 'tool/lp:competencygrade';
return has_capability($ratecap, context_course::instance($courseid))
|| static::can_grade_user($userid);
}
/**
* Can the current user read the comments on a user's competency?
*
* This follows the same philosophy as {@link self::can_read_user()}.
*
* @param int $userid The user ID the competency belongs to.
* @param int $competencyid The competency ID.
* @return bool
*/
public static function can_read_comments_user($userid, $competencyid) {
public static function can_read_comments_user($userid) {
// Everyone who can read the user competency can read the comments.
return static::can_read_user($userid, $competencyid);
return static::can_read_user($userid);
}
/**
* Can the current user read the user competencies of a user in a course?
*
* This method is useful when the competency IDs are not known in advance, but the course is.
* Though this removes a level of granirality as it will not check other courses in which
* a user could have access to the user competency, therefore not following the
* philosophy "If you can view it somewhere, you can view it anywhere.".
*
* Only use this when you want to check for "all or nothing".
*
* @param int $userid The user ID the competency belongs to.
* @param int $courseid The course ID.
* @return bool
*/
public static function can_read_user_in_course($userid, $courseid) {
$capability = 'tool/lp:usercompetencyview';
return plan::can_read_user($userid)
|| has_capability($capability, context_user::instance($userid))
|| has_capability($capability, context_course::instance($courseid));
return has_capability($capability, context_course::instance($courseid))
|| static::can_read_user($userid);
}
/**
* Can the current user read a user's competency?
*
* Following the philosophy "If you can view it somewhere, you can view it anywhere.",
* this methods checks if any of the following are true:
*
* - Can view the user's plans (user context).
* - Can view the user's user competencies (user context).
* - Can view the user's user competencies in courses where the user is enrolled (course context).
*
* Note that the competency ID is required, that's because if you're not passing it you're
* probably trying to check the wrong permissions. If you just to know if a user can read other
* users' competencies in a course, refer to {@link self::can_read_user_in_course()}, though its
* usage is not preferred. If you want to refer to a user context, for instance when viewing a plan,
* then you should simply refer to the permissions to read the plan. If you can read the plan, by
* definition you can read any of the user competencies it contains: {@link plan::can_read_user()}.
*
* @param int $userid The user ID the competency belongs to.
* @param int $competencyid The competency ID.
* @return bool
*/
public static function can_read_user($userid, $competencyid) {
public static function can_read_user($userid) {
$capability = 'tool/lp:usercompetencyview';
if (plan::can_read_user($userid)) {
return true;
} else if (has_capability($capability, context_user::instance($userid))) {
return true;
}
$courses = course_competency::get_courses_with_competency_and_user($competencyid, $userid);
foreach ($courses as $course) {
if (has_capability($capability, context_course::instance($course->id))) {
return true;
}
}
return false;
return has_capability($capability, context_user::instance($userid))
|| plan::can_read_user($userid);
}
/**
* Can the current user send a user's competency for review?
*
* This follows the same philosophy as {@link self::can_read_user()}.
* Note that the status 'review' is not meant to be used for student to self-assess
* themselves, then to ask the teacher to review their assessment. It is more intended
* for a student to provide evidence of prior learning and request their review.
*
* @param int $userid The user ID the competency belongs to.
* @param int $competencyid The competency ID.
* @return bool
*/
public static function can_request_review_user($userid, $competencyid) {
public static function can_request_review_user($userid) {
global $USER;
$capabilities = array('tool/lp:usercompetencyrequestreview');
@@ -484,66 +429,42 @@ class user_competency extends persistent {
return true;
}
$courses = course_competency::get_courses_with_competency_and_user($competencyid, $userid);
foreach ($courses as $course) {
if (has_any_capability($capabilities, context_course::instance($course->id))) {
return true;
}
}
return false;
}
/**
* Can the current user review the user competency?
*
* This follows the same philosophy as {@link self::can_read_user()}.
*
* @param int $userid The user ID the competency belongs to.
* @param int $competencyid The competency ID.
* @return bool
*/
public static function can_review_user($userid, $competencyid) {
public static function can_review_user($userid) {
$capability = 'tool/lp:usercompetencyreview';
if (has_capability($capability, context_user::instance($userid))) {
return true;
}
$courses = course_competency::get_courses_with_competency_and_user($competencyid, $userid);
foreach ($courses as $course) {
if (has_capability($capability, context_course::instance($course->id))) {
return true;
}
}
return false;
return has_capability($capability, context_user::instance($userid));
}
/**
* Can the current user suggest a grade for a user's user competency?
*
* This follows the same philosophy as {@link self::can_read_user()}.
*
* @param int $userid The user ID the competency belongs to.
* @param int $competencyid The competency ID.
* @return bool
*/
public static function can_suggest_grade_user($userid, $competencyid) {
public static function can_suggest_grade_user($userid) {
$suggestcap = 'tool/lp:competencysuggestgrade';
if (has_capability($suggestcap, context_user::instance($userid))) {
return true;
}
return has_capability($suggestcap, context_user::instance($userid));
}
$courses = course_competency::get_courses_with_competency_and_user($competencyid, $userid);
foreach ($courses as $course) {
$context = context_course::instance($course->id);
if (has_capability($suggestcap, $context) && has_capability('tool/lp:coursecompetencygradable', $context, $userid)) {
// We must be able to suggest a grade, and the user must be 'gradable'.
return true;
}
}
return false;
/**
* Can the current user suggest a grade for a user's user competency in a course?
*
* @param int $userid The user ID the competency belongs to.
* @param int $courseid The course ID.
* @return bool
*/
public static function can_suggest_grade_user_in_course($userid, $courseid) {
$suggestcap = 'tool/lp:competencysuggestgrade';
return has_capability($suggestcap, context_course::instance($courseid))
|| static::can_suggest_grade_user($userid);
}
/**
+6 -6
View File
@@ -180,41 +180,41 @@ $capabilities = array(
// User competencies.
'tool/lp:usercompetencyview' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE, // And CONTEXT_USER.
'contextlevel' => CONTEXT_USER, // And CONTEXT_COURSE.
'archetypes' => array(
'editingteacher' => CAP_ALLOW
)
),
'tool/lp:usercompetencyrequestreview' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, // And CONTEXT_USER.
'contextlevel' => CONTEXT_USER,
'archetypes' => array(
)
),
'tool/lp:usercompetencyrequestreviewown' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, // And CONTEXT_USER.
'contextlevel' => CONTEXT_USER,
'archetypes' => array(
'user' => CAP_ALLOW
)
),
'tool/lp:usercompetencyreview' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, // And CONTEXT_USER.
'contextlevel' => CONTEXT_USER,
'archetypes' => array(
),
'clonepermissionsfrom' => 'moodle/site:config'
),
'tool/lp:usercompetencycomment' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, // And CONTEXT_USER.
'contextlevel' => CONTEXT_USER,
'archetypes' => array(
),
'clonepermissionsfrom' => 'moodle/site:config'
),
'tool/lp:usercompetencycommentown' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE, // And CONTEXT_USER.
'contextlevel' => CONTEXT_USER,
'archetypes' => array(
'user' => CAP_ALLOW
),
@@ -53,11 +53,6 @@
{{#isstatusinreview}}
- {{reviewer.fullname}}
{{/isstatusinreview}}
{{#isrequestreviewallowed}}<button data-action="request-review">{{#str}}requestreview, tool_lp{{/str}}</button>{{/isrequestreviewallowed}}
{{#iscancelreviewrequestallowed}}<button data-action="cancel-review-request">{{#str}}cancelreviewrequest, tool_lp{{/str}}</button>{{/iscancelreviewrequestallowed}}
{{#isstartreviewallowed}}<button data-action="start-review">{{#str}}startreview, tool_lp{{/str}}</button>{{/isstartreviewallowed}}
{{#isstopreviewallowed}}<button data-action="stop-review">{{#str}}stopreview, tool_lp{{/str}}</button>{{/isstopreviewallowed}}
</dd>
<dt>{{#str}}proficient, tool_lp{{/str}}</dt>
<dd>
@@ -86,18 +81,13 @@
{{/cangradeorsuggest}}
</dd>
{{#js}}
require(['jquery', 'tool_lp/grade_user_competency_inline', 'tool_lp/user_competency_info', 'tool_lp/user_competency_workflow'], function($, mod, info, UserCompWorkflow) {
require(['jquery', 'tool_lp/grade_user_competency_inline', 'tool_lp/user_competency_info'], function($, mod, info) {
var scaleConfig = JSON.parse('{{{competency.scaleconfiguration}}}');
var inlineGrader = new mod('grade-competency-form-{{uniqid}}', scaleConfig, '{{competency.competency.id}}', '{{user.id}}', '', '{{course.id}}', '{{#str}}chooserating, tool_lp{{/str}}');
var competencyElement = $('[data-region-id="{{uniqid}}"]');
var infoReloader = new info(competencyElement, '{{competency.competency.id}}', '{{user.id}}', '', '{{course.id}}');
var ucw = new UserCompWorkflow();
ucw.registerEvents('[data-region="user-competency-status"]');
ucw.on('status-changed', infoReloader.reload.bind(infoReloader));
ucw.on('error-occured', infoReloader.reload.bind(infoReloader));
inlineGrader.on('competencyupdated', infoReloader.reload.bind(infoReloader));
});