本文整理汇总了PHP中core_competency\api::update_template方法的典型用法代码示例。如果您正苦于以下问题:PHP api::update_template方法的具体用法?PHP api::update_template怎么用?PHP api::update_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::update_template方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_update_template_updates_plans
public function test_update_template_updates_plans()
{
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$u1 = $dg->create_user();
$u2 = $dg->create_user();
$lpg = $dg->get_plugin_generator('core_competency');
$tpl1 = $lpg->create_template();
$tpl2 = $lpg->create_template();
// Create plans with data not matching templates.
$time = time();
$plan1 = $lpg->create_plan(array('templateid' => $tpl1->get_id(), 'userid' => $u1->id, 'name' => 'Not good name', 'duedate' => $time + 3600, 'description' => 'Ahah', 'descriptionformat' => FORMAT_MARKDOWN));
$plan2 = $lpg->create_plan(array('templateid' => $tpl1->get_id(), 'userid' => $u2->id, 'name' => 'Not right name', 'duedate' => $time + 3601, 'description' => 'Ahah', 'descriptionformat' => FORMAT_PLAIN));
$plan3 = $lpg->create_plan(array('templateid' => $tpl2->get_id(), 'userid' => $u1->id, 'name' => 'Not sweet name', 'duedate' => $time + 3602, 'description' => 'Ahah', 'descriptionformat' => FORMAT_PLAIN));
// Prepare our expectations.
$plan1->read();
$plan2->read();
$plan3->read();
$this->assertEquals($tpl1->get_id(), $plan1->get_templateid());
$this->assertEquals($tpl1->get_id(), $plan2->get_templateid());
$this->assertEquals($tpl2->get_id(), $plan3->get_templateid());
$this->assertNotEquals($tpl1->get_shortname(), $plan1->get_name());
$this->assertNotEquals($tpl1->get_shortname(), $plan2->get_name());
$this->assertNotEquals($tpl2->get_shortname(), $plan3->get_name());
$this->assertNotEquals($tpl1->get_description(), $plan1->get_description());
$this->assertNotEquals($tpl1->get_description(), $plan2->get_description());
$this->assertNotEquals($tpl2->get_description(), $plan3->get_description());
$this->assertNotEquals($tpl1->get_descriptionformat(), $plan1->get_descriptionformat());
$this->assertNotEquals($tpl1->get_descriptionformat(), $plan2->get_descriptionformat());
$this->assertNotEquals($tpl2->get_descriptionformat(), $plan3->get_descriptionformat());
$this->assertNotEquals($tpl1->get_duedate(), $plan1->get_duedate());
$this->assertNotEquals($tpl1->get_duedate(), $plan2->get_duedate());
$this->assertNotEquals($tpl2->get_duedate(), $plan3->get_duedate());
// Update the template without changing critical fields does not update the plans.
$data = $tpl1->to_record();
$data->visible = 0;
api::update_template($data);
$this->assertNotEquals($tpl1->get_shortname(), $plan1->get_name());
$this->assertNotEquals($tpl1->get_shortname(), $plan2->get_name());
$this->assertNotEquals($tpl2->get_shortname(), $plan3->get_name());
$this->assertNotEquals($tpl1->get_description(), $plan1->get_description());
$this->assertNotEquals($tpl1->get_description(), $plan2->get_description());
$this->assertNotEquals($tpl2->get_description(), $plan3->get_description());
$this->assertNotEquals($tpl1->get_descriptionformat(), $plan1->get_descriptionformat());
$this->assertNotEquals($tpl1->get_descriptionformat(), $plan2->get_descriptionformat());
$this->assertNotEquals($tpl2->get_descriptionformat(), $plan3->get_descriptionformat());
$this->assertNotEquals($tpl1->get_duedate(), $plan1->get_duedate());
$this->assertNotEquals($tpl1->get_duedate(), $plan2->get_duedate());
$this->assertNotEquals($tpl2->get_duedate(), $plan3->get_duedate());
// Now really update the template.
$data = $tpl1->to_record();
$data->shortname = 'Awesome!';
$data->description = 'This is too awesome!';
$data->descriptionformat = FORMAT_HTML;
$data->duedate = $time + 200;
api::update_template($data);
$tpl1->read();
// Now confirm that the right plans were updated.
$plan1->read();
$plan2->read();
$plan3->read();
$this->assertEquals($tpl1->get_id(), $plan1->get_templateid());
$this->assertEquals($tpl1->get_id(), $plan2->get_templateid());
$this->assertEquals($tpl2->get_id(), $plan3->get_templateid());
$this->assertEquals($tpl1->get_shortname(), $plan1->get_name());
$this->assertEquals($tpl1->get_shortname(), $plan2->get_name());
$this->assertNotEquals($tpl2->get_shortname(), $plan3->get_name());
$this->assertEquals($tpl1->get_description(), $plan1->get_description());
$this->assertEquals($tpl1->get_description(), $plan2->get_description());
$this->assertNotEquals($tpl2->get_description(), $plan3->get_description());
$this->assertEquals($tpl1->get_descriptionformat(), $plan1->get_descriptionformat());
$this->assertEquals($tpl1->get_descriptionformat(), $plan2->get_descriptionformat());
$this->assertNotEquals($tpl2->get_descriptionformat(), $plan3->get_descriptionformat());
$this->assertEquals($tpl1->get_duedate(), $plan1->get_duedate());
$this->assertEquals($tpl1->get_duedate(), $plan2->get_duedate());
$this->assertNotEquals($tpl2->get_duedate(), $plan3->get_duedate());
}
示例2: test_template_updated
/**
* Test the template updated event.
*
*/
public function test_template_updated()
{
$this->resetAfterTest(true);
$this->setAdminUser();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$template = $lpg->create_template();
// Trigger and capture the event.
$sink = $this->redirectEvents();
$template->set_shortname('Shortname modified');
api::update_template($template->to_record());
// Get our event event.
$events = $sink->get_events();
$event = reset($events);
// Check that the event data is valid.
$this->assertInstanceOf('\\core\\event\\competency_template_updated', $event);
$this->assertEquals($template->get_id(), $event->objectid);
$this->assertEquals($template->get_contextid(), $event->contextid);
$this->assertEventContextNotUsed($event);
$this->assertDebuggingNotCalled();
}
示例3: update_template
/**
* Update an existing learning plan template
*
* @param array $template The list of fields for the template.
* @return boolean
*/
public static function update_template($template)
{
$params = self::validate_parameters(self::update_template_parameters(), array('template' => $template));
$params = $params['template'];
$template = api::read_template($params['id']);
self::validate_context($template->get_context());
$params = (object) $params;
return api::update_template($params);
}
示例4: get_string
$pagetitle = get_string('addnewtemplate', 'tool_lp');
list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, null, $pagetitle, $returntype);
} else {
$template = \core_competency\api::read_template($id);
$pagetitle = get_string('edittemplate', 'tool_lp');
list($title, $subtitle, $returnurl) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle, $returntype);
}
$form = new \tool_lp\form\template($url->out(false), array('persistent' => $template, 'context' => $context));
if ($form->is_cancelled()) {
redirect($returnurl);
}
$data = $form->get_data();
if ($data) {
if (empty($data->id)) {
$template = \core_competency\api::create_template($data);
$returnurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', ['templateid' => $template->get_id(), 'pagecontextid' => $pagecontextid]);
$returnmsg = get_string('templatecreated', 'tool_lp');
} else {
\core_competency\api::update_template($data);
$returnmsg = get_string('templateupdated', 'tool_lp');
}
redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
}
$output = $PAGE->get_renderer('tool_lp');
echo $output->header();
echo $output->heading($title);
if (!empty($subtitle)) {
echo $output->heading($subtitle, 3);
}
$form->display();
echo $output->footer();