本文整理汇总了PHP中grade_item::get_grade方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::get_grade方法的具体用法?PHP grade_item::get_grade怎么用?PHP grade_item::get_grade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_item
的用法示例。
在下文中一共展示了grade_item::get_grade方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
function test_upgrade_calculated_grade_items_regrade()
{
global $DB, $CFG;
$this->resetAfterTest();
// Create a user.
$user = $this->getDataGenerator()->create_user();
// Create a course.
$course = $this->getDataGenerator()->create_course();
// Enrol the user in the course.
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$maninstance1 = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$manual = enrol_get_plugin('manual');
$manual->enrol_user($maninstance1, $user->id, $studentrole->id);
set_config('upgrade_calculatedgradeitemsonlyregrade', 1);
// Creating a category for a grade item.
$gradecategory = new grade_category();
$gradecategory->fullname = 'calculated grade category';
$gradecategory->courseid = $course->id;
$gradecategory->insert();
$gradecategoryid = $gradecategory->id;
// This is a manual grade item.
$gradeitem = new grade_item();
$gradeitem->itemname = 'grade item one';
$gradeitem->itemtype = 'manual';
$gradeitem->categoryid = $gradecategoryid;
$gradeitem->courseid = $course->id;
$gradeitem->idnumber = 'gi1';
$gradeitem->insert();
// Changing the category into a calculated grade category.
$gradecategoryitem = grade_item::fetch(array('iteminstance' => $gradecategory->id));
$gradecategoryitem->calculation = '=##gi' . $gradeitem->id . '##/2';
$gradecategoryitem->grademax = 50;
$gradecategoryitem->grademin = 15;
$gradecategoryitem->update();
// Setting a grade for the student.
$grade = $gradeitem->get_grade($user->id, true);
$grade->finalgrade = 50;
$grade->update();
grade_regrade_final_grades($course->id);
$grade = grade_grade::fetch(array('itemid' => $gradecategoryitem->id, 'userid' => $user->id));
$grade->rawgrademax = 100;
$grade->rawgrademin = 0;
$grade->update();
$this->assertNotEquals($gradecategoryitem->grademax, $grade->rawgrademax);
$this->assertNotEquals($gradecategoryitem->grademin, $grade->rawgrademin);
// This is the function that we are testing. If we comment out this line, then the test fails because the grade items
// are not flagged for regrading.
upgrade_calculated_grade_items();
grade_regrade_final_grades($course->id);
$grade = grade_grade::fetch(array('itemid' => $gradecategoryitem->id, 'userid' => $user->id));
$this->assertEquals($gradecategoryitem->grademax, $grade->rawgrademax);
$this->assertEquals($gradecategoryitem->grademin, $grade->rawgrademin);
}
示例2: test_upgrade_calculated_grade_items
/**
* Test the upgrade function for flagging courses with calculated grade item problems.
*/
public function test_upgrade_calculated_grade_items() {
global $DB, $CFG;
$this->resetAfterTest();
// Create a user.
$user = $this->getDataGenerator()->create_user();
// Create a couple of courses.
$course1 = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$course3 = $this->getDataGenerator()->create_course();
// Enrol the user in the courses.
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
$manual = enrol_get_plugin('manual');
$manual->enrol_user($maninstance1, $user->id, $studentrole->id);
$manual->enrol_user($maninstance2, $user->id, $studentrole->id);
$manual->enrol_user($maninstance3, $user->id, $studentrole->id);
// To create the data we need we freeze the grade book to use the old behaviour.
set_config('gradebook_calculations_freeze_' . $course1->id, 20150627);
set_config('gradebook_calculations_freeze_' . $course2->id, 20150627);
set_config('gradebook_calculations_freeze_' . $course3->id, 20150627);
$CFG->grade_minmaxtouse = 2;
// Creating a category for a grade item.
$gradecategory = new grade_category();
$gradecategory->fullname = 'calculated grade category';
$gradecategory->courseid = $course1->id;
$gradecategory->insert();
$gradecategoryid = $gradecategory->id;
// This is a manual grade item.
$gradeitem = new grade_item();
$gradeitem->itemname = 'grade item one';
$gradeitem->itemtype = 'manual';
$gradeitem->categoryid = $gradecategoryid;
$gradeitem->courseid = $course1->id;
$gradeitem->idnumber = 'gi1';
$gradeitem->insert();
// Changing the category into a calculated grade category.
$gradecategoryitem = grade_item::fetch(array('iteminstance' => $gradecategory->id));
$gradecategoryitem->calculation = '=##gi' . $gradeitem->id . '##/2';
$gradecategoryitem->update();
// Setting a grade for the student.
$grade = $gradeitem->get_grade($user->id, true);
$grade->finalgrade = 50;
$grade->update();
// Creating all the grade_grade items.
grade_regrade_final_grades($course1->id);
// Updating the grade category to a new grade max and min.
$gradecategoryitem->grademax = 50;
$gradecategoryitem->grademin = 5;
$gradecategoryitem->update();
// Different manual grade item for course 2. We are creating a course with a calculated grade item that has a grade max of
// 50. The grade_grade will have a rawgrademax of 100 regardless.
$gradeitem = new grade_item();
$gradeitem->itemname = 'grade item one';
$gradeitem->itemtype = 'manual';
$gradeitem->courseid = $course2->id;
$gradeitem->idnumber = 'gi1';
$gradeitem->grademax = 25;
$gradeitem->insert();
// Calculated grade item for course 2.
$calculatedgradeitem = new grade_item();
$calculatedgradeitem->itemname = 'calculated grade';
$calculatedgradeitem->itemtype = 'manual';
$calculatedgradeitem->courseid = $course2->id;
$calculatedgradeitem->calculation = '=##gi' . $gradeitem->id . '##*2';
$calculatedgradeitem->grademax = 50;
$calculatedgradeitem->insert();
// Assigning a grade for the user.
$grade = $gradeitem->get_grade($user->id, true);
$grade->finalgrade = 10;
$grade->update();
// Setting all of the grade_grade items.
grade_regrade_final_grades($course2->id);
// Different manual grade item for course 3. We are creating a course with a calculated grade item that has a grade max of
// 50. The grade_grade will have a rawgrademax of 100 regardless.
$gradeitem = new grade_item();
$gradeitem->itemname = 'grade item one';
$gradeitem->itemtype = 'manual';
$gradeitem->courseid = $course3->id;
$gradeitem->idnumber = 'gi1';
$gradeitem->grademax = 25;
$gradeitem->insert();
//.........这里部分代码省略.........