public function test_get_user_competencies_by_userevidenceid()
 {
     global $CFG, $DB;
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $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());
 }
Exemplo n.º 2
0
 public function test_delete_framework_competency_used_in_course()
 {
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $this->setAdminUser();
     $cat1 = $dg->create_category();
     $u1 = $dg->create_user();
     $course = $dg->create_course(array('category' => $cat1->id));
     $f1 = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2id = $c2->get_id();
     $c1a = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1->get_id()));
     $c1b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1a->get_id()));
     $c11b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1b->get_id()));
     $c12b = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1b->get_id()));
     // Create related competencies.
     $rc = $lpg->create_related_competency(array('competencyid' => $c2->get_id(), 'relatedcompetencyid' => $c11b->get_id()));
     $this->assertEquals($c11b->get_id(), $rc->get_relatedcompetencyid());
     // Creating a standard evidence with minimal information.
     $uc1 = $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $c11b->get_id()));
     $usercompetencyid = $uc1->get_id();
     $evidence = $lpg->create_evidence(array('usercompetencyid' => $usercompetencyid));
     $this->assertEquals($uc1->get_id(), $evidence->get_usercompetencyid());
     $uc1->delete();
     // Add competency to course.
     $cc = $lpg->create_course_competency(array('courseid' => $course->id, 'competencyid' => $c11b->get_id()));
     // We can not delete a framework if the competency or competencies children is linked to a course.
     $this->assertFalse(api::delete_framework($f1->get_id()));
     // Check that none of associated data are deleted.
     $this->assertEquals($usercompetencyid, $evidence->read()->get_usercompetencyid());
     $this->assertEquals($c2->get_id(), $rc->read()->get_competencyid());
     // We can delete the framework if we remove the competency from course.
     $cc->delete();
     $this->assertTrue(api::delete_framework($f1->get_id()));
     $this->assertFalse(competency::record_exists($c1->get_id()));
     $this->assertFalse(competency::record_exists($c2->get_id()));
     $this->assertFalse(competency::record_exists($c1a->get_id()));
     $this->assertFalse(competency::record_exists($c1b->get_id()));
     $this->assertFalse(competency::record_exists($c11b->get_id()));
     $this->assertFalse(competency::record_exists($c12b->get_id()));
     // Check if evidence are also deleted.
     $this->assertEquals(0, \core_competency\user_evidence_competency::count_records(array('competencyid' => $c11b->get_id())));
     // Check if related conpetency relation is deleted.
     $this->assertEquals(0, count(\core_competency\related_competency::get_multiple_relations(array($c2id))));
 }
Exemplo n.º 3
0
 /**
  * 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)
 {
     $userevidence = new user_evidence($id);
     $context = $userevidence->get_context();
     $userid = $userevidence->get_userid();
     if (!$userevidence->can_manage()) {
         throw new required_capability_exception($context, 'moodle/competency: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;
 }
Exemplo n.º 4
0
 /**
  * Create a new user_evidence_comp.
  *
  * @param array|stdClass $record
  * @return evidence
  */
 public function create_user_evidence_competency($record = null)
 {
     $record = (object) $record;
     if (!isset($record->userevidenceid)) {
         throw new coding_exception('The userevidenceid value is required.');
     }
     if (!isset($record->competencyid)) {
         throw new coding_exception('The competencyid value is required.');
     }
     $uec = new user_evidence_competency(0, $record);
     $uec->create();
     return $uec;
 }
Exemplo n.º 5
0
 /**
  * Get link user competencies.
  */
 public function get_user_competencies()
 {
     return user_evidence_competency::get_user_competencies_by_userevidenceid($this->get_id());
 }