本文整理汇总了PHP中core_competency\api::list_competencies方法的典型用法代码示例。如果您正苦于以下问题:PHP api::list_competencies方法的具体用法?PHP api::list_competencies怎么用?PHP api::list_competencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::list_competencies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
/**
* Export all the competencies from this framework to a csv file.
*/
public function export()
{
global $CFG;
require_once $CFG->libdir . '/csvlib.class.php';
$writer = new csv_export_writer();
$filename = clean_param($this->framework->get_shortname() . '-' . $this->framework->get_idnumber(), PARAM_FILE);
$writer->set_filename($filename);
$headers = framework_importer::list_required_headers();
$writer->add_data($headers);
// Order and number of columns must match framework_importer::list_required_headers().
$row = array('', $this->framework->get_idnumber(), $this->framework->get_shortname(), $this->framework->get_description(), $this->framework->get_descriptionformat(), $this->framework->get_scale()->compact_items(), $this->framework->get_scaleconfiguration(), '', '', '', '', '', true, implode(',', $this->framework->get_taxonomies()));
$writer->add_data($row);
$filters = array('competencyframeworkid' => $this->framework->get_id());
$competencies = api::list_competencies($filters);
// Index by id so we can lookup parents.
$indexed = array();
foreach ($competencies as $competency) {
$indexed[$competency->get_id()] = $competency;
}
foreach ($competencies as $competency) {
$parentidnumber = '';
if ($competency->get_parentid() > 0) {
$parent = $indexed[$competency->get_parentid()];
$parentidnumber = $parent->get_idnumber();
}
$scalevalues = '';
$scaleconfig = '';
if ($competency->get_scaleid() !== null) {
$scalevalues = $competency->get_scale()->compact_items();
$scaleconfig = $competency->get_scaleconfiguration();
}
$ruleconfig = $competency->get_ruleconfig();
if ($ruleconfig === null) {
$ruleconfig = "null";
}
$allrelated = $competency->get_related_competencies();
$relatedidnumbers = array();
foreach ($allrelated as $onerelated) {
$relatedidnumbers[] = str_replace(',', '%2C', $onerelated->get_idnumber());
}
$relatedidnumbers = implode(',', $relatedidnumbers);
// Order and number of columns must match framework_importer::list_required_headers().
$row = array($parentidnumber, $competency->get_idnumber(), $competency->get_shortname(), $competency->get_description(), $competency->get_descriptionformat(), $scalevalues, $scaleconfig, $competency->get_ruletype(), $competency->get_ruleoutcome(), $ruleconfig, $relatedidnumbers, $competency->get_id(), false, '');
$writer->add_data($row);
}
$writer->download_file();
}
示例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: list_competencies
/**
* List the existing competency.
*
* @param string $filters
* @param int $sort
* @param string $order
* @param string $skip
* @param int $limit
*
* @return array
* @throws \required_capability_exception
* @throws invalid_parameter_exception
*/
public static function list_competencies($filters, $sort, $order, $skip, $limit)
{
global $PAGE;
$params = self::validate_parameters(self::list_competencies_parameters(), array('filters' => $filters, 'sort' => $sort, 'order' => $order, 'skip' => $skip, 'limit' => $limit));
if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
}
$safefilters = array();
$validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'parentid', 'competencyframeworkid');
foreach ($params['filters'] as $filter) {
if (!in_array($filter->column, $validcolumns)) {
throw new invalid_parameter_exception('Filter column was invalid');
}
$safefilters[$filter->column] = $filter->value;
}
$context = null;
if (isset($safefilters['competencyframeworkid'])) {
$framework = api::read_framework($safefilters['competencyframeworkid']);
$context = $framework->get_context();
} else {
$context = context_system::instance();
}
self::validate_context($context);
$output = $PAGE->get_renderer('core');
$results = api::list_competencies($safefilters, $params['sort'], $params['order'], $params['skip'], $params['limit']);
$records = array();
foreach ($results as $result) {
$exporter = new competency_exporter($result, array('context' => $context));
$record = $exporter->export($output);
array_push($records, $record);
}
return $records;
}