MDL-31830 course: renamed functions for consistency

* course_move_by_one => course_change_sortorder_by_one
* course_move_after_course => course_move_after_course
* helper::action_course_move_after_course  => helper::action_course_change_sortorder_after_course
* helper::action_course_moveup 		   => helper::action_course_change_sortorder_up_one
* helper::action_course_movedown 	   => helper::action_course_change_sortorder_down_one
* helper::action_course_moveup_by_record   => helper::action_course_change_sortorder_up_one_by_record
* helper::action_course_movedown_by_record => helper::action_course_change_sortorder_down_one_by_record
* helper::action_category_movedown         => helper::action_category_change_sortorder_down_one
* helper::action_category_movedown_by_id   => helper::action_category_change_sortorder_down_one_by_id
* helper::action_category_moveup 	   => helper::action_category_change_sortorder_up_one
* helper::action_category_moveup_by_id     => helper::action_category_change_sortorder_up_one_by_id
* coursecat::move_by_one 	           => coursecat::change_sortorder_by_one
This commit is contained in:
Sam Hemelryk 2013-10-01 09:40:29 +13:00
parent 67e1f26874
commit 5aff38e4d8
7 changed files with 73 additions and 71 deletions

View File

@ -44,11 +44,11 @@ echo $OUTPUT->header();
switch ($action) {
case 'movecourseup' :
$courseid = required_param('courseid', PARAM_INT);
$outcome->outcome = \core_course\management\helper::action_course_moveup_by_record($courseid);
$outcome->outcome = \core_course\management\helper::action_course_change_sortorder_up_one_by_record($courseid);
break;
case 'movecoursedown' :
$courseid = required_param('courseid', PARAM_INT);
$outcome->outcome = \core_course\management\helper::action_course_movedown_by_record($courseid);
$outcome->outcome = \core_course\management\helper::action_course_change_sortorder_down_one_by_record($courseid);
break;
case 'movecourseintocategory':
$courseid = required_param('courseid', PARAM_INT);
@ -58,7 +58,8 @@ switch ($action) {
case 'movecourseafter' :
$courseid = required_param('courseid', PARAM_INT);
$moveaftercourseid = required_param('moveafter', PARAM_INT);
$outcome->outcome = \core_course\management\helper::action_course_move_after_course($courseid, $moveaftercourseid);
$outcome->outcome = \core_course\management\helper::action_course_change_sortorder_after_course(
$courseid, $moveaftercourseid);
break;
case 'hidecourse' :
$courseid = required_param('courseid', PARAM_INT);
@ -70,11 +71,11 @@ switch ($action) {
break;
case 'movecategoryup' :
$categoryid = required_param('categoryid', PARAM_INT);
$outcome->outcome = \core_course\management\helper::action_category_moveup_by_id($categoryid);
$outcome->outcome = \core_course\management\helper::action_category_change_sortorder_up_one_by_id($categoryid);
break;
case 'movecategorydown' :
$categoryid = required_param('categoryid', PARAM_INT);
$outcome->outcome = \core_course\management\helper::action_category_movedown_by_id($categoryid);
$outcome->outcome = \core_course\management\helper::action_category_change_sortorder_down_one_by_id($categoryid);
break;
case 'hidecategory' :
$categoryid = required_param('categoryid', PARAM_INT);

View File

@ -310,83 +310,83 @@ class helper {
}
/**
* Moves the provided course up one place in the sort order given a \course_in_list object.
* Resorts the courses within a category moving the given course up by one.
*
* @param \course_in_list $course
* @param \coursecat $category
* @return bool
* @throws \moodle_exception
*/
public static function action_course_moveup(\course_in_list $course, \coursecat $category) {
public static function action_course_change_sortorder_up_one(\course_in_list $course, \coursecat $category) {
if (!$category->can_resort_courses()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort');
}
return course_move_by_one($course, true);
return \course_change_sortorder_by_one($course, true);
}
/**
* Moves the provided course down one place in the sort order given a \course_in_list object.
* 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_movedown(\course_in_list $course, \coursecat $category) {
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_move_by_one($course, false);
return \course_change_sortorder_by_one($course, false);
}
/**
* Moves the provided course up one place in the sort order given an id or database record.
* Resorts the courses within a category moving the given course up by one.
*
* @global \moodle_database $DB
* @param int|\stdClass $courserecordorid
* @return bool
*/
public static function action_course_moveup_by_record($courserecordorid) {
public static function action_course_change_sortorder_up_one_by_record($courserecordorid) {
if (is_int($courserecordorid)) {
$courserecordorid = get_course($courserecordorid);
}
$course = new \course_in_list($courserecordorid);
$category = \coursecat::get($course->category);
return self::action_course_moveup($course, $category);
return self::action_course_change_sortorder_up_one($course, $category);
}
/**
* Moves the provided course down one place in the sort order given an id or database record.
* Resorts the courses within a category moving the given course down by one.
*
* @global \moodle_database $DB
* @param int|\stdClass $courserecordorid
* @return bool
*/
public static function action_course_movedown_by_record($courserecordorid) {
public static function action_course_change_sortorder_down_one_by_record($courserecordorid) {
if (is_int($courserecordorid)) {
$courserecordorid = get_course($courserecordorid);
}
$course = new \course_in_list($courserecordorid);
$category = \coursecat::get($course->category);
return self::action_course_movedown($course, $category);
return self::action_course_change_sortorder_down_one($course, $category);
}
/**
* Changes the sort order so that the first course appears after the second course.
*
* @param int|stdClass $courserecordorid
* @param int|\stdClass $courserecordorid
* @param int $moveaftercourseid
* @return bool
* @throws \moodle_exception
*/
public static function action_course_move_after_course($courserecordorid, $moveaftercourseid) {
public static function action_course_change_sortorder_after_course($courserecordorid, $moveaftercourseid) {
$course = \get_course($courserecordorid);
$category = \coursecat::get($course->category);
if (!$category->can_resort_courses()) {
$url = '/course/management.php?categoryid='.$course->category;
throw new \moodle_exception('nopermissions', 'error', $url, \get_string('resortcourses', 'moodle'));
}
return \course_move_after_course($course, $moveaftercourseid);
return \course_change_sortorder_after_course($course, $moveaftercourseid);
}
/**
@ -448,53 +448,53 @@ class helper {
}
/**
* Moves a category up one spot in the sort order given a \coursecat object.
* Resort a categories subcategories shifting the given category up one.
*
* @param \coursecat $category
* @return bool
* @throws \moodle_exception
*/
public static function action_category_moveup(\coursecat $category) {
public static function action_category_change_sortorder_up_one(\coursecat $category) {
if (!$category->can_change_sortorder()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_change_sortorder');
}
return $category->move_by_one(true);
return $category->change_sortorder_by_one(true);
}
/**
* Moves a category down one spot in the sort order given a \coursecat object.
* Resort a categories subcategories shifting the given category down one.
*
* @param \coursecat $category
* @return bool
* @throws \moodle_exception
*/
public static function action_category_movedown(\coursecat $category) {
public static function action_category_change_sortorder_down_one(\coursecat $category) {
if (!$category->can_change_sortorder()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_change_sortorder');
}
return $category->move_by_one(false);
return $category->change_sortorder_by_one(false);
}
/**
* Moves a category up one spot in the sort order given a category id.
* Resort a categories subcategories shifting the given category up one.
*
* @param int $categoryid
* @return bool
*/
public static function action_category_moveup_by_id($categoryid) {
public static function action_category_change_sortorder_up_one_by_id($categoryid) {
$category = \coursecat::get($categoryid);
return self::action_category_moveup($category);
return self::action_category_change_sortorder_up_one($category);
}
/**
* Moves a category down one spot in the sort order given a category id.
* Resort a categories subcategories shifting the given category down one.
*
* @param int $categoryid
* @return bool
*/
public static function action_category_movedown_by_id($categoryid) {
public static function action_category_change_sortorder_down_one_by_id($categoryid) {
$category = \coursecat::get($categoryid);
return self::action_category_movedown($category);
return self::action_category_change_sortorder_down_one($category);
}
/**
@ -589,7 +589,7 @@ class helper {
* @param \coursecat $newcategory The category we are moving courses into.
* @param array $courseids The ID's of the courses we want to move.
* @return bool True on success.
* @throws moodle_exception
* @throws \moodle_exception
*/
public static function action_category_move_courses_into(\coursecat $oldcategory, \coursecat $newcategory, array $courseids) {
global $DB;
@ -665,9 +665,10 @@ class helper {
* This function works much the same way as action_category_move_courses_into however it allows courses from multiple
* categories to be moved into a single category.
*
* @param int|coursecat $categoryid The category to move them into.
* @param int|\coursecat $categoryorid The category to move them into.
* @param array|int $courseids An array of course id's or optionally just a single course id.
* @return bool True on success or false on failure.
* @throws \moodle_exception
*/
public static function move_courses_into_category($categoryorid, $courseids = array()) {
global $DB;

View File

@ -3382,13 +3382,13 @@ function course_change_visibility($courseid, $show = true) {
}
/**
* Moves the course up or down one in respect to sort order.
* Changes the course sortorder by one, moving it up or down one in respect to sort order.
*
* @param stdClass|course_in_list $course
* @param bool $up If set to true the course will be moved up one. Otherwise down one.
* @return bool
*/
function course_move_by_one($course, $up) {
function course_change_sortorder_by_one($course, $up) {
global $DB;
$params = array($course->sortorder, $course->category);
if ($up) {
@ -3413,13 +3413,13 @@ function course_move_by_one($course, $up) {
}
/**
* Move one course after another.
* Changes the sort order of courses in a category so that the first course appears after the second.
*
* @param int|stdClass $courseorid The course to move.
* @param int $moveaftercourseid The course to move after or 0 if you want it to be the first course in the category.
* @param int|stdClass $courseorid The course to focus on.
* @param int $moveaftercourseid The course to shifter after or 0 if you want it to be the first course in the category.
* @return bool
*/
function course_move_after_course($courseorid, $moveaftercourseid) {
function course_change_sortorder_after_course($courseorid, $moveaftercourseid) {
global $DB;
if (!is_object($courseorid)) {

View File

@ -146,13 +146,13 @@ if ($action !== false && confirm_sesskey()) {
// They must have specified a category and a course.
required_param('categoryid', PARAM_INT);
required_param('courseid', PARAM_INT);
$redirectback = \core_course\management\helper::action_course_moveup($course, $category);
$redirectback = \core_course\management\helper::action_course_change_sortorder_up_one($course, $category);
break;
case 'movecoursedown' :
// They must have specified a category and a course.
required_param('categoryid', PARAM_INT);
required_param('courseid', PARAM_INT);
$redirectback = \core_course\management\helper::action_course_movedown($course, $category);
$redirectback = \core_course\management\helper::action_course_change_sortorder_down_one($course, $category);
break;
case 'showcategory' :
// They must have specified a category.
@ -167,12 +167,12 @@ if ($action !== false && confirm_sesskey()) {
case 'movecategoryup' :
// They must have specified a category.
required_param('categoryid', PARAM_INT);
$redirectback = \core_course\management\helper::action_category_moveup($category);
$redirectback = \core_course\management\helper::action_category_change_sortorder_up_one($category);
break;
case 'movecategorydown' :
// They must have specified a category.
required_param('categoryid', PARAM_INT);
$redirectback = \core_course\management\helper::action_category_movedown($category);
$redirectback = \core_course\management\helper::action_category_change_sortorder_down_one($category);
break;
case 'deletecategory':
// They must have specified a category.

View File

@ -2212,7 +2212,7 @@ class core_course_courselib_testcase extends advanced_testcase {
/**
* Test course move after course.
*/
public function test_course_move_after_course() {
public function test_course_change_sortorder_after_course() {
global $DB;
$this->resetAfterTest(true);
@ -2234,7 +2234,7 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
// Test moving down.
$this->assertTrue(course_move_after_course($course1->id, $course3->id));
$this->assertTrue(course_change_sortorder_after_course($course1->id, $course3->id));
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course2->id, $course3->id, $course1->id), array_keys($courses));
@ -2242,7 +2242,7 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
// Test moving up.
$this->assertTrue(course_move_after_course($course1->id, $course2->id));
$this->assertTrue(course_change_sortorder_after_course($course1->id, $course2->id));
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course2->id, $course1->id, $course3->id), array_keys($courses));
@ -2250,7 +2250,7 @@ class core_course_courselib_testcase extends advanced_testcase {
$this->assertEquals(array_keys($dbcourses), array_keys($courses));
// Test moving to the top.
$this->assertTrue(course_move_after_course($course1->id, 0));
$this->assertTrue(course_change_sortorder_after_course($course1->id, 0));
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
$this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
@ -2287,7 +2287,7 @@ class core_course_courselib_testcase extends advanced_testcase {
/**
* Tests moving the course up and down by one.
*/
public function test_course_move_by_one() {
public function test_course_change_sortorder_by_one() {
global $DB;
$this->resetAfterTest(true);
@ -2306,7 +2306,7 @@ class core_course_courselib_testcase extends advanced_testcase {
// Test moving down.
$course1 = get_course($course1->id);
$this->assertTrue(course_move_by_one($course1, false));
$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));
@ -2315,7 +2315,7 @@ class core_course_courselib_testcase extends advanced_testcase {
// Test moving up.
$course1 = get_course($course1->id);
$this->assertTrue(course_move_by_one($course1, true));
$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));
@ -2324,7 +2324,7 @@ class core_course_courselib_testcase extends advanced_testcase {
// Test moving the top course up one.
$course1 = get_course($course1->id);
$this->assertFalse(course_move_by_one($course1, true));
$this->assertFalse(course_change_sortorder_by_one($course1, true));
// Check nothing changed.
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
@ -2334,7 +2334,7 @@ class core_course_courselib_testcase extends advanced_testcase {
// Test moving the bottom course up down.
$course3 = get_course($course3->id);
$this->assertFalse(course_move_by_one($course3, false));
$this->assertFalse(course_change_sortorder_by_one($course3, false));
// Check nothing changed.
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);

View File

@ -545,7 +545,7 @@ class core_course_management_helper_test extends advanced_testcase {
);
// Move the top category down one.
$this->assertTrue(\core_course\management\helper::action_category_movedown($cat1));
$this->assertTrue(\core_course\management\helper::action_category_change_sortorder_down_one($cat1));
// Reload out objects.
$cat1 = coursecat::get($cat1->id);
$cat2 = coursecat::get($cat2->id);
@ -561,7 +561,7 @@ class core_course_management_helper_test extends advanced_testcase {
);
// Move the bottom category up one.
$this->assertTrue(\core_course\management\helper::action_category_moveup($cat3));
$this->assertTrue(\core_course\management\helper::action_category_change_sortorder_up_one($cat3));
// Reload out objects.
$cat1 = coursecat::get($cat1->id);
$cat2 = coursecat::get($cat2->id);
@ -577,14 +577,14 @@ class core_course_management_helper_test extends advanced_testcase {
);
// Move the top category down one.
$this->assertTrue(\core_course\management\helper::action_category_movedown_by_id($cat2->id));
$this->assertTrue(\core_course\management\helper::action_category_change_sortorder_down_one_by_id($cat2->id));
$this->assertEquals(
array('Three', 'Two', 'One'),
array_keys($DB->get_records('course_categories', array('parent' => $parent->id), 'sortorder', 'name'))
);
// Move the top category down one.
$this->assertTrue(\core_course\management\helper::action_category_moveup_by_id($cat1->id));
$this->assertTrue(\core_course\management\helper::action_category_change_sortorder_up_one_by_id($cat1->id));
$this->assertEquals(
array('Three', 'One', 'Two'),
array_keys($DB->get_records('course_categories', array('parent' => $parent->id), 'sortorder', 'name'))
@ -601,7 +601,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Verify sorting.
// Test moving the top category up one. Nothing should change but it should return false.
$this->assertFalse(\core_course\management\helper::action_category_moveup($cat3));
$this->assertFalse(\core_course\management\helper::action_category_change_sortorder_up_one($cat3));
// Reload out objects.
$cat1 = coursecat::get($cat1->id);
$cat2 = coursecat::get($cat2->id);
@ -617,7 +617,7 @@ class core_course_management_helper_test extends advanced_testcase {
);
// Test moving the bottom category down one. Nothing should change but it should return false.
$this->assertFalse(\core_course\management\helper::action_category_movedown($cat2));
$this->assertFalse(\core_course\management\helper::action_category_change_sortorder_down_one($cat2));
// Reload out objects.
$cat1 = coursecat::get($cat1->id);
$cat2 = coursecat::get($cat2->id);
@ -635,7 +635,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Prevent moving on the parent.
course_capability_assignment::prevent(self::CATEGORY_MANAGE, $roleid, $parent->get_context()->id);
try {
\core_course\management\helper::action_category_moveup($cat1);
\core_course\management\helper::action_category_change_sortorder_up_one($cat1);
} catch (moodle_exception $exception) {
// Check everything is still where it should be.
$this->assertEquals(
@ -644,7 +644,7 @@ class core_course_management_helper_test extends advanced_testcase {
);
}
try {
\core_course\management\helper::action_category_movedown($cat3);
\core_course\management\helper::action_category_change_sortorder_down_one($cat3);
} catch (moodle_exception $exception) {
// Check everything is still where it should be.
$this->assertEquals(
@ -1009,7 +1009,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Move a course down.
$this->assertTrue(
\core_course\management\helper::action_course_movedown(new course_in_list(get_course($course1->id)), $category)
\core_course\management\helper::action_course_change_sortorder_down_one(new course_in_list(get_course($course1->id)), $category)
);
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
@ -1019,7 +1019,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Move a course up.
$this->assertTrue(
\core_course\management\helper::action_course_moveup(new course_in_list(get_course($course3->id)), $category)
\core_course\management\helper::action_course_change_sortorder_up_one(new course_in_list(get_course($course3->id)), $category)
);
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
@ -1029,7 +1029,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Move a course down by record.
$this->assertTrue(
\core_course\management\helper::action_course_movedown_by_record(get_course($course2->id), $category)
\core_course\management\helper::action_course_change_sortorder_down_one_by_record(get_course($course2->id), $category)
);
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
@ -1039,7 +1039,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Move a course up by record.
$this->assertTrue(
\core_course\management\helper::action_course_moveup_by_record(get_course($course2->id), $category)
\core_course\management\helper::action_course_change_sortorder_up_one_by_record(get_course($course2->id), $category)
);
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
@ -1049,7 +1049,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Try move the bottom course down. This should return false and nothing changes.
$this->assertFalse(
\core_course\management\helper::action_course_movedown(new course_in_list(get_course($course1->id)), $category)
\core_course\management\helper::action_course_change_sortorder_down_one(new course_in_list(get_course($course1->id)), $category)
);
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
@ -1059,7 +1059,7 @@ class core_course_management_helper_test extends advanced_testcase {
// Try move the top course up. This should return false and nothing changes.
$this->assertFalse(
\core_course\management\helper::action_course_moveup(new course_in_list(get_course($course2->id)), $category)
\core_course\management\helper::action_course_change_sortorder_up_one(new course_in_list(get_course($course2->id)), $category)
);
$courses = $category->get_courses();
$this->assertInternalType('array', $courses);
@ -1073,7 +1073,7 @@ class core_course_management_helper_test extends advanced_testcase {
$category = coursecat::get($category->id);
try {
\core_course\management\helper::action_course_movedown(new course_in_list(get_course($course2->id)), $category);
\core_course\management\helper::action_course_change_sortorder_down_one(new course_in_list(get_course($course2->id)), $category);
$this->fail('Course moved without having the required permissions.');
} catch (moodle_exception $exception) {
// Check nothing has changed.

View File

@ -2420,13 +2420,13 @@ class coursecat implements renderable, cacheable_object, IteratorAggregate {
}
/**
* Moves a category up or down one spot in the sort order.
* Changes the sort order of this categories parent shifting this category up or down one.
*
* @global \moodle_database $DB
* @param bool $up If set to true the category is moved up one spot, else its moved down.
* @param bool $up If set to true the category is shifted up one spot, else its moved down.
* @return bool True on success, false otherwise.
*/
public function move_by_one($up) {
public function change_sortorder_by_one($up) {
global $DB;
$params = array($this->sortorder, $this->parent);
if ($up) {