本文整理汇总了PHP中core_competency\api::create_plan_from_template方法的典型用法代码示例。如果您正苦于以下问题:PHP api::create_plan_from_template方法的具体用法?PHP api::create_plan_from_template怎么用?PHP api::create_plan_from_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::create_plan_from_template方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Do the job.
*/
public function execute()
{
if (!api::is_enabled()) {
return;
}
$missingplans = template_cohort::get_all_missing_plans(self::get_last_run_time());
foreach ($missingplans as $missingplan) {
foreach ($missingplan['userids'] as $userid) {
try {
api::create_plan_from_template($missingplan['template'], $userid);
} catch (\Exception $e) {
debugging(sprintf('Exception caught while creating plan for user %d from template %d. Message: %s', $userid, $missingplan['template']->get_id(), $e->getMessage()), DEBUG_DEVELOPER);
}
}
}
}
示例2: test_hidden_template
/**
* Test when using hidden template in plan/cohort.
*/
public function test_hidden_template()
{
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$user = $dg->create_user();
// Create a cohort.
$cohort = $dg->create_cohort();
// Create a hidden template.
$template = $lpg->create_template(array('visible' => false));
// Can not link hidden template to plan.
try {
api::create_plan_from_template($template->get_id(), $user->id);
$this->fail('Can not link a hidden template to plan');
} catch (coding_exception $e) {
$this->assertTrue(true);
}
// Can associate hidden template to cohort.
$templatecohort = api::create_template_cohort($template->get_id(), $cohort->id);
$this->assertInstanceOf('\\core_competency\\template_cohort', $templatecohort);
}
示例3: required_capability_exception
$template = \core_competency\api::read_template($id);
$context = $template->get_context();
$canreadtemplate = $template->can_read();
$canmanagetemplate = $template->can_manage();
if (!$canreadtemplate) {
throw new required_capability_exception($context, 'moodle/competency:templateview', 'nopermissions', '');
}
// Set up the page.
$url = new moodle_url('/admin/tool/lp/template_plans.php', array('id' => $id, 'pagecontextid' => $pagecontextid));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, get_string('userplans', 'core_competency'));
// Capture the form submission.
$form = new \tool_lp\form\template_plans($url->out(false));
if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->users)) {
$i = 0;
foreach ($data->users as $userid) {
$result = \core_competency\api::create_plan_from_template($template->get_id(), $userid);
if ($result) {
$i++;
}
}
if ($i == 0) {
$notification = get_string('noplanswerecreated', 'tool_lp');
} else {
if ($i == 1) {
$notification = get_string('oneplanwascreated', 'tool_lp');
} else {
$notification = get_string('aplanswerecreated', 'tool_lp', $i);
}
}
redirect($url, $notification);
}