mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 18:06:51 +02:00
Merge branch 'MDL-54997-master' of git://github.com/damyon/moodle
This commit is contained in:
commit
f8ca380b47
3 changed files with 92 additions and 6 deletions
|
@ -4152,7 +4152,7 @@ class api {
|
|||
* @param int $limit Number of records to return.
|
||||
* @return \core_competency\evidence[]
|
||||
*/
|
||||
public static function list_evidence_in_course($userid = 0, $courseid = 0, $competencyid = 0, $sort = 'timecreated',
|
||||
public static function list_evidence_in_course($userid = 0, $courseid = 0, $competencyid = 0, $sort = 'timecreated, id',
|
||||
$order = 'DESC', $skip = 0, $limit = 0) {
|
||||
static::require_enabled();
|
||||
|
||||
|
@ -4166,11 +4166,8 @@ class api {
|
|||
return array();
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'usercompetencyid' => $usercompetency->get_id(),
|
||||
'contextid' => context_course::instance($courseid)->id
|
||||
);
|
||||
return evidence::get_records($params, $sort, $order, $skip, $limit);
|
||||
$context = context_course::instance($courseid);
|
||||
return evidence::get_records_for_usercompetency($usercompetency->get_id(), $context, $sort, $order, $skip, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -284,4 +284,52 @@ class evidence extends persistent {
|
|||
return has_capability('moodle/competency:evidencedelete', context_user::instance($userid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a list of records in a context for a user competency.
|
||||
*
|
||||
* @param int $usercompetencyid The id of the user competency.
|
||||
* @param context $context Context to filter the evidence list.
|
||||
* @param string $sort The field from the evidence table to sort on.
|
||||
* @param string $order The sort direction
|
||||
* @param int $skip Limitstart.
|
||||
* @param int $limit Number of rows to return.
|
||||
*
|
||||
* @return \core_competency\persistent[]
|
||||
*/
|
||||
public static function get_records_for_usercompetency($usercompetencyid,
|
||||
\context $context,
|
||||
$sort = '',
|
||||
$order = 'ASC',
|
||||
$skip = 0,
|
||||
$limit = 0) {
|
||||
global $DB;
|
||||
|
||||
$params = array(
|
||||
'usercompid' => $usercompetencyid,
|
||||
'path' => $context->path . '/%',
|
||||
'contextid' => $context->id
|
||||
);
|
||||
|
||||
if (!empty($sort)) {
|
||||
$sortcolumns = explode(',', $sort);
|
||||
$sortcolumns = array_map('trim', $sortcolumns);
|
||||
$sort = ' ORDER BY e.' . implode(', e.', $sortcolumns) . ' ' . $order;
|
||||
}
|
||||
|
||||
$sql = 'SELECT e.*
|
||||
FROM {' . static::TABLE . '} e
|
||||
JOIN {context} c ON c.id = e.contextid
|
||||
WHERE (c.path LIKE :path OR c.id = :contextid)
|
||||
AND e.usercompetencyid = :usercompid
|
||||
' . $sort;
|
||||
$records = $DB->get_records_sql($sql, $params, $skip, $limit);
|
||||
$instances = array();
|
||||
|
||||
foreach ($records as $record) {
|
||||
$newrecord = new static(0, $record);
|
||||
array_push($instances, $newrecord);
|
||||
}
|
||||
return $instances;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2579,6 +2579,47 @@ class core_competency_api_testcase extends advanced_testcase {
|
|||
$this->assertEquals(null, $ev4->get_actionuserid());
|
||||
}
|
||||
|
||||
public function test_list_evidence_in_course() {
|
||||
global $SITE;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
$dg = $this->getDataGenerator();
|
||||
$lpg = $dg->get_plugin_generator('core_competency');
|
||||
$u1 = $dg->create_user();
|
||||
$course = $dg->create_course();
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
$this->setAdminUser();
|
||||
$f = $lpg->create_framework();
|
||||
$c = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
|
||||
$c2 = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
|
||||
$cc = api::add_competency_to_course($course->id, $c->get_id());
|
||||
$cc2 = api::add_competency_to_course($course->id, $c2->get_id());
|
||||
|
||||
$pagegenerator = $this->getDataGenerator()->get_plugin_generator('mod_page');
|
||||
$page = $pagegenerator->create_instance(array('course' => $course->id));
|
||||
|
||||
$cm = get_coursemodule_from_instance('page', $page->id);
|
||||
$cmcontext = context_module::instance($cm->id);
|
||||
// Add the competency to the course module.
|
||||
$ccm = api::add_competency_to_course_module($cm, $c->get_id());
|
||||
|
||||
// Now add the evidence to the course.
|
||||
$evidence1 = api::add_evidence($u1->id, $c->get_id(), $coursecontext->id, \core_competency\evidence::ACTION_LOG,
|
||||
'invaliddata', 'error');
|
||||
|
||||
$result = api::list_evidence_in_course($u1->id, $course->id, $c->get_id());
|
||||
$this->assertEquals($result[0]->get_id(), $evidence1->get_id());
|
||||
|
||||
// Now add the evidence to the course module.
|
||||
$evidence2 = api::add_evidence($u1->id, $c->get_id(), $cmcontext->id, \core_competency\evidence::ACTION_LOG,
|
||||
'invaliddata', 'error');
|
||||
|
||||
$result = api::list_evidence_in_course($u1->id, $course->id, $c->get_id());
|
||||
$this->assertEquals($result[0]->get_id(), $evidence2->get_id());
|
||||
$this->assertEquals($result[1]->get_id(), $evidence1->get_id());
|
||||
}
|
||||
|
||||
public function test_list_course_modules_using_competency() {
|
||||
global $SITE;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue