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


PHP api::grade_competency_in_course方法代码示例

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


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

示例1: test_course_statistics

 /**
  * Test course statistics api functions.
  */
 public function test_course_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();
     // Enrol students in the course.
     $studentarch = get_archetype_roles('student');
     $studentrole = array_shift($studentarch);
     $coursecontext = context_course::instance($c1->id);
     $dg->role_assign($studentrole->id, $u1->id, $coursecontext->id);
     $dg->enrol_user($u1->id, $c1->id, $studentrole->id);
     $dg->role_assign($studentrole->id, $u2->id, $coursecontext->id);
     $dg->enrol_user($u2->id, $c1->id, $studentrole->id);
     $dg->role_assign($studentrole->id, $u3->id, $coursecontext->id);
     $dg->enrol_user($u3->id, $c1->id, $studentrole->id);
     $dg->role_assign($studentrole->id, $u4->id, $coursecontext->id);
     $dg->enrol_user($u4->id, $c1->id, $studentrole->id);
     // 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 6 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));
     $lpg->create_course_competency(array('competencyid' => $comp6->get_id(), 'courseid' => $c1->id));
     // Rate some competencies.
     // User 1.
     api::grade_competency_in_course($c1, $u1->id, $comp1->get_id(), 4, 'Unit test');
     api::grade_competency_in_course($c1, $u1->id, $comp2->get_id(), 4, 'Unit test');
     api::grade_competency_in_course($c1, $u1->id, $comp3->get_id(), 4, 'Unit test');
     api::grade_competency_in_course($c1, $u1->id, $comp4->get_id(), 4, 'Unit test');
     // User 2.
     api::grade_competency_in_course($c1, $u2->id, $comp1->get_id(), 1, 'Unit test');
     api::grade_competency_in_course($c1, $u2->id, $comp2->get_id(), 1, 'Unit test');
     api::grade_competency_in_course($c1, $u2->id, $comp3->get_id(), 1, 'Unit test');
     api::grade_competency_in_course($c1, $u2->id, $comp4->get_id(), 1, 'Unit test');
     // User 3.
     api::grade_competency_in_course($c1, $u3->id, $comp1->get_id(), 3, 'Unit test');
     api::grade_competency_in_course($c1, $u3->id, $comp2->get_id(), 3, 'Unit test');
     // User 4.
     api::grade_competency_in_course($c1, $u4->id, $comp1->get_id(), 2, 'Unit test');
     api::grade_competency_in_course($c1, $u4->id, $comp2->get_id(), 2, 'Unit test');
     // OK we have enough data - lets call some API functions and check for expected results.
     $result = api::count_proficient_competencies_in_course_for_user($c1->id, $u1->id);
     $this->assertEquals(4, $result);
     $result = api::count_proficient_competencies_in_course_for_user($c1->id, $u2->id);
     $this->assertEquals(0, $result);
     $result = api::count_proficient_competencies_in_course_for_user($c1->id, $u3->id);
     $this->assertEquals(2, $result);
     $result = api::count_proficient_competencies_in_course_for_user($c1->id, $u4->id);
     $this->assertEquals(0, $result);
     $result = api::get_least_proficient_competencies_for_course($c1->id, 0, 2);
     // We should get 5 and 6 in repeatable order.
     $valid = false;
     if ($comp5->get_id() == $result[0]->get_id() || $comp6->get_id() == $result[0]->get_id()) {
         $valid = true;
     }
     $this->assertTrue($valid);
     $valid = false;
     if ($comp5->get_id() == $result[1]->get_id() || $comp6->get_id() == $result[1]->get_id()) {
         $valid = true;
     }
     $this->assertTrue($valid);
     $expected = $result[1]->get_id();
     $result = api::get_least_proficient_competencies_for_course($c1->id, 1, 1);
     $this->assertEquals($result[0]->get_id(), $expected);
 }
开发者ID:dg711,项目名称:moodle,代码行数:83,代码来源:api_test.php

示例2: test_user_competency_rated_in_course

 /**
  * Test the user competency grade rated in course event.
  *
  */
 public function test_user_competency_rated_in_course()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $dg = $this->getDataGenerator();
     $lpg = $this->getDataGenerator()->get_plugin_generator('core_competency');
     $scale = $dg->create_scale(array('scale' => 'A,B,C,D'));
     $course = $dg->create_course();
     $user = $dg->create_user();
     $studentarch = get_archetype_roles('student');
     $studentrole = array_shift($studentarch);
     $scaleconfig = array(array('scaleid' => $scale->id));
     $scaleconfig[] = array('name' => 'A', 'id' => 1, 'scaledefault' => 0, 'proficient' => 0);
     $scaleconfig[] = array('name' => 'B', 'id' => 2, 'scaledefault' => 1, 'proficient' => 0);
     $scaleconfig[] = array('name' => 'C', 'id' => 3, 'scaledefault' => 0, 'proficient' => 1);
     $scaleconfig[] = array('name' => 'D', 'id' => 4, 'scaledefault' => 0, 'proficient' => 1);
     $fr = $lpg->create_framework();
     $c = $lpg->create_competency(array('competencyframeworkid' => $fr->get_id(), 'scaleid' => $scale->id, 'scaleconfiguration' => $scaleconfig));
     // Enrol the user as students in course.
     $dg->enrol_user($user->id, $course->id, $studentrole->id);
     $lpg->create_course_competency(array('courseid' => $course->id, 'competencyid' => $c->get_id()));
     $uc = $lpg->create_user_competency(array('userid' => $user->id, 'competencyid' => $c->get_id()));
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     api::grade_competency_in_course($course->id, $user->id, $c->get_id(), 2, true);
     // Get our event event.
     $events = $sink->get_events();
     // Evidence created.
     $this->assertCount(2, $events);
     $evidencecreatedevent = $events[0];
     $event = $events[1];
     // Check that the event data is valid.
     $this->assertInstanceOf('\\core\\event\\competency_evidence_created', $evidencecreatedevent);
     $this->assertInstanceOf('\\core\\event\\competency_user_competency_rated_in_course', $event);
     $this->assertEquals(context_course::instance($course->id)->id, $event->contextid);
     $this->assertEquals($course->id, $event->courseid);
     $this->assertEquals($uc->get_userid(), $event->relateduserid);
     $this->assertEquals($uc->get_competencyid(), $event->other['competencyid']);
     $this->assertEquals(2, $event->other['grade']);
     $this->assertEventContextNotUsed($event);
     $this->assertDebuggingNotCalled();
 }
开发者ID:evltuma,项目名称:moodle,代码行数:46,代码来源:event_test.php

示例3: grade_competency_in_course

 /**
  * Grade a competency in a course.
  *
  * @param int $courseid The course id
  * @param int $userid The user id
  * @param int $competencyid The competency id
  * @param int $grade The new grade value
  * @param string $note A note to add to the evidence
  * @return bool
  */
 public static function grade_competency_in_course($courseid, $userid, $competencyid, $grade, $note = null)
 {
     global $USER, $PAGE, $DB;
     $params = self::validate_parameters(self::grade_competency_in_course_parameters(), array('courseid' => $courseid, 'userid' => $userid, 'competencyid' => $competencyid, 'grade' => $grade, 'note' => $note));
     $course = $DB->get_record('course', array('id' => $params['courseid']));
     $context = context_course::instance($course->id);
     self::validate_context($context);
     $output = $PAGE->get_renderer('core');
     $evidence = api::grade_competency_in_course($params['courseid'], $params['userid'], $params['competencyid'], $params['grade'], $params['note']);
     $competency = api::read_competency($params['competencyid']);
     $scale = $competency->get_scale();
     $exporter = new evidence_exporter($evidence, array('actionuser' => $USER, 'scale' => $scale, 'usercompetency' => null, 'usercompetencyplan' => null));
     return $exporter->export($output);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:24,代码来源:external.php

示例4: test_who_can_change_settings

 public function test_who_can_change_settings()
 {
     global $CFG, $DB;
     $this->resetAfterTest(true);
     $syscontext = context_system::instance();
     $dg = $this->getDataGenerator();
     $lpg = $dg->get_plugin_generator('core_competency');
     $role = create_role('Settings changer role', 'settingschanger', 'Someone who can change course competency settings');
     assign_capability('moodle/competency:coursecompetencyconfigure', CAP_ALLOW, $role, $syscontext->id);
     assign_capability('moodle/competency:competencygrade', CAP_ALLOW, $role, $syscontext->id);
     assign_capability('moodle/competency:coursecompetencyview', CAP_ALLOW, $role, $syscontext->id);
     assign_capability('moodle/competency:planview', CAP_ALLOW, $role, $syscontext->id);
     $gradedrole = create_role('Graded role', 'graded', 'Someone who can be graded');
     assign_capability('moodle/competency:coursecompetencygradable', CAP_ALLOW, $gradedrole, $syscontext->id);
     $c1 = $dg->create_course();
     $u1 = $dg->create_user();
     $u2 = $dg->create_user();
     $u3 = $dg->create_user();
     $framework = $lpg->create_framework();
     $comp1 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $comp2 = $lpg->create_competency(array('competencyframeworkid' => $framework->get_id()));
     $lpg->create_course_competency(array('competencyid' => $comp1->get_id(), 'courseid' => $c1->id));
     $lpg->create_course_competency(array('competencyid' => $comp2->get_id(), 'courseid' => $c1->id));
     // Enrol the user.
     $dg->enrol_user($u1->id, $c1->id);
     role_assign($gradedrole, $u1->id, $syscontext->id);
     // Assign roles.
     role_assign($role, $u2->id, $syscontext->id);
     $this->setUser($u2);
     set_config('pushcourseratingstouserplans', true, 'core_competency');
     $coursesettings = course_competency_settings::get_by_courseid($c1->id);
     $this->assertTrue((bool) $coursesettings->get_pushratingstouserplans());
     set_config('pushcourseratingstouserplans', false, 'core_competency');
     $coursesettings = course_competency_settings::get_by_courseid($c1->id);
     $this->assertFalse((bool) $coursesettings->get_pushratingstouserplans());
     api::update_course_competency_settings($c1->id, (object) array('pushratingstouserplans' => true));
     $coursesettings = course_competency_settings::get_by_courseid($c1->id);
     $this->assertTrue((bool) $coursesettings->get_pushratingstouserplans());
     set_config('pushcourseratingstouserplans', true, 'core_competency');
     api::update_course_competency_settings($c1->id, (object) array('pushratingstouserplans' => false));
     $coursesettings = course_competency_settings::get_by_courseid($c1->id);
     $this->assertFalse((bool) $coursesettings->get_pushratingstouserplans());
     // Right now the setting is false.
     api::grade_competency_in_course($c1->id, $u1->id, $comp1->get_id(), 1, 'Note');
     $filterparams = array('userid' => $u1->id, 'competencyid' => $comp1->get_id());
     $usercompcourse = \core_competency\user_competency_course::get_record($filterparams);
     $usercomp = \core_competency\user_competency::get_record($filterparams);
     // No grade in plan - only a grade in the course.
     $this->assertEmpty($usercomp->get_grade());
     $this->assertEquals(1, $usercompcourse->get_grade());
     api::update_course_competency_settings($c1->id, (object) array('pushratingstouserplans' => true));
     api::grade_competency_in_course($c1->id, $u1->id, $comp1->get_id(), 2, 'Note 2');
     $filterparams = array('userid' => $u1->id, 'competencyid' => $comp1->get_id());
     $usercompcourse = \core_competency\user_competency_course::get_record($filterparams);
     $usercomp = \core_competency\user_competency::get_record($filterparams);
     // Updated grade in plan - updated grade in the course.
     $this->assertEquals(2, $usercomp->get_grade());
     $this->assertEquals(2, $usercompcourse->get_grade());
     $this->setUser($u3);
     $this->setExpectedException('required_capability_exception');
     api::update_course_competency_settings($c1->id, (object) array('pushratingstouserplans' => false));
 }
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:62,代码来源:course_competency_settings_test.php


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