mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-43739 block_course_overview: allow resorting of big number of courses
previously an exception was thrown if the user preference exceeds 1333 chars
This commit is contained in:
parent
457f818026
commit
1302bb08f6
@ -59,10 +59,34 @@ function block_course_overview_update_mynumber($number) {
|
||||
/**
|
||||
* Sets user course sorting preference in course_overview block
|
||||
*
|
||||
* @param array $sortorder sort order of course
|
||||
* @param array $sortorder list of course ids
|
||||
*/
|
||||
function block_course_overview_update_myorder($sortorder) {
|
||||
set_user_preference('course_overview_course_order', serialize($sortorder));
|
||||
$value = implode(',', $sortorder);
|
||||
if (core_text::strlen($value) > 1333) {
|
||||
// The value won't fit into the user preference. Remove courses in the end of the list (mostly likely user won't even notice).
|
||||
$value = preg_replace('/,[\d]*$/', '', core_text::substr($value, 0, 1334));
|
||||
}
|
||||
set_user_preference('course_overview_course_sortorder', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets user course sorting preference in course_overview block
|
||||
*
|
||||
* @return array list of course ids
|
||||
*/
|
||||
function block_course_overview_get_myorder() {
|
||||
if ($value = get_user_preferences('course_overview_course_sortorder')) {
|
||||
return explode(',', $value);
|
||||
}
|
||||
// If preference was not found, look in the old location and convert if found.
|
||||
$order = array();
|
||||
if ($value = get_user_preferences('course_overview_course_order')) {
|
||||
$order = unserialize($value);
|
||||
block_course_overview_update_myorder($order);
|
||||
unset_user_preference('course_overview_course_order');
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,10 +191,7 @@ function block_course_overview_get_sorted_courses($showallcourses = false) {
|
||||
$courses[$remoteid] = $val;
|
||||
}
|
||||
|
||||
$order = array();
|
||||
if (!is_null($usersortorder = get_user_preferences('course_overview_course_order'))) {
|
||||
$order = unserialize($usersortorder);
|
||||
}
|
||||
$order = block_course_overview_get_myorder();
|
||||
|
||||
$sortedcourses = array();
|
||||
$counter = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user