當前位置: 首頁>>代碼示例>>PHP>>正文


PHP reorder_sections函數代碼示例

本文整理匯總了PHP中reorder_sections函數的典型用法代碼示例。如果您正苦於以下問題:PHP reorder_sections函數的具體用法?PHP reorder_sections怎麽用?PHP reorder_sections使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了reorder_sections函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testReorderSections

 function testReorderSections()
 {
     $sections = array(20 => 0, 21 => 1, 22 => 2, 23 => 3, 24 => 4, 25 => 5);
     $this->assertFalse(reorder_sections(1, 3, 4));
     $newsections = reorder_sections($sections, 2, 4);
     $newsections_flipped = array_flip($newsections);
     $this->assertEqual(20, reset($newsections_flipped));
     $this->assertEqual(21, next($newsections_flipped));
     $this->assertEqual(23, next($newsections_flipped));
     $this->assertEqual(24, next($newsections_flipped));
     $this->assertEqual(22, next($newsections_flipped));
     $this->assertEqual(25, next($newsections_flipped));
     $newsections = reorder_sections($sections, 4, 0);
     $newsections_flipped = array_flip($newsections);
     $this->assertEqual(20, reset($newsections_flipped));
     $this->assertEqual(24, next($newsections_flipped));
     $this->assertEqual(21, next($newsections_flipped));
     $this->assertEqual(22, next($newsections_flipped));
     $this->assertEqual(23, next($newsections_flipped));
     $this->assertEqual(25, next($newsections_flipped));
     $newsections = reorder_sections($sections, 1, 5);
     $newsections_flipped = array_flip($newsections);
     $this->assertEqual(20, reset($newsections_flipped));
     $this->assertEqual(22, next($newsections_flipped));
     $this->assertEqual(23, next($newsections_flipped));
     $this->assertEqual(24, next($newsections_flipped));
     $this->assertEqual(25, next($newsections_flipped));
     $this->assertEqual(21, next($newsections_flipped));
 }
開發者ID:JackCanada,項目名稱:moodle-hacks,代碼行數:29,代碼來源:testcourselib.php

示例2: move_section_to

/**
 * Moves a section within a course, from a position to another.
 * Be very careful: $section and $destination refer to section number,
 * not id!.
 *
 * @param object $course
 * @param int $section Section number (not id!!!)
 * @param int $destination
 * @return boolean Result
 */
function move_section_to($course, $section, $destination)
{
    /// Moves a whole course section up and down within the course
    global $USER, $DB;
    if (!$destination && $destination != 0) {
        return true;
    }
    if ($destination > $course->numsections) {
        return false;
    }
    // Get all sections for this course and re-order them (2 of them should now share the same section number)
    if (!($sections = $DB->get_records_menu('course_sections', array('course' => $course->id), 'section ASC, id ASC', 'id, section'))) {
        return false;
    }
    $movedsections = reorder_sections($sections, $section, $destination);
    // Update all sections. Do this in 2 steps to avoid breaking database
    // uniqueness constraint
    $transaction = $DB->start_delegated_transaction();
    foreach ($movedsections as $id => $position) {
        if ($sections[$id] !== $position) {
            $DB->set_field('course_sections', 'section', -$position, array('id' => $id));
        }
    }
    foreach ($movedsections as $id => $position) {
        if ($sections[$id] !== $position) {
            $DB->set_field('course_sections', 'section', $position, array('id' => $id));
        }
    }
    // Adjust destination to reflect the actual section
    $moveup = false;
    if ($section > $destination) {
        $destination++;
        $moveup = true;
    }
    // If we move the highlighted section itself, then just highlight the destination.
    // Adjust the higlighted section location if we move something over it either direction.
    if ($section == $course->marker) {
        course_set_marker($course, $destination);
    } elseif ($moveup && $section > $course->marker && $course->marker >= $destination) {
        course_set_marker($course, $course->marker + 1);
    } elseif (!$moveup && $section < $course->marker && $course->marker <= $destination) {
        course_set_marker($course, $course->marker - 1);
    }
    // if the focus is on the section that is being moved, then move the focus along
    if (course_get_display($course->id) == $section) {
        course_set_display($course->id, $destination);
    }
    $transaction->allow_commit();
    return true;
}
開發者ID:numbas,項目名稱:moodle,代碼行數:60,代碼來源:lib.php

示例3: move_section_to

/**
 * Moves a section within a course, from a position to another.
 * Be very careful: $section and $destination refer to section number,
 * not id!.
 *
 * @param object $course
 * @param int $section Section number (not id!!!)
 * @param int $destination
 * @return boolean Result
 */
function move_section_to($course, $section, $destination)
{
    /// Moves a whole course section up and down within the course
    global $USER, $DB;
    if (!$destination && $destination != 0) {
        return true;
    }
    // compartibility with course formats using field 'numsections'
    $courseformatoptions = course_get_format($course)->get_format_options();
    if (array_key_exists('numsections', $courseformatoptions) && $destination > $courseformatoptions['numsections'] || $destination < 1) {
        return false;
    }
    // Get all sections for this course and re-order them (2 of them should now share the same section number)
    if (!($sections = $DB->get_records_menu('course_sections', array('course' => $course->id), 'section ASC, id ASC', 'id, section'))) {
        return false;
    }
    $movedsections = reorder_sections($sections, $section, $destination);
    // Update all sections. Do this in 2 steps to avoid breaking database
    // uniqueness constraint
    $transaction = $DB->start_delegated_transaction();
    foreach ($movedsections as $id => $position) {
        if ($sections[$id] !== $position) {
            $DB->set_field('course_sections', 'section', -$position, array('id' => $id));
        }
    }
    foreach ($movedsections as $id => $position) {
        if ($sections[$id] !== $position) {
            $DB->set_field('course_sections', 'section', $position, array('id' => $id));
        }
    }
    // If we move the highlighted section itself, then just highlight the destination.
    // Adjust the higlighted section location if we move something over it either direction.
    if ($section == $course->marker) {
        course_set_marker($course->id, $destination);
    } elseif ($section > $course->marker && $course->marker >= $destination) {
        course_set_marker($course->id, $course->marker + 1);
    } elseif ($section < $course->marker && $course->marker <= $destination) {
        course_set_marker($course->id, $course->marker - 1);
    }
    $transaction->allow_commit();
    rebuild_course_cache($course->id, true);
    return true;
}
開發者ID:EmmanuelYupit,項目名稱:educursos,代碼行數:53,代碼來源:lib.php

示例4: move_section_to

/**
 * Moves a section within a course, from a position to another.
 * Be very careful: $section and $destination refer to section number,
 * not id!.
 *
 * @param object $course
 * @param int $section Section number (not id!!!)
 * @param int $destination
 * @return boolean Result
 */
function move_section_to($course, $section, $destination)
{
    /// Moves a whole course section up and down within the course
    global $USER;
    if (!$destination && $destination != 0) {
        return true;
    }
    if ($destination > $course->numsections) {
        return false;
    }
    // Get all sections for this course and re-order them (2 of them should now share the same section number)
    if (!($sections = get_records_menu('course_sections', 'course', $course->id, 'section ASC, id ASC', 'id, section'))) {
        return false;
    }
    $sections = reorder_sections($sections, $section, $destination);
    // Update all sections
    foreach ($sections as $id => $position) {
        set_field('course_sections', 'section', $position, 'id', $id);
    }
    // if the focus is on the section that is being moved, then move the focus along
    if (isset($USER->display[$course->id]) and $USER->display[$course->id] == $section) {
        course_set_display($course->id, $destination);
    }
    return true;
}
開發者ID:arshanam,項目名稱:Moodle-ITScholars-LMS,代碼行數:35,代碼來源:lib.php


注:本文中的reorder_sections函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。