Exemplo n.º 1
0
 /**
  * Validate the template ID.
  *
  * @param  int $value The template ID.
  * @return true|lang_string
  */
 protected function validate_templateid($value)
 {
     if (!template::record_exists($value)) {
         return new lang_string('invaliddata', 'error');
     }
     return true;
 }
Exemplo n.º 2
0
 public function test_delete_template_unlink_plans()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $u1 = $dg->create_user();
     $f = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
     $tpl = $lpg->create_template();
     $tplc1 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $c1->get_id(), 'sortorder' => 1));
     $tplc2 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $c2->get_id(), 'sortorder' => 2));
     $p1 = $lpg->create_plan(array('templateid' => $tpl->get_id(), 'userid' => $u1->id));
     // Check pre-test.
     $this->assertTrue(\core_competency\template::record_exists($tpl->get_id()));
     $this->assertEquals(2, \core_competency\template_competency::count_competencies($tpl->get_id()));
     $this->assertEquals(1, count(\core_competency\plan::get_records(array('templateid' => $tpl->get_id()))));
     $result = api::delete_template($tpl->get_id(), false);
     $this->assertTrue($result);
     // Check that the template does not exist anymore.
     $this->assertFalse(\core_competency\template::record_exists($tpl->get_id()));
     // Check that associated competencies are also deleted.
     $this->assertEquals(0, \core_competency\template_competency::count_competencies($tpl->get_id()));
     // Check that associated plan still exist but unlink from template.
     $plans = \core_competency\plan::get_records(array('id' => $p1->get_id()));
     $this->assertEquals(1, count($plans));
     $this->assertEquals($plans[0]->get_origtemplateid(), $tpl->get_id());
     $this->assertNull($plans[0]->get_templateid());
 }
Exemplo n.º 3
0
 /**
  * Validate the template ID.
  *
  * @param mixed $value The value.
  * @return true|lang_string
  */
 protected function validate_templateid($value)
 {
     // Checks that the template exists.
     if (!empty($value) && !template::record_exists($value)) {
         return new lang_string('invaliddata', 'error');
     }
     return true;
 }