/symphony/content/content.ajaxreorder.php

https://github.com/builders/sym-bootstrap · PHP · 63 lines · 41 code · 14 blank · 8 comment · 12 complexity · a8a9f116258a50b9d3226b5437de4d42 MD5 · raw file

  1. <?php
  2. /**
  3. * @package content
  4. */
  5. /**
  6. * The AjaxReorder page is used for reordering objects in the Symphony
  7. * backend through Javascript.
  8. */
  9. Class contentAjaxReorder extends AjaxPage{
  10. const kREORDER_PAGES = 0;
  11. const kREORDER_SECTIONS = 1;
  12. const kREORDER_EXTENSION = 2;
  13. const kREORDER_UNKNOWN = 3;
  14. public function view(){
  15. $destination = self::kREORDER_UNKNOWN;
  16. if($this->_context[0] == 'blueprints' && $this->_context[1] == 'pages') $destination = self::kREORDER_PAGES;
  17. elseif($this->_context[0] == 'blueprints' && $this->_context[1] == 'sections') $destination = self::kREORDER_SECTIONS;
  18. elseif($this->_context[0] == 'extensions') $destination = self::kREORDER_EXTENSION;
  19. $items = $_REQUEST['items'];
  20. if(!is_array($items) || empty($items)) return;
  21. switch($destination){
  22. case self::kREORDER_PAGES:
  23. foreach($items as $id => $position) {
  24. if(!Symphony::Database()->query("UPDATE `tbl_pages` SET `sortorder` = '$position' WHERE `id` = '$id' LIMIT 1")){
  25. $this->_status = self::STATUS_ERROR;
  26. $this->_Result->setValue(__('A database error occurred while attempting to reorder.'));
  27. break;
  28. }
  29. }
  30. break;
  31. case self::kREORDER_SECTIONS:
  32. foreach($items as $id => $position) {
  33. if(!Symphony::Database()->query("UPDATE `tbl_sections` SET `sortorder` = '$position' WHERE `id` = '$id' LIMIT 1")){
  34. $this->_status = self::STATUS_ERROR;
  35. $this->_Result->setValue(__('A database error occurred while attempting to reorder.'));
  36. break;
  37. }
  38. }
  39. break;
  40. case self::kREORDER_EXTENSION:
  41. ## TODO
  42. break;
  43. case self::kREORDER_UNKNOWN:
  44. default:
  45. $this->_status = self::STATUS_BAD;
  46. break;
  47. }
  48. }
  49. }