本文整理汇总了PHP中core_competency\api::list_plan_competencies方法的典型用法代码示例。如果您正苦于以下问题:PHP api::list_plan_competencies方法的具体用法?PHP api::list_plan_competencies怎么用?PHP api::list_plan_competencies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::list_plan_competencies方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export_for_template
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output)
{
$data = new stdClass();
$data->userid = $this->userid;
$data->competencyid = $this->competencyid;
$data->planid = $this->planid;
$data->baseurl = $this->baseurl;
$plancompetencies = \core_competency\api::list_plan_competencies($data->planid);
$data->competencies = array();
$contextcache = array();
foreach ($plancompetencies as $plancompetency) {
$frameworkid = $plancompetency->competency->get_competencyframeworkid();
if (!isset($contextcache[$frameworkid])) {
$contextcache[$frameworkid] = $plancompetency->competency->get_context();
}
$context = $contextcache[$frameworkid];
$exporter = new competency_exporter($plancompetency->competency, array('context' => $context));
$competency = $exporter->export($output);
if ($competency->id == $this->competencyid) {
$competency->selected = true;
}
$data->competencies[] = $competency;
}
$data->hascompetencies = count($data->competencies);
return $data;
}
示例2: export_for_template
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(\renderer_base $output)
{
$frameworks = array();
$scales = array();
$planexporter = new plan_exporter($this->plan, array('template' => $this->plan->get_template()));
$data = new stdClass();
$data->plan = $planexporter->export($output);
$data->competencies = array();
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(false);
$data->contextid = $this->plan->get_context()->id;
if ($data->plan->iscompleted) {
$ucproperty = 'usercompetencyplan';
$ucexporter = 'core_competency\\external\\user_competency_plan_exporter';
} else {
$ucproperty = 'usercompetency';
$ucexporter = 'core_competency\\external\\user_competency_exporter';
}
$pclist = api::list_plan_competencies($this->plan);
$proficientcount = 0;
foreach ($pclist as $pc) {
$comp = $pc->competency;
$usercomp = $pc->{$ucproperty};
// Get the framework.
if (!isset($frameworks[$comp->get_competencyframeworkid()])) {
$frameworks[$comp->get_competencyframeworkid()] = $comp->get_framework();
}
$framework = $frameworks[$comp->get_competencyframeworkid()];
// Get the scale.
$scaleid = $comp->get_scaleid();
if ($scaleid === null) {
$scaleid = $framework->get_scaleid();
}
if (!isset($scales[$framework->get_scaleid()])) {
$scales[$framework->get_scaleid()] = $framework->get_scale();
}
$scale = $scales[$framework->get_scaleid()];
// Prepare the data.
$record = new stdClass();
$exporter = new competency_exporter($comp, array('context' => $framework->get_context()));
$record->competency = $exporter->export($output);
// Competency path.
$exporter = new competency_path_exporter(['ancestors' => $comp->get_ancestors(), 'framework' => $framework, 'context' => $framework->get_context()]);
$record->comppath = $exporter->export($output);
$exporter = new $ucexporter($usercomp, array('scale' => $scale));
$record->{$ucproperty} = $exporter->export($output);
$data->competencies[] = $record;
if ($usercomp->get_proficiency()) {
$proficientcount++;
}
}
$data->competencycount = count($data->competencies);
$data->proficientcompetencycount = $proficientcount;
if ($data->competencycount) {
$data->proficientcompetencypercentage = (double) $proficientcount / (double) $data->competencycount * 100.0;
} else {
$data->proficientcompetencypercentage = 0.0;
}
$data->proficientcompetencypercentageformatted = format_float($data->proficientcompetencypercentage);
return $data;
}
示例3: test_list_plan_competencies_manage_archived_competencies
/**
* Test listing of plan competencies.
*/
public function test_list_plan_competencies_manage_archived_competencies()
{
$this->resetAfterTest(true);
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
// Create user and role for the test.
$user = $dg->create_user();
$viewrole = $dg->create_role(array('name' => 'User view', 'shortname' => 'view'));
assign_capability('moodle/competency:planviewdraft', CAP_ALLOW, $viewrole, $syscontext->id);
assign_capability('moodle/competency:planview', CAP_ALLOW, $viewrole, $syscontext->id);
$dg->role_assign($viewrole, $user->id, $syscontext->id);
$this->setUser($user);
// Create a framework and assign competencies.
$framework = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
// Create draft plan with records in user_competency.
$draftplan = $lpg->create_plan(array('userid' => $user->id));
$lpg->create_plan_competency(array('planid' => $draftplan->get_id(), 'competencyid' => $c1->get_id()));
$lpg->create_plan_competency(array('planid' => $draftplan->get_id(), 'competencyid' => $c2->get_id()));
$lpg->create_plan_competency(array('planid' => $draftplan->get_id(), 'competencyid' => $c3->get_id()));
$uc1 = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c1->get_id()));
$uc2 = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c2->get_id()));
// Check that user_competency objects are returned when plan status is not complete.
$plancompetencies = api::list_plan_competencies($draftplan);
$this->assertCount(3, $plancompetencies);
$this->assertInstanceOf('\\core_competency\\user_competency', $plancompetencies[0]->usercompetency);
$this->assertEquals($uc1->get_id(), $plancompetencies[0]->usercompetency->get_id());
$this->assertNull($plancompetencies[0]->usercompetencyplan);
$this->assertInstanceOf('\\core_competency\\user_competency', $plancompetencies[1]->usercompetency);
$this->assertEquals($uc2->get_id(), $plancompetencies[1]->usercompetency->get_id());
$this->assertNull($plancompetencies[1]->usercompetencyplan);
$this->assertInstanceOf('\\core_competency\\user_competency', $plancompetencies[2]->usercompetency);
$this->assertEquals(0, $plancompetencies[2]->usercompetency->get_id());
$this->assertNull($plancompetencies[2]->usercompetencyplan);
// Create completed plan with records in user_competency_plan.
$completedplan = $lpg->create_plan(array('userid' => $user->id, 'status' => \core_competency\plan::STATUS_COMPLETE));
$pc1 = $lpg->create_plan_competency(array('planid' => $completedplan->get_id(), 'competencyid' => $c1->get_id()));
$pc2 = $lpg->create_plan_competency(array('planid' => $completedplan->get_id(), 'competencyid' => $c2->get_id()));
$pc3 = $lpg->create_plan_competency(array('planid' => $completedplan->get_id(), 'competencyid' => $c3->get_id()));
$ucp1 = $lpg->create_user_competency_plan(array('userid' => $user->id, 'competencyid' => $c1->get_id(), 'planid' => $completedplan->get_id()));
$ucp2 = $lpg->create_user_competency_plan(array('userid' => $user->id, 'competencyid' => $c2->get_id(), 'planid' => $completedplan->get_id()));
$ucp3 = $lpg->create_user_competency_plan(array('userid' => $user->id, 'competencyid' => $c3->get_id(), 'planid' => $completedplan->get_id()));
// Check that user_competency_plan objects are returned when plan status is complete.
$plancompetencies = api::list_plan_competencies($completedplan);
$this->assertCount(3, $plancompetencies);
$this->assertInstanceOf('\\core_competency\\user_competency_plan', $plancompetencies[0]->usercompetencyplan);
$this->assertEquals($ucp1->get_id(), $plancompetencies[0]->usercompetencyplan->get_id());
$this->assertNull($plancompetencies[0]->usercompetency);
$this->assertInstanceOf('\\core_competency\\user_competency_plan', $plancompetencies[1]->usercompetencyplan);
$this->assertEquals($ucp2->get_id(), $plancompetencies[1]->usercompetencyplan->get_id());
$this->assertNull($plancompetencies[1]->usercompetency);
$this->assertInstanceOf('\\core_competency\\user_competency_plan', $plancompetencies[2]->usercompetencyplan);
$this->assertEquals($ucp3->get_id(), $plancompetencies[2]->usercompetencyplan->get_id());
$this->assertNull($plancompetencies[2]->usercompetency);
}
示例4: list_plan_competencies
/**
* List plan competencies.
* @param int $id The plan ID.
* @return array
*/
public static function list_plan_competencies($id)
{
global $PAGE;
$params = self::validate_parameters(self::list_plan_competencies_parameters(), array('id' => $id));
$id = $params['id'];
$plan = api::read_plan($id);
$usercontext = $plan->get_context();
self::validate_context($usercontext);
$output = $PAGE->get_renderer('core');
$result = api::list_plan_competencies($plan);
if ($plan->get_status() == plan::STATUS_COMPLETE) {
$ucproperty = 'usercompetencyplan';
} else {
$ucproperty = 'usercompetency';
}
$contextcache = array();
$scalecache = array();
foreach ($result as $key => $r) {
if (!isset($scalecache[$r->competency->get_competencyframeworkid()])) {
$scalecache[$r->competency->get_competencyframeworkid()] = $r->competency->get_framework()->get_scale();
}
$scale = $scalecache[$r->competency->get_competencyframeworkid()];
if (!isset($contextcache[$r->competency->get_competencyframeworkid()])) {
$contextcache[$r->competency->get_competencyframeworkid()] = $r->competency->get_context();
}
$context = $contextcache[$r->competency->get_competencyframeworkid()];
$exporter = new competency_exporter($r->competency, array('context' => $context));
$r->competency = $exporter->export($output);
if ($r->usercompetency) {
$exporter = new user_competency_exporter($r->usercompetency, array('scale' => $scale));
$r->usercompetency = $exporter->export($output);
unset($r->usercompetencyplan);
} else {
$exporter = new user_competency_plan_exporter($r->usercompetencyplan, array('scale' => $scale));
$r->usercompetencyplan = $exporter->export($output);
unset($r->usercompetency);
}
}
return $result;
}