Ejemplo n.º 1
0
 /**
  * Delete a competency framework
  *
  * @param int $id The competency framework id
  * @return boolean
  */
 public static function delete_competency_framework($id)
 {
     $params = self::validate_parameters(self::delete_competency_framework_parameters(), array('id' => $id));
     $framework = api::read_framework($params['id']);
     self::validate_context($framework->get_context());
     return api::delete_framework($params['id']);
 }
Ejemplo 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))));
 }
Ejemplo n.º 3
0
 /**
  * Test the competency deleted event by delete framework.
  *
  */
 public function test_competency_deleted_by_deleteframework()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $f1 = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c12 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id(), 'parentid' => $c1->get_id()));
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     // Delete framework should trigger a deleted event for competencies.
     api::delete_framework($f1->get_id());
     // Get our event event.
     $events = $sink->get_events();
     $this->assertEquals(4, count($events));
     $event = array_shift($events);
     $this->assertInstanceOf('\\core\\event\\competency_framework_deleted', $event);
     $event = array_shift($events);
     $this->assertInstanceOf('\\core\\event\\competency_deleted', $event);
     $event = array_shift($events);
     $this->assertInstanceOf('\\core\\event\\competency_deleted', $event);
     $event = array_shift($events);
     $this->assertInstanceOf('\\core\\event\\competency_deleted', $event);
 }