本文整理汇总了PHP中upgrade_calculated_grade_items函数的典型用法代码示例。如果您正苦于以下问题:PHP upgrade_calculated_grade_items函数的具体用法?PHP upgrade_calculated_grade_items怎么用?PHP upgrade_calculated_grade_items使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了upgrade_calculated_grade_items函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_upgrade_calculated_grade_items_regrade
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: xmldb_main_upgrade
//.........这里部分代码省略.........
}
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2015060400.02) {
// Sites that were upgrading from 2.7 and older will ignore this step.
if (empty($CFG->upgrade_minmaxgradestepignored)) {
upgrade_minmaxgrade();
// Flags this upgrade step as already run to prevent it from running multiple times.
set_config('upgrade_minmaxgradestepignored', 1);
}
upgrade_main_savepoint(true, 2015060400.02);
}
if ($oldversion < 2015061900.0) {
// MDL-49257. Changed the algorithm of calculating automatic weights of extra credit items.
// Before the change, in case when grade category (in "Natural" agg. method) had items with
// overridden weights, the automatic weight of extra credit items was illogical.
// In order to prevent grades changes after the upgrade we need to freeze gradebook calculation
// for the affected courses.
// This script in included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_extracreditweightsstepignored)) {
upgrade_extra_credit_weightoverride();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_extracreditweightsstepignored', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015061900.0);
}
if ($oldversion < 2015062500.01) {
// MDL-48239. Changed calculated grade items so that the maximum and minimum grade can be set.
// If the changes are accepted and a regrade is done on the gradebook then some grades may change significantly.
// This is here to freeze the gradebook in affected courses.
// This script is included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_calculatedgradeitemsignored)) {
upgrade_calculated_grade_items();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_calculatedgradeitemsignored', 1);
// This config value is never used again.
unset_config('upgrade_calculatedgradeitemsonlyregrade');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015062500.01);
}
if ($oldversion < 2015081300.01) {
// Define field importtype to be added to grade_import_values.
$table = new xmldb_table('grade_import_values');
$field = new xmldb_field('importonlyfeedback', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'importer');
// Conditionally launch add field importtype.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015081300.01);
}
if ($oldversion < 2015082400.0) {
// Define table webdav_locks to be dropped.
$table = new xmldb_table('webdav_locks');
// Conditionally launch drop table for webdav_locks.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015082400.0);
}
if ($oldversion < 2015090200.0) {
$table = new xmldb_table('message');
// Define the deleted fields to be added to the message tables.
示例3: xmldb_main_upgrade
//.........这里部分代码省略.........
}
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2015060400.02) {
// Sites that were upgrading from 2.7 and older will ignore this step.
if (empty($CFG->upgrade_minmaxgradestepignored)) {
upgrade_minmaxgrade();
// Flags this upgrade step as already run to prevent it from running multiple times.
set_config('upgrade_minmaxgradestepignored', 1);
}
upgrade_main_savepoint(true, 2015060400.02);
}
if ($oldversion < 2015061900.0) {
// MDL-49257. Changed the algorithm of calculating automatic weights of extra credit items.
// Before the change, in case when grade category (in "Natural" agg. method) had items with
// overridden weights, the automatic weight of extra credit items was illogical.
// In order to prevent grades changes after the upgrade we need to freeze gradebook calculation
// for the affected courses.
// This script in included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_extracreditweightsstepignored)) {
upgrade_extra_credit_weightoverride();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_extracreditweightsstepignored', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015061900.0);
}
if ($oldversion < 2015062500.01) {
// MDL-48239. Changed calculated grade items so that the maximum and minimum grade can be set.
// If the changes are accepted and a regrade is done on the gradebook then some grades may change significantly.
// This is here to freeze the gradebook in affected courses.
// This script is included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_calculatedgradeitemsignored)) {
upgrade_calculated_grade_items();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_calculatedgradeitemsignored', 1);
// This config value is never used again.
unset_config('upgrade_calculatedgradeitemsonlyregrade');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015062500.01);
}
if ($oldversion < 2015081300.01) {
// Define field importtype to be added to grade_import_values.
$table = new xmldb_table('grade_import_values');
$field = new xmldb_field('importonlyfeedback', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'importer');
// Conditionally launch add field importtype.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015081300.01);
}
if ($oldversion < 2015082400.0) {
// Define table webdav_locks to be dropped.
$table = new xmldb_table('webdav_locks');
// Conditionally launch drop table for webdav_locks.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015082400.0);
}
if ($oldversion < 2015090200.0) {
$table = new xmldb_table('message');
// Define the deleted fields to be added to the message tables.
示例4: gradebook_calculation_freeze
/**
* Freeze gradebook calculation if needed.
*
* This is similar to various upgrade scripts that check if the freeze is needed.
*/
protected function gradebook_calculation_freeze()
{
global $CFG;
$gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->get_courseid());
preg_match('/(\\d{8})/', $this->get_task()->get_info()->moodle_release, $matches);
$backupbuild = (int) $matches[1];
// The function floatval will return a float even if there is text mixed with the release number.
$backuprelease = floatval($this->get_task()->get_info()->backup_release);
// Extra credits need adjustments only for backups made between 2.8 release (20141110) and the fix release (20150619).
if (!$gradebookcalculationsfreeze && $backupbuild >= 20141110 && $backupbuild < 20150619) {
require_once $CFG->libdir . '/db/upgradelib.php';
upgrade_extra_credit_weightoverride($this->get_courseid());
}
// Calculated grade items need recalculating for backups made between 2.8 release (20141110) and the fix release (20150627).
if (!$gradebookcalculationsfreeze && $backupbuild >= 20141110 && $backupbuild < 20150627) {
require_once $CFG->libdir . '/db/upgradelib.php';
upgrade_calculated_grade_items($this->get_courseid());
}
// Courses from before 3.1 (20160518) may have a letter boundary problem and should be checked for this issue.
// Backups from before and including 2.9 could have a build number that is greater than 20160518 and should
// be checked for this problem.
if (!$gradebookcalculationsfreeze && ($backupbuild < 20160518 || $backuprelease <= 2.9)) {
require_once $CFG->libdir . '/db/upgradelib.php';
upgrade_course_letter_boundary($this->get_courseid());
}
}
示例5: gradebook_calculation_freeze
/**
* Freeze gradebook calculation if needed.
*
* This is similar to various upgrade scripts that check if the freeze is needed.
*/
protected function gradebook_calculation_freeze()
{
global $CFG;
$gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->get_courseid());
preg_match('/(\\d{8})/', $this->get_task()->get_info()->moodle_release, $matches);
$backupbuild = (int) $matches[1];
// Extra credits need adjustments only for backups made between 2.8 release (20141110) and the fix release (20150619).
if (!$gradebookcalculationsfreeze && $backupbuild >= 20141110 && $backupbuild < 20150619) {
require_once $CFG->libdir . '/db/upgradelib.php';
upgrade_extra_credit_weightoverride($this->get_courseid());
}
// Calculated grade items need recalculating for backups made between 2.8 release (20141110) and the fix release (20150627).
if (!$gradebookcalculationsfreeze && $backupbuild >= 20141110 && $backupbuild < 20150627) {
require_once $CFG->libdir . '/db/upgradelib.php';
upgrade_calculated_grade_items($this->get_courseid());
}
}
示例6: 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();
//.........这里部分代码省略.........
示例7: xmldb_main_upgrade
//.........这里部分代码省略.........
}
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2015060400.02) {
// Sites that were upgrading from 2.7 and older will ignore this step.
if (empty($CFG->upgrade_minmaxgradestepignored)) {
upgrade_minmaxgrade();
// Flags this upgrade step as already run to prevent it from running multiple times.
set_config('upgrade_minmaxgradestepignored', 1);
}
upgrade_main_savepoint(true, 2015060400.02);
}
if ($oldversion < 2015061900.0) {
// MDL-49257. Changed the algorithm of calculating automatic weights of extra credit items.
// Before the change, in case when grade category (in "Natural" agg. method) had items with
// overridden weights, the automatic weight of extra credit items was illogical.
// In order to prevent grades changes after the upgrade we need to freeze gradebook calculation
// for the affected courses.
// This script in included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_extracreditweightsstepignored)) {
upgrade_extra_credit_weightoverride();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_extracreditweightsstepignored', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015061900.0);
}
if ($oldversion < 2015062500.01) {
// MDL-48239. Changed calculated grade items so that the maximum and minimum grade can be set.
// If the changes are accepted and a regrade is done on the gradebook then some grades may change significantly.
// This is here to freeze the gradebook in affected courses.
// This script is included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_calculatedgradeitemsignored)) {
upgrade_calculated_grade_items();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_calculatedgradeitemsignored', 1);
// This config value is never used again.
unset_config('upgrade_calculatedgradeitemsonlyregrade');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015062500.01);
}
if ($oldversion < 2015081300.01) {
// Define field importtype to be added to grade_import_values.
$table = new xmldb_table('grade_import_values');
$field = new xmldb_field('importonlyfeedback', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'importer');
// Conditionally launch add field importtype.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015081300.01);
}
if ($oldversion < 2015082400.0) {
// Define table webdav_locks to be dropped.
$table = new xmldb_table('webdav_locks');
// Conditionally launch drop table for webdav_locks.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015082400.0);
}
if ($oldversion < 2015090200.0) {
$table = new xmldb_table('message');
// Define the deleted fields to be added to the message tables.