当前位置: 首页>>代码示例>>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;未经允许,请勿转载。