Fixed bugs in invitation system
This commit is contained in:
parent
b8a3394fe4
commit
f6b53a1623
3 changed files with 65 additions and 11 deletions
|
@ -28,6 +28,7 @@ require_once($CFG->libdir.'/gradelib.php');
|
||||||
require_once($CFG->dirroot.'/course/lib.php');
|
require_once($CFG->dirroot.'/course/lib.php');
|
||||||
|
|
||||||
use core_competency\course_competency;
|
use core_competency\course_competency;
|
||||||
|
use core_competency\user_competency_course;
|
||||||
use core_competency\competency;
|
use core_competency\competency;
|
||||||
use core_competency\api as c_api;
|
use core_competency\api as c_api;
|
||||||
use core_competency\competency_rule_points;
|
use core_competency\competency_rule_points;
|
||||||
|
@ -427,12 +428,14 @@ class coursecompetencyinfo {
|
||||||
*/
|
*/
|
||||||
public function course_competencies() {
|
public function course_competencies() {
|
||||||
$list = [];
|
$list = [];
|
||||||
// First retrieve all the competencies associates with this course.
|
|
||||||
$coursecompetencies = c_api::list_course_competencies($this->course->id);
|
$coursecompetencies = course_competency::list_course_competencies($this->course->id);
|
||||||
// Next create the data model, and check user proficiency for each competency.
|
$competencies = course_competency::list_competencies($this->course->id);
|
||||||
foreach($coursecompetencies as $ccinfo) {
|
|
||||||
$list[] = $ccinfo['competency'];
|
foreach ($coursecompetencies as $key => $coursecompetency) {
|
||||||
|
$list[] = $competencies[$coursecompetency->get('competencyid')];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,6 +458,56 @@ class coursecompetencyinfo {
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user competency. (Copied from competency api and stripped out permission checks)
|
||||||
|
*
|
||||||
|
* @param int $userid The user ID.
|
||||||
|
* @param int $competencyid The competency ID.
|
||||||
|
* @return user_competency
|
||||||
|
*/
|
||||||
|
public static function get_user_competency($userid, $competencyid) {
|
||||||
|
c_api::require_enabled();
|
||||||
|
$existing = user_competency::get_multiple($userid, array($competencyid));
|
||||||
|
$uc = array_pop($existing);
|
||||||
|
|
||||||
|
if (!$uc) {
|
||||||
|
$uc = user_competency::create_relation($userid, $competencyid);
|
||||||
|
$uc->create();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $uc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user competency in a course. (Copied from competency api and stripped out permission checks)
|
||||||
|
*
|
||||||
|
* @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_course
|
||||||
|
*/
|
||||||
|
public static function get_user_competency_in_course($courseid, $userid, $competencyid) {
|
||||||
|
c_api::require_enabled();
|
||||||
|
// First we do a permissions check.
|
||||||
|
$context = \context_course::instance($courseid);
|
||||||
|
|
||||||
|
// This will throw an exception if the competency does not belong to the course.
|
||||||
|
$competency = course_competency::get_competency($courseid, $competencyid);
|
||||||
|
|
||||||
|
$params = array('courseid' => $courseid, 'userid' => $userid, 'competencyid' => $competencyid);
|
||||||
|
$exists = user_competency_course::get_record($params);
|
||||||
|
// Create missing.
|
||||||
|
if ($exists) {
|
||||||
|
$ucc = $exists;
|
||||||
|
} else {
|
||||||
|
$ucc = user_competency_course::create_relation($userid, $competency->get('id'), $courseid);
|
||||||
|
$ucc->create();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ucc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve course proficiency and overall proficiency for a competency and user
|
* Retrieve course proficiency and overall proficiency for a competency and user
|
||||||
*
|
*
|
||||||
|
@ -469,7 +522,7 @@ class coursecompetencyinfo {
|
||||||
$competencyid = $competency->get('id');
|
$competencyid = $competency->get('id');
|
||||||
$r = new \stdClass();
|
$r = new \stdClass();
|
||||||
|
|
||||||
$uc = c_api::get_user_competency($userid, $competencyid);
|
$uc = self::get_user_competency($userid, $competencyid);
|
||||||
$proficiency = $uc->get('proficiency');
|
$proficiency = $uc->get('proficiency');
|
||||||
$r->proficient = $proficiency;
|
$r->proficient = $proficiency;
|
||||||
$r->grade = $scale->get_nearest_item($uc->get('grade'));
|
$r->grade = $scale->get_nearest_item($uc->get('grade'));
|
||||||
|
@ -477,7 +530,7 @@ class coursecompetencyinfo {
|
||||||
$r->failed = $proficiency === false;
|
$r->failed = $proficiency === false;
|
||||||
try {
|
try {
|
||||||
// Only add course grade and proficiency if the competency is included in the course.
|
// Only add course grade and proficiency if the competency is included in the course.
|
||||||
$ucc = c_api::get_user_competency_in_course($this->course->id,$userid,$competencyid);
|
$ucc = self::get_user_competency_in_course($this->course->id,$userid,$competencyid);
|
||||||
$r->courseproficient = $ucc->get('proficiency');
|
$r->courseproficient = $ucc->get('proficiency');
|
||||||
$r->coursegrade = $scale->get_nearest_item($ucc->get('grade'));
|
$r->coursegrade = $scale->get_nearest_item($ucc->get('grade'));
|
||||||
} catch (\Exception $x) {}
|
} catch (\Exception $x) {}
|
||||||
|
@ -495,7 +548,7 @@ class coursecompetencyinfo {
|
||||||
*/
|
*/
|
||||||
public function retrievefeedback($competency, $userid) {
|
public function retrievefeedback($competency, $userid) {
|
||||||
$competencyid = $competency->get('id');
|
$competencyid = $competency->get('id');
|
||||||
$uc = c_api::get_user_competency($userid, $competencyid);
|
$uc = self::get_user_competency($userid, $competencyid);
|
||||||
|
|
||||||
// Get evidences and sort by creation date (newest first)
|
// Get evidences and sort by creation date (newest first)
|
||||||
$evidence = evidence::get_records_for_usercompetency($uc->get('id'),\context_system::instance(),'timecreated', "DESC");
|
$evidence = evidence::get_records_for_usercompetency($uc->get('id'),\context_system::instance(),'timecreated', "DESC");
|
||||||
|
|
|
@ -556,7 +556,7 @@ class courseinfo {
|
||||||
* @return array [value,type] of the field for this
|
* @return array [value,type] of the field for this
|
||||||
*/
|
*/
|
||||||
protected function extrafields_value($fieldname,$includeteachervisible=false) {
|
protected function extrafields_value($fieldname,$includeteachervisible=false) {
|
||||||
|
global $PAGE;
|
||||||
if ($fieldname == "description") {
|
if ($fieldname == "description") {
|
||||||
// Process embedded files.
|
// Process embedded files.
|
||||||
$value = \file_rewrite_pluginfile_urls(
|
$value = \file_rewrite_pluginfile_urls(
|
||||||
|
@ -614,6 +614,7 @@ class courseinfo {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Everything else can just use the export value.
|
// Everything else can just use the export value.
|
||||||
|
$PAGE->set_context(\context_system::instance());
|
||||||
$value = $data->export_value();
|
$value = $data->export_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
lib.php
4
lib.php
|
@ -424,8 +424,8 @@ function local_treestudyplan_pluginfile(
|
||||||
$plan = studyplan::find_by_id($itemid);
|
$plan = studyplan::find_by_id($itemid);
|
||||||
$planctx = $plan->context();
|
$planctx = $plan->context();
|
||||||
|
|
||||||
// Check if the current user has access to this studyplan
|
// Studyplan icons are not secret, so don't check for access..
|
||||||
if ( webservicehelper::has_capabilities($studyplan_filecaps,$planctx) || $plan->has_linked_user($USER)) {
|
if ( true ) {
|
||||||
// Extract the filename / filepath from the $args array
|
// Extract the filename / filepath from the $args array
|
||||||
$filename = array_pop($args); // The last item in the $args array.
|
$filename = array_pop($args); // The last item in the $args array.
|
||||||
if (empty($args)) {
|
if (empty($args)) {
|
||||||
|
|
Loading…
Reference in a new issue