/** * Validate the plan ID. * * @param int $value The value. * @return true|lang_string */ protected function validate_planid($value) { if (!plan::record_exists($value)) { return new lang_string('invalidplan', 'core_competency'); } return true; }
/** * Validate planid. * * @param int $value ID. * @return true|lang_string */ protected function validate_planid($value) { if (!plan::record_exists($value)) { return new lang_string('invaliddata', 'error'); } return true; }
/** * @expectedException coding_exception */ public function test_create_plan_from_template() { $this->resetAfterTest(true); $this->setAdminUser(); $u1 = $this->getDataGenerator()->create_user(); $tpl = $this->getDataGenerator()->get_plugin_generator('core_competency')->create_template(); // Creating a new plan. $plan = api::create_plan_from_template($tpl, $u1->id); $record = $plan->to_record(); $this->assertInstanceOf('\\core_competency\\plan', $plan); $this->assertTrue(\core_competency\plan::record_exists($plan->get_id())); $this->assertEquals($tpl->get_id(), $plan->get_templateid()); $this->assertEquals($u1->id, $plan->get_userid()); $this->assertTrue($plan->is_based_on_template()); // Creating a plan that already exists. $plan = api::create_plan_from_template($tpl, $u1->id); $this->assertFalse($plan); // Check that api::create_plan cannot be used. unset($record->id); $plan = api::create_plan($record); }
/** * Validates comments. * * @param stdClass $params The parameters. * @return bool */ function core_competency_comment_validate($params) { if (!get_config('core_competency', 'enabled')) { return false; } if ($params->commentarea == 'user_competency') { if (!user_competency::record_exists($params->itemid)) { return false; } return true; } else { if ($params->commentarea == 'plan') { if (!plan::record_exists($params->itemid)) { return false; } return true; } } return false; }