public function test_create_competency_reset_rules() { $data = $this->setup_framework_for_reset_rules_tests(); $f1 = $data['f1']; $c1 = $data['c1']; $c1a = $data['c1a']; $c1a1 = $data['c1a1']; $c1a1a = $data['c1a1a']; $c1b = $data['c1b']; $c1b1 = $data['c1b1']; $c1b1a = $data['c1b1a']; $c2 = $data['c2']; $c2a = $data['c2a']; // Adding a new competency resets the rule of its parent. api::create_competency((object) array('shortname' => 'A', 'parentid' => $c1->get_id(), 'idnumber' => 'A', 'competencyframeworkid' => $f1->get_id())); $c1->read(); $c1a->read(); $c1a1->read(); $c1b->read(); $c2->read(); $this->assertEquals(competency::OUTCOME_NONE, $c1->get_ruleoutcome()); $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a->get_ruleoutcome()); $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1a1->get_ruleoutcome()); $this->assertEquals(competency::OUTCOME_EVIDENCE, $c1b->get_ruleoutcome()); $this->assertEquals(competency::OUTCOME_EVIDENCE, $c2->get_ruleoutcome()); }
// Get page URL. $urloptions = ['id' => $id, 'competencyframeworkid' => $competencyframework->get_id(), 'parentid' => $parentid, 'pagecontextid' => $pagecontextid]; $url = new moodle_url("/admin/tool/lp/editcompetency.php", $urloptions); // Set up the page. list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_competency($pagecontextid, $url, $competencyframework, $competency, $parent); // Set up the form. $formoptions = ['competencyframework' => $competencyframework, 'parent' => $parent, 'persistent' => $competency, 'pagecontextid' => $pagecontextid]; $form = new \tool_lp\form\competency($url->out(false), $formoptions); // Form cancelled. if ($form->is_cancelled()) { redirect($returnurl); } // Get form data. $data = $form->get_data(); if ($data) { if (empty($competency)) { \core_competency\api::create_competency($data); $returnmsg = get_string('competencycreated', 'tool_lp'); } else { \core_competency\api::update_competency($data); $returnmsg = get_string('competencyupdated', 'tool_lp'); } redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS); } // Render the page. $output = $PAGE->get_renderer('tool_lp'); echo $output->header(); echo $output->heading($title); echo $output->heading($subtitle, 3); $form->display(); echo $output->footer();
public function create_competency($parent, $record, $framework) { $competency = new stdClass(); $competency->competencyframeworkid = $framework->get_id(); $competency->shortname = trim(clean_param(shorten_text($record->shortname, 50), PARAM_TEXT)); if (!empty($record->description)) { $competency->description = trim(clean_param($record->description, PARAM_TEXT)); } if ($parent) { $competency->parentid = $parent->get_id(); if (empty($competency->shortname)) { if (!empty($competency->description)) { $competency->shortname = shorten_text($competency->description, 50); } else { $competency->shortname = $parent->get_shortname(); } } } else { $competency->parentid = 0; if (empty($competency->shortname)) { if (!empty($competency->description)) { $competency->shortname = shorten_text($competency->description, 50); } else { $competency->shortname = $framework->get_shortname(); } } } if (!empty($record->code)) { $competency->idnumber = trim(clean_param($record->code, PARAM_TEXT)); } else { $competency->idnumber = trim(clean_param($record->idnumber, PARAM_TEXT)); } if (!empty($competency->idnumber) && !empty($competency->shortname)) { $parent = api::create_competency($competency); $record->id = $parent->get_id(); foreach ($record->children as $child) { $this->create_competency($parent, $child, $framework); } if (!empty($record->iscompetency) && !empty($record->children)) { $parent->set_ruletype('core_competency\\competency_rule_all'); $parent->set_ruleoutcome(\core_competency\competency::OUTCOME_EVIDENCE); $parent->update(); } } }
/** * Create a new competency * * @param array $competency All the fields for a competency record (including id) * @return array the competency */ public static function create_competency($competency) { global $PAGE; $params = self::validate_parameters(self::create_competency_parameters(), array('competency' => $competency)); $params = $params['competency']; $framework = api::read_framework($params['competencyframeworkid']); $context = $framework->get_context(); self::validate_context($context); $output = $PAGE->get_renderer('core'); $params = (object) $params; $result = api::create_competency($params); $exporter = new competency_exporter($result, array('context' => $context)); $record = $exporter->export($output); return $record; }
/** * Test the competency created event. * */ public function test_competency_created() { $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())); $record = $c1->to_record(); $record->id = 0; $record->idnumber = 'comp idnumber'; // Trigger and capture the event. $sink = $this->redirectEvents(); // Create competency should trigger a created event. $competency = api::create_competency($record); // Get our event event. $events = $sink->get_events(); $event = reset($events); $this->assertInstanceOf('\\core\\event\\competency_created', $event); $this->assertEquals($competency->get_id(), $event->objectid); $this->assertEquals($competency->get_context()->id, $event->contextid); $this->assertEventContextNotUsed($event); $this->assertDebuggingNotCalled(); }
/** * Recursive function to add a competency with all it's children. */ public function create_competency($record, $parent, $framework) { $competency = new stdClass(); $competency->competencyframeworkid = $framework->get_id(); $competency->shortname = $record->shortname; if (!empty($record->description)) { $competency->description = $record->description; $competency->descriptionformat = $record->descriptionformat; } if ($record->scalevalues) { $competency->scaleid = $this->get_scale_id($record->scalevalues, $competency->shortname); $competency->scaleconfiguration = $this->get_scale_configuration($competency->scaleid, $record->scaleconfiguration); } if ($parent) { $competency->parentid = $parent->get_id(); } else { $competency->parentid = 0; } $competency->idnumber = $record->idnumber; if (!empty($competency->idnumber) && !empty($competency->shortname)) { $comp = api::create_competency($competency); if ($record->exportid) { $this->mappings[$record->exportid] = $comp; } $record->createdcomp = $comp; foreach ($record->children as $child) { $this->create_competency($child, $comp, $framework); } return $comp; } return false; }