本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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;
}