當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。