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


PHP api::update_plan方法代码示例

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


在下文中一共展示了api::update_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());
 }
开发者ID:dg711,项目名称:moodle,代码行数:75,代码来源:api_test.php

示例2: update_plan

 /**
  * Updates a new learning plan.
  *
  * @param array $plan Fields for the plan (id is required)
  * @return mixed
  */
 public static function update_plan($plan)
 {
     global $PAGE;
     $params = self::validate_parameters(self::update_plan_parameters(), array('plan' => $plan));
     $params = $params['plan'];
     $plan = api::read_plan($params['id']);
     self::validate_context($plan->get_context());
     $output = $PAGE->get_renderer('core');
     $params = (object) $params;
     $result = api::update_plan($params);
     $exporter = plan_exporter($result);
     $record = $exporter->export($output);
     return external_api::clean_returnvalue(self::update_plan_returns(), $record);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:external.php

示例3: coding_exception

    if (!$plan->can_be_edited()) {
        throw new coding_exception('Completed plan can not be edited');
    }
} else {
    if (!$cancreate) {
        throw new required_capability_exception($PAGE->context, 'moodle/competency:planmanage', 'nopermissions', '');
    }
}
$form = new \tool_lp\form\plan($url->out(false), $customdata);
if ($form->is_cancelled()) {
    redirect($returnurl);
}
$data = $form->get_data();
if ($data) {
    if (empty($data->id)) {
        $plan = \core_competency\api::create_plan($data);
        $returnurl = new moodle_url('/admin/tool/lp/plan.php', ['id' => $plan->get_id()]);
        $returnmsg = get_string('plancreated', 'tool_lp');
    } else {
        \core_competency\api::update_plan($data);
        $returnmsg = get_string('planupdated', 'tool_lp');
    }
    redirect($returnurl, $returnmsg, null, \core\output\notification::NOTIFY_SUCCESS);
}
echo $output->header();
echo $output->heading($title);
if (!empty($subtitle)) {
    echo $output->heading($subtitle, 3);
}
$form->display();
echo $output->footer();
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:editplan.php

示例4: test_plan_updated

 /**
  * Test the plan updated event.
  *
  */
 public function test_plan_updated()
 {
     $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));
     $record = $plan->to_record();
     $record->name = 'Plan updated';
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $plan = api::update_plan($record);
     $this->assertEquals('Plan updated', $plan->get_name());
     // Get our event event.
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\core\\event\\competency_plan_updated', $event);
     $this->assertEquals($plan->get_id(), $event->objectid);
     $this->assertEquals($plan->get_context()->id, $event->contextid);
     $this->assertEventContextNotUsed($event);
     $this->assertDebuggingNotCalled();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:27,代码来源:event_test.php


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