本文整理汇总了PHP中core_competency\api::duplicate_framework方法的典型用法代码示例。如果您正苦于以下问题:PHP api::duplicate_framework方法的具体用法?PHP api::duplicate_framework怎么用?PHP api::duplicate_framework使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::duplicate_framework方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: duplicate_competency_framework
/**
* Duplicate a competency framework
*
* @param int $id The competency framework id
* @return boolean
*/
public static function duplicate_competency_framework($id)
{
global $PAGE;
$params = self::validate_parameters(self::duplicate_competency_framework_parameters(), array('id' => $id));
$framework = api::read_framework($params['id']);
self::validate_context($framework->get_context());
$output = $PAGE->get_renderer('core');
$framework = api::duplicate_framework($params['id']);
$exporter = new competency_framework_exporter($framework);
$record = $exporter->export($output);
return $record;
}
示例2: test_duplicate_framework
/**
* Test duplicate a framework.
*/
public function test_duplicate_framework()
{
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$this->resetAfterTest(true);
$this->setAdminUser();
$syscontext = context_system::instance();
$params = array('shortname' => 'shortname_a', 'idnumber' => 'idnumber_c', 'description' => 'description', 'descriptionformat' => FORMAT_HTML, 'visible' => true, 'contextid' => $syscontext->id);
$framework = $lpg->create_framework($params);
$competency1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$competency2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$competency3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$competency4 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$competency41 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $competency4->get_id()));
$competency42 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id(), 'parentid' => $competency4->get_id()));
$competencyidnumbers = array($competency1->get_idnumber(), $competency2->get_idnumber(), $competency3->get_idnumber(), $competency4->get_idnumber(), $competency41->get_idnumber(), $competency42->get_idnumber());
$config = json_encode(array('base' => array('points' => 4), 'competencies' => array(array('id' => $competency41->get_id(), 'points' => 3, 'required' => 0), array('id' => $competency42->get_id(), 'points' => 2, 'required' => 1))));
$competency4->set_ruletype('core_competency\\competency_rule_points');
$competency4->set_ruleoutcome(\core_competency\competency::OUTCOME_EVIDENCE);
$competency4->set_ruleconfig($config);
$competency4->update();
api::add_related_competency($competency1->get_id(), $competency2->get_id());
api::add_related_competency($competency3->get_id(), $competency4->get_id());
$frameworkduplicated1 = api::duplicate_framework($framework->get_id());
$frameworkduplicated2 = api::duplicate_framework($framework->get_id());
$this->assertEquals($framework->get_idnumber() . '_1', $frameworkduplicated1->get_idnumber());
$this->assertEquals($framework->get_idnumber() . '_2', $frameworkduplicated2->get_idnumber());
$competenciesfr1 = api::list_competencies(array('competencyframeworkid' => $frameworkduplicated1->get_id()));
$competenciesfr2 = api::list_competencies(array('competencyframeworkid' => $frameworkduplicated2->get_id()));
$competencyidsfr1 = array();
$competencyidsfr2 = array();
foreach ($competenciesfr1 as $cmp) {
$competencyidsfr1[] = $cmp->get_idnumber();
}
foreach ($competenciesfr2 as $cmp) {
$competencyidsfr2[] = $cmp->get_idnumber();
}
$this->assertEmpty(array_diff($competencyidsfr1, $competencyidnumbers));
$this->assertEmpty(array_diff($competencyidsfr2, $competencyidnumbers));
$this->assertCount(6, $competenciesfr1);
$this->assertCount(6, $competenciesfr2);
// Test the related competencies.
reset($competenciesfr1);
$compduplicated1 = current($competenciesfr1);
$relatedcompetencies = $compduplicated1->get_related_competencies();
$comprelated = current($relatedcompetencies);
$this->assertEquals($comprelated->get_idnumber(), $competency2->get_idnumber());
// Check if config rule have been ported correctly.
$competency4duplicated = competency::get_record(array('idnumber' => $competency4->get_idnumber(), 'competencyframeworkid' => $frameworkduplicated2->get_id()));
$configduplicated = json_decode($competency4duplicated->get_ruleconfig(), true);
$configorigin = json_decode($config, true);
// Check that the 2 config have the same base.
$this->assertEquals($configorigin['base'], $configduplicated['base']);
$this->assertEquals(count($configorigin['competencies']), count($configduplicated['competencies']));
$competencyidsrules = array();
foreach ($configduplicated['competencies'] as $key => $value) {
// Check that the only difference between the 2 config is id competency.
$this->assertEquals(1, count(array_diff($value, $configorigin['competencies'][$key])));
$competencyidsrules[] = $value['id'];
}
$this->assertTrue($competency4duplicated->is_parent_of($competencyidsrules));
// Test duplicate an empty framework.
$emptyfrm = $lpg->create_framework();
$emptyfrmduplicated = api::duplicate_framework($emptyfrm->get_id());
$this->assertEquals($emptyfrm->get_idnumber() . '_1', $emptyfrmduplicated->get_idnumber());
$nbcomp = api::count_competencies(array('competencyframeworkid' => $emptyfrmduplicated->get_id()));
$this->assertEquals(0, $nbcomp);
}
示例3: test_competency_created_by_duplicateframework
/**
* Test the competency created event by duplicate framework.
*
*/
public function test_competency_created_by_duplicateframework()
{
$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();
// Create framework should trigger a created event for competencies.
api::duplicate_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_created', $event);
$event = array_shift($events);
$this->assertInstanceOf('\\core\\event\\competency_created', $event);
$event = array_shift($events);
$this->assertInstanceOf('\\core\\event\\competency_created', $event);
$event = array_shift($events);
$this->assertInstanceOf('\\core\\event\\competency_framework_created', $event);
}