draggableviews_handler_native.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Native handler plugin.
  5. */
  6. $plugin = array(
  7. 'label' => 'Native',
  8. 'handler' => array(
  9. 'class' => 'draggableviews_handler_native',
  10. ),
  11. );
  12. class draggableviews_handler_native extends draggableviews_handler {
  13. public function get($field, $index) {
  14. $row = $field->view->result[$index];
  15. return (isset($row->draggableviews_structure_weight)) ? $row->draggableviews_structure_weight : 0;
  16. }
  17. function set($form_state) {
  18. $fv = $form_state['values'];
  19. $view = $form_state['build_info']['args'][0];
  20. $view_name = $view->name;
  21. $view_display = $view->current_display;
  22. // View arguments.
  23. $arguments = $view->args;
  24. if (isset($view->exposed_raw_input)) {
  25. $arguments += $view->exposed_raw_input;
  26. ksort($arguments);
  27. // Redirect view to the same page with exposed filters set.
  28. $form_state['redirect'] = array(current_path(), array('query' => $view->exposed_raw_input));
  29. }
  30. // Give other modules a chance to alter saved arguments.
  31. drupal_alter('draggableviews_handler_native_arguments', $arguments, $view, $fv['draggableviews']);
  32. $args_string = json_encode($arguments);
  33. // Save records to our custom table.
  34. foreach ($fv['draggableviews'] as $item) {
  35. // Delete previous order record.
  36. db_delete('draggableviews_structure')
  37. ->condition('view_name', $view_name)
  38. ->condition('view_display', $view_display)
  39. ->condition('args', $args_string)
  40. ->condition('entity_id', $item['id'])
  41. ->execute();
  42. // Create new order record.
  43. $record = array(
  44. 'view_name' => $view_name,
  45. 'view_display' => $view_display,
  46. 'args' => $args_string,
  47. 'entity_id' => $item['id'],
  48. 'weight' => $item['weight'],
  49. );
  50. drupal_write_record('draggableviews_structure', $record);
  51. }
  52. }
  53. }