本文整理汇总了PHP中course_change_sortorder_by_one函数的典型用法代码示例。如果您正苦于以下问题:PHP course_change_sortorder_by_one函数的具体用法?PHP course_change_sortorder_by_one怎么用?PHP course_change_sortorder_by_one使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了course_change_sortorder_by_one函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_course_change_sortorder_by_one
/**
* Tests moving the course up and down by one.
*/
public function test_course_change_sortorder_by_one()
{
global $DB;
$this->resetAfterTest(true);
$generator = $this->getDataGenerator();
$category = $generator->create_category();
$course3 = $generator->create_course(array('category' => $category->id));
$course2 = $generator->create_course(array('category' => $category->id));
$course1 = $generator->create_course(array('category' => $category->id));
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
$dbcourses = $DB->get_records('course', array('category' => $category->id), 'sortorder', 'id');
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
// Test moving down.
$course1 = get_course($course1->id);
$this->assertTrue(course_change_sortorder_by_one($course1, false));
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course2->id, $course1->id, $course3->id), array_keys($courses));
$dbcourses = $DB->get_records('course', array('category' => $category->id), 'sortorder', 'id');
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
// Test moving up.
$course1 = get_course($course1->id);
$this->assertTrue(course_change_sortorder_by_one($course1, true));
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
$dbcourses = $DB->get_records('course', array('category' => $category->id), 'sortorder', 'id');
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
// Test moving the top course up one.
$course1 = get_course($course1->id);
$this->assertFalse(course_change_sortorder_by_one($course1, true));
// Check nothing changed.
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
$dbcourses = $DB->get_records('course', array('category' => $category->id), 'sortorder', 'id');
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
// Test moving the bottom course up down.
$course3 = get_course($course3->id);
$this->assertFalse(course_change_sortorder_by_one($course3, false));
// Check nothing changed.
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
$dbcourses = $DB->get_records('course', array('category' => $category->id), 'sortorder', 'id');
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
}
示例2: action_course_change_sortorder_down_one
/**
* Resorts the courses within a category moving the given course down by one.
*
* @param \course_in_list $course
* @param \coursecat $category
* @return bool
* @throws \moodle_exception
*/
public static function action_course_change_sortorder_down_one(\course_in_list $course, \coursecat $category)
{
if (!$category->can_resort_courses()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort');
}
return \course_change_sortorder_by_one($course, false);
}