function _media_gallery_reorder in Media Gallery 7.2
Same name and namespace in other branches
- 7 media_gallery.pages.inc \_media_gallery_reorder()
Helper function to reorder a list when given a reordered subset of the list.
Parameters
array $list: The list in its original order, as a numeric array.
array $ordered_subset: The part of the list that is to be reordered, as a numeric array.
Return value
array The list in its new order.
1 call to _media_gallery_reorder()
- media_gallery_reorder_collection in ./
media_gallery.pages.inc - Reorder a gallery collection.
File
- ./
media_gallery.pages.inc, line 264 - Common pages for the Media Gallery module.
Code
function _media_gallery_reorder($list, $ordered_subset) {
$list_by_id = array_flip($list);
// Determine the current position of each item in the subset that we're
// reordering.
$subset = array();
foreach ($ordered_subset as $position => $id) {
$subset[$list_by_id[$id]] = $id;
}
ksort($subset);
// Place each item of the reordered subset into the list in its new position.
foreach ($subset as $original_position => $id) {
$list[$original_position] = current($ordered_subset);
next($ordered_subset);
}
return $list;
}