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


PHP grade_item::fix_duplicate_sortorder方法代码示例

本文整理汇总了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);
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:6,代码来源:restore_stepslib.php

示例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++;
     }
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:42,代码来源:grade_item_test.php


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