本文整理匯總了PHP中core_competency\api::create_template_cohort方法的典型用法代碼示例。如果您正苦於以下問題:PHP api::create_template_cohort方法的具體用法?PHP api::create_template_cohort怎麽用?PHP api::create_template_cohort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core_competency\api
的用法示例。
在下文中一共展示了api::create_template_cohort方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test_sync_plans_from_cohorts_with_passed_duedate
public function test_sync_plans_from_cohorts_with_passed_duedate()
{
global $DB;
$this->resetAfterTest(true);
$this->setAdminUser();
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('core_competency');
$user1 = $dg->create_user();
$user2 = $dg->create_user();
$cohort = $dg->create_cohort();
$tpl = $lpg->create_template(array('duedate' => time() + 1000));
$templatecohort = api::create_template_cohort($tpl->get_id(), $cohort->id);
$task = \core\task\manager::get_scheduled_task('\\core\\task\\sync_plans_from_template_cohorts_task');
// Add 1 user to the cohort.
cohort_add_member($cohort->id, $user1->id);
// Creating plans from template cohort.
$task->execute();
$this->assertEquals(1, \core_competency\plan::count_records());
// Now add another user, but this time the template will be expired.
cohort_add_member($cohort->id, $user2->id);
$record = $tpl->to_record();
$record->duedate = time() - 10000;
$DB->update_record(\core_competency\template::TABLE, $record);
$tpl->read();
$task->execute();
$this->assertEquals(1, \core_competency\plan::count_records());
// Still only one plan.
// Pretend it wasn't expired.
$tpl->set_duedate(time() + 100);
$tpl->update();
$task->execute();
$this->assertEquals(2, \core_competency\plan::count_records());
// Now there is two.
}
示例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: moodle_url
// Set up the page.
$url = new moodle_url('/admin/tool/lp/template_cohorts.php', array('id' => $id, 'pagecontextid' => $pagecontextid));
list($title, $subtitle) = \tool_lp\page_helper::setup_for_template($pagecontextid, $url, $template, get_string('cohortssyncedtotemplate', 'tool_lp'));
// Remove cohort.
if ($canmanagetemplate && ($removecohort = optional_param('removecohort', false, PARAM_INT)) !== false && confirm_sesskey()) {
\core_competency\api::delete_template_cohort($template, $removecohort);
}
// Capture the form submission.
$form = new \tool_lp\form\template_cohorts($url->out(false), array('pagecontextid' => $pagecontextid));
if ($canmanagetemplate && ($data = $form->get_data()) && !empty($data->cohorts)) {
$maxtocreate = 50;
$maxreached = false;
$i = 0;
foreach ($data->cohorts as $cohortid) {
// Create the template/cohort relationship.
$relation = \core_competency\api::create_template_cohort($template, $cohortid);
// Create a plan for each member if template visible, and the due date is not reached, and we didn't reach our limit yet.
if ($template->get_visible() && $i < $maxtocreate && !$duedatereached) {
// Only create a few plans right now.
$tocreate = \core_competency\template_cohort::get_missing_plans($template->get_id(), $cohortid);
if ($i + count($tocreate) <= $maxtocreate) {
$i += \core_competency\api::create_plans_from_template_cohort($template, $cohortid);
} else {
$maxreached = true;
}
}
}
if ($i == 0) {
$notification = get_string('noplanswerecreated', 'tool_lp');
} else {
if ($i == 1) {