reorder.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. $folder_guid = (int) get_input("folder_guid", 0);
  3. $parent_guid = (int) get_input("parent_guid", 0);
  4. $order = get_input("order");
  5. if (!empty($folder_guid) && (!empty($parent_guid) || $parent_guid == 0)) {
  6. // if parent guid, check if it is a folder
  7. if (!empty($parent_guid)) {
  8. if (!($parent = get_entity($parent_guid)) || !elgg_instanceof($parent, "object", FILE_TOOLS_SUBTYPE)) {
  9. unset($parent_guid);
  10. }
  11. }
  12. // get folder from folder_guid and check if it is a folder
  13. if (!is_null($parent_guid) && ($folder_guid != $parent_guid) && ($folder = get_entity($folder_guid))) {
  14. if (elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE) && $folder->canEditMetadata("parent_guid")) {
  15. // set new parent_guid
  16. $folder->parent_guid = $parent_guid;
  17. $folder->save();
  18. }
  19. }
  20. // reorder
  21. if (!empty($order) && !is_array($order)) {
  22. $order = array($order);
  23. }
  24. if (!empty($order) && !is_null($parent_guid)) {
  25. foreach ($order as $index => $order_guid) {
  26. if ($folder = get_entity($order_guid)) {
  27. if (elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE) && $folder->canEditMetadata("order")) {
  28. if ($folder->parent_guid == $parent_guid) {
  29. $folder->order = $index;
  30. $folder->save();
  31. }
  32. }
  33. }
  34. }
  35. }
  36. system_message(elgg_echo("file_tools:action:folder:reorder:success"));
  37. } else {
  38. register_error(elgg_echo("InvalidParameterException:MissingParameter"));
  39. }
  40. forward(REFERER);