コード例 #1
0
ファイル: external.php プロジェクト: evltuma/moodle
 /**
  * Change the order of template competencies.
  *
  * @param int $templateid The template id
  * @param int $competencyidfrom The competency to move.
  * @param int $competencyidto The competency to move to.
  * @return bool
  */
 public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto)
 {
     $params = self::validate_parameters(self::reorder_template_competency_parameters(), array('templateid' => $templateid, 'competencyidfrom' => $competencyidfrom, 'competencyidto' => $competencyidto));
     $template = api::read_template($params['templateid']);
     self::validate_context($template->get_context());
     return api::reorder_template_competency($params['templateid'], $params['competencyidfrom'], $params['competencyidto']);
 }
コード例 #2
0
ファイル: api_test.php プロジェクト: dg711/moodle
 public function test_reorder_template_competencies_permissions()
 {
     $this->resetAfterTest(true);
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $cat = $dg->create_category();
     $catcontext = context_coursecat::instance($cat->id);
     $syscontext = context_system::instance();
     $user = $dg->create_user();
     $role = $dg->create_role();
     assign_capability('moodle/competency:templatemanage', CAP_ALLOW, $role, $syscontext->id, true);
     $dg->role_assign($role, $user->id, $syscontext->id);
     // Create a template.
     $template = $lpg->create_template(array('contextid' => $catcontext->id));
     // Create a competency framework.
     $framework = $lpg->create_framework(array('contextid' => $catcontext->id));
     // Create competencies.
     $competency1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $competency2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     // Add the competencies.
     $lpg->create_template_competency(array('templateid' => $template->get_id(), 'competencyid' => $competency1->get_id()));
     $lpg->create_template_competency(array('templateid' => $template->get_id(), 'competencyid' => $competency2->get_id()));
     $this->setUser($user);
     // Can reorder competencies with system context permissions in category context.
     $result = api::reorder_template_competency($template->get_id(), $competency2->get_id(), $competency1->get_id());
     $this->assertTrue($result);
     unassign_capability('moodle/competency:templatemanage', $role, $syscontext->id);
     accesslib_clear_all_caches_for_unit_testing();
     try {
         api::reorder_template_competency($template->get_id(), $competency2->get_id(), $competency1->get_id());
         $this->fail('Exception expected due to not permissions to manage template competencies');
     } catch (required_capability_exception $e) {
         $this->assertEquals('nopermissions', $e->errorcode);
     }
     // Giving permissions in category context.
     assign_capability('moodle/competency:templatemanage', CAP_ALLOW, $role, $catcontext->id, true);
     $dg->role_assign($role, $user->id, $catcontext->id);
     // User with templatemanage capability in category context can reorder competencies in temple.
     $result = api::reorder_template_competency($template->get_id(), $competency1->get_id(), $competency2->get_id());
     $this->assertTrue($result);
     // Removing templatemanage capability in category context.
     unassign_capability('moodle/competency:templatemanage', $role, $catcontext->id);
     accesslib_clear_all_caches_for_unit_testing();
     try {
         api::reorder_template_competency($template->get_id(), $competency2->get_id(), $competency1->get_id());
         $this->fail('Exception expected due to not permissions to manage template competencies');
     } catch (required_capability_exception $e) {
         $this->assertEquals('nopermissions', $e->errorcode);
     }
 }
コード例 #3
0
ファイル: api_test.php プロジェクト: IFPBMoodle/moodle
 /**
  * Test completing plan does not change the order of competencies.
  */
 public function test_complete_plan_doesnot_change_order()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $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();
     // 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));
     $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()));
     // Changing competencies order in plan competency.
     api::reorder_plan_competency($plan->get_id(), $c1->get_id(), $c3->get_id());
     $competencies = api::list_plan_competencies($plan);
     $this->assertEquals($c2->get_id(), $competencies[0]->competency->get_id());
     $this->assertEquals($c3->get_id(), $competencies[1]->competency->get_id());
     $this->assertEquals($c1->get_id(), $competencies[2]->competency->get_id());
     // Completing plan.
     api::complete_plan($plan);
     $competencies = api::list_plan_competencies($plan);
     // Completing plan does not change order.
     $this->assertEquals($c2->get_id(), $competencies[0]->competency->get_id());
     $this->assertEquals($c3->get_id(), $competencies[1]->competency->get_id());
     $this->assertEquals($c1->get_id(), $competencies[2]->competency->get_id());
     // Testing plan based on template.
     $template = $lpg->create_template();
     $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()));
     $lpg->create_template_competency(array('templateid' => $template->get_id(), 'competencyid' => $c1->get_id()));
     $lpg->create_template_competency(array('templateid' => $template->get_id(), 'competencyid' => $c2->get_id()));
     $lpg->create_template_competency(array('templateid' => $template->get_id(), 'competencyid' => $c3->get_id()));
     // Reorder competencies in template.
     api::reorder_template_competency($template->get_id(), $c1->get_id(), $c3->get_id());
     // Create plan from template.
     $plan = api::create_plan_from_template($template->get_id(), $user->id);
     $competencies = api::list_plan_competencies($plan);
     // Completing plan does not change order.
     $this->assertEquals($c2->get_id(), $competencies[0]->competency->get_id());
     $this->assertEquals($c3->get_id(), $competencies[1]->competency->get_id());
     $this->assertEquals($c1->get_id(), $competencies[2]->competency->get_id());
     // Completing plan.
     api::complete_plan($plan);
     $competencies = api::list_plan_competencies($plan);
     // Completing plan does not change order.
     $this->assertEquals($c2->get_id(), $competencies[0]->competency->get_id());
     $this->assertEquals($c3->get_id(), $competencies[1]->competency->get_id());
     $this->assertEquals($c1->get_id(), $competencies[2]->competency->get_id());
 }