本文整理汇总了PHP中core_competency\api::reopen_plan方法的典型用法代码示例。如果您正苦于以下问题:PHP api::reopen_plan方法的具体用法?PHP api::reopen_plan怎么用?PHP api::reopen_plan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::reopen_plan方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_update_plan_manage_archived_competencies
/**
* Test update plan and the managing of archived user competencies.
*/
public function test_update_plan_manage_archived_competencies()
{
global $DB;
$this->resetAfterTest(true);
$dg = $this->getDataGenerator();
$lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
$syscontext = context_system::instance();
// Create users and roles for the test.
$user = $dg->create_user();
$manageownrole = $dg->create_role(array('name' => 'User manage own', 'shortname' => 'manageown'));
assign_capability('moodle/competency:planmanageowndraft', CAP_ALLOW, $manageownrole, $syscontext->id);
assign_capability('moodle/competency:planviewowndraft', CAP_ALLOW, $manageownrole, $syscontext->id);
assign_capability('moodle/competency:planmanageown', CAP_ALLOW, $manageownrole, $syscontext->id);
assign_capability('moodle/competency:planviewown', CAP_ALLOW, $manageownrole, $syscontext->id);
$dg->role_assign($manageownrole, $user->id, $syscontext->id);
$this->setUser($user);
// Create a framework and assign competencies.
$framework = $lpg->create_framework();
$c1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$c2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
$c3 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
// Create two plans and assign competencies.
$plan = $lpg->create_plan(array('userid' => $user->id));
$otherplan = $lpg->create_plan(array('userid' => $user->id));
$lpg->create_plan_competency(array('planid' => $plan->get_id(), 'competencyid' => $c1->get_id()));
$lpg->create_plan_competency(array('planid' => $plan->get_id(), 'competencyid' => $c2->get_id()));
$lpg->create_plan_competency(array('planid' => $plan->get_id(), 'competencyid' => $c3->get_id()));
$lpg->create_plan_competency(array('planid' => $otherplan->get_id(), 'competencyid' => $c1->get_id()));
$uclist = array($lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c1->get_id(), 'proficiency' => true, 'grade' => 1)), $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c2->get_id(), 'proficiency' => false, 'grade' => 2)));
// Change status of the plan to complete.
$record = $plan->to_record();
$record->status = \core_competency\plan::STATUS_COMPLETE;
try {
$plan = api::update_plan($record);
$this->fail('We cannot complete a plan using api::update_plan().');
} catch (coding_exception $e) {
// All good.
}
api::complete_plan($plan);
// Check that user compretencies are now in user_competency_plan objects and still in user_competency.
$this->assertEquals(2, \core_competency\user_competency::count_records());
$this->assertEquals(3, \core_competency\user_competency_plan::count_records());
$usercompetenciesplan = \core_competency\user_competency_plan::get_records();
$this->assertEquals($uclist[0]->get_userid(), $usercompetenciesplan[0]->get_userid());
$this->assertEquals($uclist[0]->get_competencyid(), $usercompetenciesplan[0]->get_competencyid());
$this->assertEquals($uclist[0]->get_proficiency(), (bool) $usercompetenciesplan[0]->get_proficiency());
$this->assertEquals($uclist[0]->get_grade(), $usercompetenciesplan[0]->get_grade());
$this->assertEquals($plan->get_id(), $usercompetenciesplan[0]->get_planid());
$this->assertEquals($uclist[1]->get_userid(), $usercompetenciesplan[1]->get_userid());
$this->assertEquals($uclist[1]->get_competencyid(), $usercompetenciesplan[1]->get_competencyid());
$this->assertEquals($uclist[1]->get_proficiency(), (bool) $usercompetenciesplan[1]->get_proficiency());
$this->assertEquals($uclist[1]->get_grade(), $usercompetenciesplan[1]->get_grade());
$this->assertEquals($plan->get_id(), $usercompetenciesplan[1]->get_planid());
$this->assertEquals($user->id, $usercompetenciesplan[2]->get_userid());
$this->assertEquals($c3->get_id(), $usercompetenciesplan[2]->get_competencyid());
$this->assertNull($usercompetenciesplan[2]->get_proficiency());
$this->assertNull($usercompetenciesplan[2]->get_grade());
$this->assertEquals($plan->get_id(), $usercompetenciesplan[2]->get_planid());
// Change status of the plan to active.
$record = $plan->to_record();
$record->status = \core_competency\plan::STATUS_ACTIVE;
try {
api::update_plan($record);
$this->fail('Completed plan can not be edited');
} catch (coding_exception $e) {
// All good.
}
api::reopen_plan($record->id);
// Check that user_competency_plan objects are deleted if the plan status is changed to another status.
$this->assertEquals(2, \core_competency\user_competency::count_records());
$this->assertEquals(0, \core_competency\user_competency_plan::count_records());
}
示例2: test_plan_reopened
/**
* Test the plan reopened event.
*
*/
public function test_plan_reopened()
{
$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_COMPLETE));
$planid = $plan->get_id();
$contextid = $plan->get_context()->id;
// Trigger and capture the event.
$sink = $this->redirectEvents();
$result = api::reopen_plan($plan->get_id());
$this->assertTrue($result);
// Get our event event.
$events = $sink->get_events();
$event = reset($events);
$this->assertInstanceOf('\\core\\event\\competency_plan_reopened', $event);
$this->assertEquals($planid, $event->objectid);
$this->assertEquals($contextid, $event->contextid);
$this->assertEquals($plan->get_userid(), $event->relateduserid);
$this->assertEventContextNotUsed($event);
$this->assertDebuggingNotCalled();
}
示例3: reopen_plan
/**
* Reopen Learning plan.
*
* @param int $planid plan id (id is required)
* @return boolean
*/
public static function reopen_plan($planid)
{
$params = self::validate_parameters(self::reopen_plan_parameters(), array('planid' => $planid));
return api::reopen_plan($params['planid']);
}
示例4: test_validate_duedate
//.........这里部分代码省略.........
// 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());
$this->assertTrue($success);
// Completing plan: with due date unset (pass).
$record = $plan->to_record();
$record->status = plan::STATUS_ACTIVE;
$record->duedate = 0;
$DB->update_record(plan::TABLE, $record);
$success = core_competency\api::complete_plan($plan->get_id());
$this->assertTrue($success);
// Reopening plan: with due date in the past => duedate unset.
$record = $plan->to_record();
$record->status = plan::STATUS_COMPLETE;
$record->duedate = time() - 200;
$DB->update_record(plan::TABLE, $record);
$success = core_competency\api::reopen_plan($plan->get_id());
$this->assertTrue($success);
$plan->read();
$this->assertEquals(0, $plan->get_duedate());
// Reopening plan: with due date too soon => duedate unset.
$record = $plan->to_record();
$record->status = plan::STATUS_COMPLETE;
$record->duedate = time() + 100;
$DB->update_record(plan::TABLE, $record);
$success = core_competency\api::reopen_plan($plan->get_id());
$this->assertTrue($success);
$plan->read();
$this->assertEquals(0, $plan->get_duedate());
// Reopening plan: with due date in the future => duedate unchanged.
$record = $plan->to_record();
$record->status = plan::STATUS_COMPLETE;
$duedate = time() + plan::DUEDATE_THRESHOLD + 10;
$record->duedate = $duedate;
$DB->update_record(plan::TABLE, $record);
$success = core_competency\api::reopen_plan($plan->get_id());
$this->assertTrue($success);
$plan->read();
// Check that the due date has not changed.
$this->assertNotEquals(0, $plan->get_duedate());
$this->assertEquals($duedate, $plan->get_duedate());
}