本文整理汇总了PHP中grade_item::fix_duplicate_sortorder方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::fix_duplicate_sortorder方法的具体用法?PHP grade_item::fix_duplicate_sortorder怎么用?PHP grade_item::fix_duplicate_sortorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_item
的用法示例。
在下文中一共展示了grade_item::fix_duplicate_sortorder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: after_restore
public function after_restore()
{
// Fix grade item's sortorder after restore, as it might have duplicates.
$courseid = $this->get_task()->get_courseid();
grade_item::fix_duplicate_sortorder($courseid);
}
示例2: sub_test_grade_item_fix_sortorder
/**
* Test the {@link grade_item::fix_duplicate_sortorder() function with
* faked duplicate sortorder data.
*/
public function sub_test_grade_item_fix_sortorder()
{
global $DB;
$this->resetAfterTest(true);
// Each set is used for filling the db with fake data and will be representing the result of query:
// "SELECT sortorder from {grade_items} WHERE courseid=? ORDER BY id".
$testsets = array(array(1, 2, 3), array(5, 6, 7), array(7, 6, 1, 3, 2, 5), array(1, 2, 2, 3, 3, 4, 5), array(1, 1), array(3, 3), array(3, 3, 7, 5, 6, 6, 9, 10, 8, 3), array(7, 7, 3), array(3, 4, 5, 3, 5, 4, 7, 1));
$origsequence = array();
// Generate the data and remember the initial sequence or items.
foreach ($testsets as $testset) {
$course = $this->getDataGenerator()->create_course();
foreach ($testset as $sortorder) {
$this->insert_fake_grade_item_sortorder($course->id, $sortorder);
}
$DB->get_records('grade_items');
$origsequence[$course->id] = $DB->get_fieldset_sql("SELECT id FROM {grade_items} " . "WHERE courseid = ? ORDER BY sortorder, id", array($course->id));
}
$duplicatedetectionsql = "SELECT courseid, sortorder\n FROM {grade_items}\n WHERE courseid = :courseid\n GROUP BY courseid, sortorder\n HAVING COUNT(id) > 1";
// Do the work.
foreach ($origsequence as $courseid => $ignore) {
grade_item::fix_duplicate_sortorder($courseid);
// Verify that no duplicates are left in the database.
$dupes = $DB->record_exists_sql($duplicatedetectionsql, array('courseid' => $courseid));
$this->assertFalse($dupes);
}
// Verify that sequences are exactly the same as they were before upgrade script.
$idx = 0;
foreach ($origsequence as $courseid => $sequence) {
if (count($testsets[$idx]) == count(array_unique($testsets[$idx]))) {
// If there were no duplicates for this course verify that sortorders are not modified.
$newsortorders = $DB->get_fieldset_sql("SELECT sortorder from {grade_items} WHERE courseid=? ORDER BY id", array($courseid));
$this->assertEquals($testsets[$idx], $newsortorders);
}
$newsequence = $DB->get_fieldset_sql("SELECT id FROM {grade_items} " . "WHERE courseid = ? ORDER BY sortorder, id", array($courseid));
$this->assertEquals($sequence, $newsequence, "Sequences do not match for test set {$idx} : " . join(',', $testsets[$idx]));
$idx++;
}
}