You are here

function media_gallery_reorder_gallery in Media Gallery 7.2

Same name and namespace in other branches
  1. 7 media_gallery.pages.inc \media_gallery_reorder_gallery()

Reorder the media items in a gallery.

1 call to media_gallery_reorder_gallery()
media_gallery_ajax_sort in ./media_gallery.pages.inc
AJAX callback for drag-and-drop gallery sorting.

File

./media_gallery.pages.inc, line 238
Common pages for the Media Gallery module.

Code

function media_gallery_reorder_gallery($gallery, $order) {
  $media_field = $gallery->media_gallery_file[LANGUAGE_NONE];
  $offset = 0;
  if (!empty($_POST['page'])) {
    $page = array_pop(explode(',', $_POST['page']));
    $num_per_page = $gallery->media_gallery_columns[LANGUAGE_NONE][0]['value'] * $gallery->media_gallery_rows[LANGUAGE_NONE][0]['value'];
    $offset = $num_per_page * $page;
  }
  foreach ($order as $new_delta => $old_delta) {
    $gallery->media_gallery_file[LANGUAGE_NONE][$new_delta + $offset] = $media_field[$old_delta + $offset];
  }
  node_save($gallery);
  return TRUE;
}