本文整理汇总了PHP中core_competency\api::create_plan方法的典型用法代码示例。如果您正苦于以下问题:PHP api::create_plan方法的具体用法?PHP api::create_plan怎么用?PHP api::create_plan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::create_plan方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_create_plan_from_template
/**
* @expectedException coding_exception
*/
public function test_create_plan_from_template()
{
$this->resetAfterTest(true);
$this->setAdminUser();
$u1 = $this->getDataGenerator()->create_user();
$tpl = $this->getDataGenerator()->get_plugin_generator('core_competency')->create_template();
// Creating a new plan.
$plan = api::create_plan_from_template($tpl, $u1->id);
$record = $plan->to_record();
$this->assertInstanceOf('\\core_competency\\plan', $plan);
$this->assertTrue(\core_competency\plan::record_exists($plan->get_id()));
$this->assertEquals($tpl->get_id(), $plan->get_templateid());
$this->assertEquals($u1->id, $plan->get_userid());
$this->assertTrue($plan->is_based_on_template());
// Creating a plan that already exists.
$plan = api::create_plan_from_template($tpl, $u1->id);
$this->assertFalse($plan);
// Check that api::create_plan cannot be used.
unset($record->id);
$plan = api::create_plan($record);
}
示例2: create_plan
/**
* Create a new learning plan.
*
* @param array $plan List of fields for the plan.
* @return array New plan record.
*/
public static function create_plan($plan)
{
global $PAGE;
$params = self::validate_parameters(self::create_plan_parameters(), array('plan' => $plan));
$params = $params['plan'];
$context = context_user::instance($params['userid']);
self::validate_context($context);
$output = $PAGE->get_renderer('core');
$params = (object) $params;
$result = api::create_plan($params);
$exporter = new plan_exporter($result, array('template' => null));
return $exporter->export($output);
}
示例3: coding_exception
if (!$plan->can_be_edited()) {
throw new coding_exception('Completed plan can not be edited');
}
} else {
if (!$cancreate) {
throw new required_capability_exception($PAGE->context, 'moodle/competency:planmanage', 'nopermissions', '');
}
}
$form = new \tool_lp\form\plan($url->out(false), $customdata);
if ($form->is_cancelled()) {
redirect($returnurl);
}
$data = $form->get_data();
if ($data) {
if (empty($data->id)) {
$plan = \core_competency\api::create_plan($data);
$returnurl = new moodle_url('/admin/tool/lp/plan.php', ['id' => $plan->get_id()]);
$returnmsg = get_string('plancreated', 'tool_lp');
} else {
\core_competency\api::update_plan($data);
$returnmsg = get_string('planupdated', 'tool_lp');
}
redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
}
echo $output->header();
echo $output->heading($title);
if (!empty($subtitle)) {
echo $output->heading($subtitle, 3);
}
$form->display();
echo $output->footer();
示例4: test_plan_created
/**
* Test the plan created event.
*
*/
public function test_plan_created()
{
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$user = $dg->create_user();
$plan = array('name' => 'plan', 'userid' => $user->id);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$plan = api::create_plan((object) $plan);
// Get our event event.
$events = $sink->get_events();
$event = reset($events);
// Check that the event data is valid.
$this->assertInstanceOf('\\core\\event\\competency_plan_created', $event);
$this->assertEquals($plan->get_id(), $event->objectid);
$this->assertEquals($plan->get_context()->id, $event->contextid);
$this->assertEventContextNotUsed($event);
$this->assertDebuggingNotCalled();
}