当前位置: 首页>>代码示例>>PHP>>正文


PHP api::create_plans_from_template_cohort方法代码示例

本文整理汇总了PHP中core_competency\api::create_plans_from_template_cohort方法的典型用法代码示例。如果您正苦于以下问题:PHP api::create_plans_from_template_cohort方法的具体用法?PHP api::create_plans_from_template_cohort怎么用?PHP api::create_plans_from_template_cohort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core_competency\api的用法示例。


在下文中一共展示了api::create_plans_from_template_cohort方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_plan_created_using_templatecohort

 /**
  * Test the plan created event using template_cohort.
  *
  */
 public function test_plan_created_using_templatecohort()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $user1 = $dg->create_user();
     $user2 = $dg->create_user();
     $c1 = $dg->create_cohort();
     // Add 2 users to the cohort.
     cohort_add_member($c1->id, $user1->id);
     cohort_add_member($c1->id, $user2->id);
     $t1 = $lpg->create_template();
     $tc = $lpg->create_template_cohort(array('templateid' => $t1->get_id(), 'cohortid' => $c1->id));
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     api::create_plans_from_template_cohort($t1->get_id(), $c1->id);
     // Get our event event.
     $plans = core_competency\plan::get_records(array('templateid' => $t1->get_id()), 'id');
     $events = $sink->get_events();
     $this->assertCount(2, $events);
     $this->assertCount(2, $plans);
     $event = $events[0];
     $plan = $plans[0];
     // 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);
     $event = $events[1];
     $plan = $plans[1];
     $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();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:40,代码来源:event_test.php

示例2: test_sync_plans_from_cohorts_with_templateduedate_task

 public function test_sync_plans_from_cohorts_with_templateduedate_task()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $user1 = $dg->create_user();
     $user2 = $dg->create_user();
     $user3 = $dg->create_user();
     $user4 = $dg->create_user();
     $user5 = $dg->create_user();
     $cohort = $dg->create_cohort();
     $tpl = $lpg->create_template(array('duedate' => time() + 400));
     // Add 2 users to the cohort.
     cohort_add_member($cohort->id, $user1->id);
     cohort_add_member($cohort->id, $user2->id);
     // Creating plans from template cohort.
     $templatecohort = api::create_template_cohort($tpl->get_id(), $cohort->id);
     $created = api::create_plans_from_template_cohort($tpl->get_id(), $cohort->id);
     $this->assertEquals(2, $created);
     $task = \core\task\manager::get_scheduled_task('\\core\\task\\sync_plans_from_template_cohorts_task');
     $this->assertInstanceOf('\\core\\task\\sync_plans_from_template_cohorts_task', $task);
     // Add two more users to the cohort.
     cohort_add_member($cohort->id, $user3->id);
     cohort_add_member($cohort->id, $user4->id);
     $task->execute();
     $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
     // Test if remove user from cohort will affect plans.
     cohort_remove_member($cohort->id, $user3->id);
     cohort_remove_member($cohort->id, $user4->id);
     $task->execute();
     $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
     // The template is now hidden, and I've added a user with a missing plan. Nothing should happen.
     $tpl->set_visible(false);
     $tpl->update();
     cohort_add_member($cohort->id, $user5->id);
     $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get_id())));
     $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
     $task->execute();
     $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get_id())));
     $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
     // Now I set the template as visible again, the plan is created.
     $tpl->set_visible(true);
     $tpl->update();
     $task->execute();
     $this->assertTrue(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get_id())));
     $this->assertEquals(5, plan::count_records(array('templateid' => $tpl->get_id())));
     // Let's unlink the plan and run the task again, it should not be recreated.
     $plan = plan::get_record(array('userid' => $user5->id, 'templateid' => $tpl->get_id()));
     \core_competency\api::unlink_plan_from_template($plan);
     $this->assertTrue(plan::record_exists_select('userid = ?', array($user5->id)));
     $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get_id())));
     $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
     $task->execute();
     $this->assertTrue(plan::record_exists_select('userid = ?', array($user5->id)));
     $this->assertFalse(plan::record_exists_select('userid = ? AND templateid = ?', array($user5->id, $tpl->get_id())));
     $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
     // Adding users to cohort that already exist in plans.
     cohort_add_member($cohort->id, $user3->id);
     cohort_add_member($cohort->id, $user4->id);
     $task->execute();
     $this->assertEquals(4, plan::count_records(array('templateid' => $tpl->get_id())));
 }
开发者ID:evltuma,项目名称:moodle,代码行数:63,代码来源:task_test.php

示例3: array

}
// 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) {
            $notification = get_string('oneplanwascreated', 'tool_lp');
        } else {
            if ($maxreached) {
                $notification = get_string('aplanswerecreatedmoremayrequiresync', 'tool_lp', $i);
            } else {
                $notification = get_string('aplanswerecreated', 'tool_lp', $i);
开发者ID:gabrielrosset,项目名称:moodle,代码行数:31,代码来源:template_cohorts.php


注:本文中的core_competency\api::create_plans_from_template_cohort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。