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


PHP api::complete_plan方法代码示例

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


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

示例1: execute

 /**
  * Do the job.
  */
 public function execute()
 {
     if (!api::is_enabled()) {
         return;
     }
     $records = plan::get_recordset_for_due_and_incomplete();
     foreach ($records as $record) {
         $plan = new plan(0, $record);
         api::complete_plan($plan);
     }
     $records->close();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:15,代码来源:complete_plans_task.php

示例2: test_list_plans_to_review

 public function test_list_plans_to_review()
 {
     $dg = $this->getDataGenerator();
     $this->resetAfterTest();
     $ccg = $dg->get_plugin_generator('core_competency');
     $sysctx = context_system::instance();
     $this->setAdminUser();
     $reviewer = $dg->create_user();
     $roleallow = $dg->create_role();
     $roleprohibit = $dg->create_role();
     assign_capability('moodle/competency:planreview', CAP_ALLOW, $roleallow, $sysctx->id);
     assign_capability('moodle/competency:planreview', CAP_PROHIBIT, $roleprohibit, $sysctx->id);
     role_assign($roleallow, $reviewer->id, $sysctx->id);
     accesslib_clear_all_caches_for_unit_testing();
     $u1 = $dg->create_user();
     $u2 = $dg->create_user();
     $f1 = $ccg->create_framework();
     $comp1 = $ccg->create_competency(['competencyframeworkid' => $f1->get_id()]);
     $p1a = $ccg->create_plan(['userid' => $u1->id, 'status' => plan::STATUS_WAITING_FOR_REVIEW]);
     $p1b = $ccg->create_plan(['userid' => $u1->id, 'status' => plan::STATUS_IN_REVIEW, 'reviewerid' => $reviewer->id]);
     $p1c = $ccg->create_plan(['userid' => $u1->id, 'status' => plan::STATUS_DRAFT]);
     $p2a = $ccg->create_plan(['userid' => $u2->id, 'status' => plan::STATUS_WAITING_FOR_REVIEW]);
     $p2b = $ccg->create_plan(['userid' => $u2->id, 'status' => plan::STATUS_IN_REVIEW]);
     $p2c = $ccg->create_plan(['userid' => $u2->id, 'status' => plan::STATUS_ACTIVE]);
     $p2d = $ccg->create_plan(['userid' => $u2->id, 'status' => plan::STATUS_ACTIVE]);
     api::complete_plan($p2d);
     // The reviewer can review all plans waiting for review, or in review where they are the reviewer.
     $this->setUser($reviewer);
     $result = api::list_plans_to_review();
     $this->assertEquals(3, $result['count']);
     $this->assertEquals($p1a->get_id(), $result['plans'][0]->plan->get_id());
     $this->assertEquals($p1b->get_id(), $result['plans'][1]->plan->get_id());
     $this->assertEquals($p2a->get_id(), $result['plans'][2]->plan->get_id());
     // The reviewer cannot view the plans when they do not have the permission in the user's context.
     role_assign($roleprohibit, $reviewer->id, context_user::instance($u2->id)->id);
     accesslib_clear_all_caches_for_unit_testing();
     $result = api::list_plans_to_review();
     $this->assertEquals(2, $result['count']);
     $this->assertEquals($p1a->get_id(), $result['plans'][0]->plan->get_id());
     $this->assertEquals($p1b->get_id(), $result['plans'][1]->plan->get_id());
 }
开发者ID:dg711,项目名称:moodle,代码行数:41,代码来源:api_test.php

示例3: complete_plan

 /**
  * Complete Learning plan.
  *
  * @param int $planid plan id (id is required)
  * @return boolean
  */
 public static function complete_plan($planid)
 {
     $params = self::validate_parameters(self::complete_plan_parameters(), array('planid' => $planid));
     return api::complete_plan($params['planid']);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:11,代码来源:external.php

示例4: test_plan_completed

 /**
  * Test the plan completed event.
  *
  */
 public function test_plan_completed()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $user1 = $dg->create_user();
     $plan = $lpg->create_plan(array('userid' => $user1->id, 'status' => \core_competency\plan::STATUS_ACTIVE));
     $planid = $plan->get_id();
     $contextid = $plan->get_context()->id;
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $result = api::complete_plan($plan->get_id());
     $this->assertTrue($result);
     // Get our event event.
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\competency_plan_completed', $event);
     $this->assertEquals($planid, $event->objectid);
     $this->assertEquals($contextid, $event->contextid);
     $this->assertEquals($plan->get_userid(), $event->relateduserid);
     $this->assertEventContextNotUsed($event);
     $this->assertDebuggingNotCalled();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:28,代码来源:event_test.php

示例5: test_get_competency

 public function test_get_competency()
 {
     $this->resetAfterTest();
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $u1 = $dg->create_user();
     $u2 = $dg->create_user();
     $u3 = $dg->create_user();
     $u4 = $dg->create_user();
     $f1 = $lpg->create_framework();
     $c1 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c2 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c3 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $c4 = $lpg->create_competency(array('competencyframeworkid' => $f1->get_id()));
     $tpl1 = $lpg->create_template();
     $p1 = $lpg->create_plan(array('userid' => $u1->id));
     $p2 = $lpg->create_plan(array('userid' => $u2->id));
     $p3 = $lpg->create_plan(array('userid' => $u3->id, 'templateid' => $tpl1->get_id()));
     $p4 = $lpg->create_plan(array('userid' => $u4->id, 'templateid' => $tpl1->get_id()));
     $lpg->create_plan_competency(array('planid' => $p1->get_id(), 'competencyid' => $c1->get_id()));
     $lpg->create_plan_competency(array('planid' => $p2->get_id(), 'competencyid' => $c2->get_id()));
     $lpg->create_template_competency(array('templateid' => $tpl1->get_id(), 'competencyid' => $c3->get_id()));
     $lpg->create_template_competency(array('templateid' => $tpl1->get_id(), 'competencyid' => $c4->get_id()));
     // Completing the plans and removing a competency from the template.
     api::complete_plan($p2);
     api::complete_plan($p4);
     api::remove_competency_from_template($tpl1->get_id(), $c4->get_id());
     // We can find all competencies.
     $this->assertEquals($c1->to_record(), $p1->get_competency($c1->get_id())->to_record());
     $this->assertEquals($c2->to_record(), $p2->get_competency($c2->get_id())->to_record());
     $this->assertEquals($c3->to_record(), $p3->get_competency($c3->get_id())->to_record());
     $this->assertEquals($c4->to_record(), $p4->get_competency($c4->get_id())->to_record());
     // Getting the competency 4 from the non-completed plan based on a template p4, will throw an exception.
     $this->setExpectedException('coding_exception', 'The competency does not belong to this template: ');
     $p3->get_competency($c4->get_id());
 }
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:37,代码来源:plan_test.php

示例6: test_validate_duedate

 public function test_validate_duedate()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $user = $dg->create_user();
     $record = array('userid' => $user->id, 'status' => plan::STATUS_DRAFT, 'duedate' => time() - 8000);
     // Ignore duedate validation on create/update draft plan.
     $plan = $lpg->create_plan($record);
     $this->assertInstanceOf('core_competency\\plan', $plan);
     // Passing from draft to active.
     $plan->set_status(plan::STATUS_ACTIVE);
     // Draft to active with duedate in the past.
     $expected = array('duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'));
     $this->assertEquals($expected, $plan->validate());
     // Draft to active: past date => past date(fail).
     $plan->set_duedate(time() - 100);
     $expected = array('duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'));
     $this->assertEquals($expected, $plan->validate());
     // Draft to active: past date => too soon (fail).
     $plan->set_duedate(time() + 100);
     $expected = array('duedate' => new lang_string('errorcannotsetduedatetoosoon', 'core_competency'));
     $this->assertEquals($expected, $plan->validate());
     // Draft to active: past date => future date (pass).
     $plan->set_duedate(time() + plan::DUEDATE_THRESHOLD + 10);
     $this->assertEquals(true, $plan->validate());
     // Draft to active: past date => unset date (pass).
     $plan->set_duedate(0);
     $this->assertEquals(true, $plan->validate());
     // Updating active plan.
     $plan->update();
     // Active to active: past => same past (pass).
     $record = $plan->to_record();
     $record->duedate = 1;
     $DB->update_record(plan::TABLE, $record);
     $plan->read();
     $plan->set_description(uniqid());
     // Force revalidation.
     $this->assertTrue($plan->is_valid());
     // Active to active: past => unset (pass).
     $plan->set_duedate(0);
     $this->assertTrue($plan->is_valid());
     $plan->update();
     // Active to active: unset => unset (pass).
     $plan->set_description(uniqid());
     // Force revalidation.
     $this->assertTrue($plan->is_valid());
     // Active to active: unset date => past date(fail).
     $plan->set_duedate(time() - 100);
     $expected = array('duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'));
     $this->assertEquals($expected, $plan->validate());
     // Active to active: unset date => too soon (fail).
     $plan->set_duedate(time() + 100);
     $expected = array('duedate' => new lang_string('errorcannotsetduedatetoosoon', 'core_competency'));
     $this->assertEquals($expected, $plan->validate());
     // Active to active: unset date => future date (pass).
     $plan->set_duedate(time() + plan::DUEDATE_THRESHOLD + 10);
     $this->assertEquals(true, $plan->validate());
     // Updating active plan with future date.
     $plan->update();
     // Active to active: future => same future (pass).
     $plan->set_description(uniqid());
     // Force revalidation.
     $this->assertTrue($plan->is_valid());
     // Active to active: future date => unset date (pass).
     $plan->set_duedate(0);
     $this->assertEquals(true, $plan->validate());
     // Active to active: future date => past date(fail).
     $plan->set_duedate(time() - 100);
     $expected = array('duedate' => new lang_string('errorcannotsetduedateinthepast', 'core_competency'));
     $this->assertEquals($expected, $plan->validate());
     // Active to active: future date => too soon (fail).
     $plan->set_duedate(time() + 100);
     $expected = array('duedate' => new lang_string('errorcannotsetduedatetoosoon', 'core_competency'));
     $this->assertEquals($expected, $plan->validate());
     // Active to active: future date => future date (pass).
     $plan->set_duedate(time() + plan::DUEDATE_THRESHOLD + 10);
     $this->assertEquals(true, $plan->validate());
     // Completing plan: with due date in the past.
     $record = $plan->to_record();
     $record->status = plan::STATUS_ACTIVE;
     $record->duedate = time() - 200;
     $DB->update_record(plan::TABLE, $record);
     $success = core_competency\api::complete_plan($plan->get_id());
     $this->assertTrue($success);
     // Completing plan: with due date too soon (pass).
     $record = $plan->to_record();
     $record->status = plan::STATUS_ACTIVE;
     $record->duedate = time() + 200;
     $DB->update_record(plan::TABLE, $record);
     $success = core_competency\api::complete_plan($plan->get_id());
     $this->assertTrue($success);
     // Completing plan: with due date in the future (pass).
     $record = $plan->to_record();
     $record->status = plan::STATUS_ACTIVE;
     $record->duedate = time() + plan::DUEDATE_THRESHOLD + 10;
     $DB->update_record(plan::TABLE, $record);
     $success = core_competency\api::complete_plan($plan->get_id());
//.........这里部分代码省略.........
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:101,代码来源:plan_test.php

示例7: test_delete_plan_removes_relations

 public function test_delete_plan_removes_relations()
 {
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $user = $dg->create_user();
     $plan = $lpg->create_plan(array('userid' => $user->id));
     $framework = $lpg->create_framework();
     $comp1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $pc1 = $lpg->create_plan_competency(array('planid' => $plan->get_id(), 'competencyid' => $comp1->get_id()));
     $pc2 = $lpg->create_plan_competency(array('planid' => $plan->get_id(), 'competencyid' => $comp2->get_id()));
     $pc3 = $lpg->create_plan_competency(array('planid' => $plan->get_id(), 'competencyid' => $comp3->get_id()));
     // Complete the plan to generate user_competency_plan entries.
     api::complete_plan($plan);
     // Confirm the data we have.
     $this->assertEquals(3, plan_competency::count_records(array('planid' => $plan->get_id())));
     $this->assertEquals(3, user_competency_plan::count_records(array('planid' => $plan->get_id(), 'userid' => $user->id)));
     // Delete the plan now.
     api::delete_plan($plan->get_id());
     $this->assertEquals(0, plan_competency::count_records(array('planid' => $plan->get_id())));
     $this->assertEquals(0, user_competency_plan::count_records(array('planid' => $plan->get_id(), 'userid' => $user->id)));
 }
开发者ID:reconnectmedia,项目名称:moodle,代码行数:24,代码来源:external_test.php

示例8: test_template_statistics

 /**
  * Test template statistics api functions.
  */
 public function test_template_statistics()
 {
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $this->setAdminUser();
     $u1 = $dg->create_user();
     $u2 = $dg->create_user();
     $u3 = $dg->create_user();
     $u4 = $dg->create_user();
     $c1 = $dg->create_course();
     $framework = $lpg->create_framework();
     // Create 6 competencies.
     $comp1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp4 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp5 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp6 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     // Link 5 out of 6 to a course.
     $lpg->create_course_competency(array('competencyid' => $comp1->get_id(), 'courseid' => $c1->id));
     $lpg->create_course_competency(array('competencyid' => $comp2->get_id(), 'courseid' => $c1->id));
     $lpg->create_course_competency(array('competencyid' => $comp3->get_id(), 'courseid' => $c1->id));
     $lpg->create_course_competency(array('competencyid' => $comp4->get_id(), 'courseid' => $c1->id));
     $lpg->create_course_competency(array('competencyid' => $comp5->get_id(), 'courseid' => $c1->id));
     // Put all 6 in a template.
     $tpl = $this->getDataGenerator()->get_plugin_generator('core_competency')->create_template();
     $tplc1 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $comp1->get_id()));
     $tplc2 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $comp2->get_id()));
     $tplc3 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $comp3->get_id()));
     $tplc4 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $comp4->get_id()));
     $tplc5 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $comp5->get_id()));
     $tplc6 = $lpg->create_template_competency(array('templateid' => $tpl->get_id(), 'competencyid' => $comp6->get_id()));
     // Create some plans from the template.
     $p1 = $lpg->create_plan(array('templateid' => $tpl->get_id(), 'userid' => $u1->id));
     $p2 = $lpg->create_plan(array('templateid' => $tpl->get_id(), 'userid' => $u2->id));
     $p3 = $lpg->create_plan(array('templateid' => $tpl->get_id(), 'userid' => $u3->id));
     $p4 = $lpg->create_plan(array('templateid' => $tpl->get_id(), 'userid' => $u4->id));
     // Rate some competencies.
     // User 1.
     $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $comp1->get_id(), 'proficiency' => true, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $comp2->get_id(), 'proficiency' => true, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u1->id, 'competencyid' => $comp3->get_id(), 'proficiency' => true, 'grade' => 1));
     // User 2.
     $lpg->create_user_competency(array('userid' => $u2->id, 'competencyid' => $comp1->get_id(), 'proficiency' => false, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u2->id, 'competencyid' => $comp2->get_id(), 'proficiency' => false, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u2->id, 'competencyid' => $comp3->get_id(), 'proficiency' => false, 'grade' => 1));
     // User 3.
     $lpg->create_user_competency(array('userid' => $u3->id, 'competencyid' => $comp2->get_id(), 'proficiency' => false, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u3->id, 'competencyid' => $comp3->get_id(), 'proficiency' => true, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u3->id, 'competencyid' => $comp4->get_id(), 'proficiency' => false, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u3->id, 'competencyid' => $comp5->get_id(), 'proficiency' => true, 'grade' => 1));
     // User 4.
     $lpg->create_user_competency(array('userid' => $u4->id, 'competencyid' => $comp3->get_id(), 'proficiency' => true, 'grade' => 1));
     $lpg->create_user_competency(array('userid' => $u4->id, 'competencyid' => $comp5->get_id(), 'proficiency' => true, 'grade' => 1));
     // Complete 3 out of 4 plans.
     api::complete_plan($p1->get_id());
     api::complete_plan($p2->get_id());
     api::complete_plan($p3->get_id());
     // OK we have enough data - lets call some API functions and check for expected results.
     $result = api::count_competencies_in_template_with_no_courses($tpl->get_id());
     $this->assertEquals(1, $result);
     $result = api::count_plans_for_template($tpl->get_id());
     $this->assertEquals(4, $result);
     $result = api::count_plans_for_template($tpl->get_id(), plan::STATUS_COMPLETE);
     $this->assertEquals(3, $result);
     // This counts the records of competencies in completed plans for all users with a plan from this template.
     $result = api::count_user_competency_plans_for_template($tpl->get_id());
     // There should be 3 plans * 6 competencies.
     $this->assertEquals(18, $result);
     // This counts the records of proficient competencies in completed plans for all users with a plan from this template.
     $result = api::count_user_competency_plans_for_template($tpl->get_id(), true);
     // There should be 5.
     $this->assertEquals(5, $result);
     // This counts the records of not proficient competencies in completed plans for all users with a plan from this template.
     $result = api::count_user_competency_plans_for_template($tpl->get_id(), false);
     // There should be 13.
     $this->assertEquals(13, $result);
     // This lists the plans based on this template, optionally filtered by status.
     $result = api::list_plans_for_template($tpl->get_id());
     $this->assertEquals(4, count($result));
     foreach ($result as $one) {
         $this->assertInstanceOf('\\core_competency\\plan', $one);
     }
     // This lists the plans based on this template, optionally filtered by status.
     $result = api::list_plans_for_template($tpl->get_id(), plan::STATUS_COMPLETE);
     $this->assertEquals(3, count($result));
     foreach ($result as $one) {
         $this->assertInstanceOf('\\core_competency\\plan', $one);
         $this->assertEquals(plan::STATUS_COMPLETE, $one->get_status());
     }
     $result = api::get_least_proficient_competencies_for_template($tpl->get_id(), 0, 2);
     // Our times completed counts should look like this:
     // - comp1 - 1
     // - comp2 - 1
     // - comp3 - 2
     // - comp4 - 0
//.........这里部分代码省略.........
开发者ID:reconnectmedia,项目名称:moodle,代码行数:101,代码来源:api_test.php


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