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


PHP assign::update_grade方法代码示例

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


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

示例1: test_grade_grade_min_max

 public function test_grade_grade_min_max()
 {
     global $CFG;
     $initialminmaxtouse = $CFG->grade_minmaxtouse;
     $this->setAdminUser();
     $course = $this->getDataGenerator()->create_course();
     $user = $this->getDataGenerator()->create_user();
     $assignrecord = $this->getDataGenerator()->create_module('assign', array('course' => $course, 'grade' => 100));
     $cm = get_coursemodule_from_instance('assign', $assignrecord->id);
     $assigncontext = context_module::instance($cm->id);
     $assign = new assign($assigncontext, $cm, $course);
     // Fetch the assignment item.
     $giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $assignrecord->id, 'courseid' => $course->id, 'itemnumber' => 0);
     $gi = grade_item::fetch($giparams);
     $this->assertEquals(0, $gi->grademin);
     $this->assertEquals(100, $gi->grademax);
     // Give a grade to the student.
     $usergrade = $assign->get_user_grade($user->id, true);
     $usergrade->grade = 10;
     $assign->update_grade($usergrade);
     // Check the grade stored in gradebook.
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(10, $gg->rawgrade);
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     // Change the min/max grade of the item.
     $gi->grademax = 50;
     $gi->grademin = 2;
     $gi->update();
     // Fetch the updated item.
     $gi = grade_item::fetch($giparams);
     // Now check the grade grade min/max with system setting.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_ITEM;
     grade_set_setting($course->id, 'minmaxtouse', null);
     // Ensure no course setting.
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(2, $gg->get_grade_min());
     $this->assertEquals(50, $gg->get_grade_max());
     // Now with other system setting.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_GRADE;
     grade_set_setting($course->id, 'minmaxtouse', null);
     // Ensure no course setting, and reset static cache.
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     // Now with overriden setting in course.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_ITEM;
     grade_set_setting($course->id, 'minmaxtouse', GRADE_MIN_MAX_FROM_GRADE_GRADE);
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(0, $gg->get_grade_min());
     $this->assertEquals(100, $gg->get_grade_max());
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_GRADE;
     grade_set_setting($course->id, 'minmaxtouse', GRADE_MIN_MAX_FROM_GRADE_ITEM);
     $gg = grade_grade::fetch(array('userid' => $user->id, 'itemid' => $gi->id));
     $this->assertEquals(2, $gg->get_grade_min());
     $this->assertEquals(50, $gg->get_grade_max());
     $CFG->grade_minmaxtouse = $initialminmaxtouse;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:58,代码来源:grade_grade_test.php

示例2: test_upgrade_minmaxgrade

 /**
  * Test upgrade minmaxgrade step.
  */
 public function test_upgrade_minmaxgrade()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/gradelib.php';
     $initialminmax = $CFG->grade_minmaxtouse;
     $this->resetAfterTest();
     $c1 = $this->getDataGenerator()->create_course();
     $c2 = $this->getDataGenerator()->create_course();
     $c3 = $this->getDataGenerator()->create_course();
     $u1 = $this->getDataGenerator()->create_user();
     $a1 = $this->getDataGenerator()->create_module('assign', array('course' => $c1, 'grade' => 100));
     $a2 = $this->getDataGenerator()->create_module('assign', array('course' => $c2, 'grade' => 100));
     $a3 = $this->getDataGenerator()->create_module('assign', array('course' => $c3, 'grade' => 100));
     $cm1 = get_coursemodule_from_instance('assign', $a1->id);
     $ctx1 = context_module::instance($cm1->id);
     $assign1 = new assign($ctx1, $cm1, $c1);
     $cm2 = get_coursemodule_from_instance('assign', $a2->id);
     $ctx2 = context_module::instance($cm2->id);
     $assign2 = new assign($ctx2, $cm2, $c2);
     $cm3 = get_coursemodule_from_instance('assign', $a3->id);
     $ctx3 = context_module::instance($cm3->id);
     $assign3 = new assign($ctx3, $cm3, $c3);
     // Give a grade to the student.
     $ug = $assign1->get_user_grade($u1->id, true);
     $ug->grade = 10;
     $assign1->update_grade($ug);
     $ug = $assign2->get_user_grade($u1->id, true);
     $ug->grade = 20;
     $assign2->update_grade($ug);
     $ug = $assign3->get_user_grade($u1->id, true);
     $ug->grade = 30;
     $assign3->update_grade($ug);
     // Run the upgrade.
     upgrade_minmaxgrade();
     // Nothing has happened.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c1->id)));
     $this->assertSame(false, grade_get_setting($c1->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c1->id)));
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c2->id)));
     $this->assertSame(false, grade_get_setting($c2->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c2->id)));
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Create inconsistency in c1 and c2.
     $giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a1->id, 'courseid' => $c1->id, 'itemnumber' => 0);
     $gi = grade_item::fetch($giparams);
     $gi->grademin = 5;
     $gi->update();
     $giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a2->id, 'courseid' => $c2->id, 'itemnumber' => 0);
     $gi = grade_item::fetch($giparams);
     $gi->grademax = 50;
     $gi->update();
     // C1 and C2 should be updated, but the course setting should not be set.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_GRADE;
     // Run the upgrade.
     upgrade_minmaxgrade();
     // C1 and C2 were partially updated.
     $this->assertTrue($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c1->id)));
     $this->assertSame(false, grade_get_setting($c1->id, 'minmaxtouse', false, true));
     $this->assertTrue($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c1->id)));
     $this->assertTrue($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c2->id)));
     $this->assertSame(false, grade_get_setting($c2->id, 'minmaxtouse', false, true));
     $this->assertTrue($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c2->id)));
     // Nothing has happened for C3.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Course setting should not be set on a course that has the setting already.
     $CFG->grade_minmaxtouse = GRADE_MIN_MAX_FROM_GRADE_ITEM;
     grade_set_setting($c1->id, 'minmaxtouse', -1);
     // Sets different value than constant to check that it remained the same.
     // Run the upgrade.
     upgrade_minmaxgrade();
     // C2 was updated.
     $this->assertSame((string) GRADE_MIN_MAX_FROM_GRADE_GRADE, grade_get_setting($c2->id, 'minmaxtouse', false, true));
     // Nothing has happened for C1.
     $this->assertSame('-1', grade_get_setting($c1->id, 'minmaxtouse', false, true));
     // Nothing has happened for C3.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Final check, this time we'll unset the default config.
     unset($CFG->grade_minmaxtouse);
     grade_set_setting($c1->id, 'minmaxtouse', null);
     // Run the upgrade.
     upgrade_minmaxgrade();
     // C1 was updated.
     $this->assertSame((string) GRADE_MIN_MAX_FROM_GRADE_GRADE, grade_get_setting($c1->id, 'minmaxtouse', false, true));
     // Nothing has happened for C3.
     $this->assertFalse($DB->record_exists('config', array('name' => 'show_min_max_grades_changed_' . $c3->id)));
     $this->assertSame(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     $this->assertFalse($DB->record_exists('grade_items', array('needsupdate' => 1, 'courseid' => $c3->id)));
     // Restore value.
     $CFG->grade_minmaxtouse = $initialminmax;
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:99,代码来源:upgradelib_test.php

示例3: test_upgrade_mark_grading_configuration

 /**
  * Test upgrade minmaxgrade step.
  */
 public function test_upgrade_mark_grading_configuration()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/gradelib.php';
     $initialminmax = $CFG->grade_minmaxtouse;
     $this->resetAfterTest();
     $c1 = $this->getDataGenerator()->create_course();
     $c2 = $this->getDataGenerator()->create_course();
     $c3 = $this->getDataGenerator()->create_course();
     $u1 = $this->getDataGenerator()->create_user();
     $a1 = $this->getDataGenerator()->create_module('assign', array('course' => $c1, 'grade' => 100));
     $a2 = $this->getDataGenerator()->create_module('assign', array('course' => $c2, 'grade' => 100));
     $a3 = $this->getDataGenerator()->create_module('assign', array('course' => $c3, 'grade' => 100));
     $cm1 = get_coursemodule_from_instance('assign', $a1->id);
     $ctx1 = context_module::instance($cm1->id);
     $assign1 = new assign($ctx1, $cm1, $c1);
     $cm2 = get_coursemodule_from_instance('assign', $a2->id);
     $ctx2 = context_module::instance($cm2->id);
     $assign2 = new assign($ctx2, $cm2, $c2);
     $cm3 = get_coursemodule_from_instance('assign', $a3->id);
     $ctx3 = context_module::instance($cm3->id);
     $assign3 = new assign($ctx3, $cm3, $c3);
     // Give a grade to the student.
     $ug = $assign1->get_user_grade($u1->id, true);
     $ug->grade = 10;
     $assign1->update_grade($ug);
     $ug = $assign2->get_user_grade($u1->id, true);
     $ug->grade = 20;
     $assign2->update_grade($ug);
     $ug = $assign3->get_user_grade($u1->id, true);
     $ug->grade = 30;
     $assign3->update_grade($ug);
     // Create inconsistency in c1 and c2.
     $giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a1->id, 'courseid' => $c1->id, 'itemnumber' => 0);
     $gi = grade_item::fetch($giparams);
     $gi->grademin = 5;
     $gi->update();
     $giparams = array('itemtype' => 'mod', 'itemmodule' => 'assign', 'iteminstance' => $a2->id, 'courseid' => $c2->id, 'itemnumber' => 0);
     $gi = grade_item::fetch($giparams);
     $gi->grademax = 50;
     $gi->update();
     // Run the upgrade.
     upgrade_mark_grading_configuration();
     // Nothing has happened.
     $this->assertEquals(GRADE_MIN_MAX_FROM_GRADE_ITEM, grade_get_setting($c1->id, 'minmaxtouse', false, true));
     $this->assertEquals(GRADE_MIN_MAX_FROM_GRADE_ITEM, grade_get_setting($c2->id, 'minmaxtouse', false, true));
     $this->assertEquals(false, grade_get_setting($c3->id, 'minmaxtouse', false, true));
     // Restore value.
     $CFG->grade_minmaxtouse = $initialminmax;
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:53,代码来源:upgradelib_test.php


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