draggableviews_join_handler.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Native handler join handler.
  5. */
  6. /**
  7. * Join handler for extra join conditions.
  8. */
  9. class draggableviews_join_handler extends views_join {
  10. /**
  11. * Build the SQL for the join this object represents.
  12. */
  13. function build_join($select_query, $table, $view_query) {
  14. if (empty($this->definition['table formula'])) {
  15. $right_table = $this->table;
  16. }
  17. else {
  18. $right_table = $this->definition['table formula'];
  19. }
  20. if ($this->left_table) {
  21. $left = $view_query->get_table_info($this->left_table);
  22. $left_field = "$left[alias].$this->left_field";
  23. }
  24. else {
  25. // This can be used if left_field is a formula or something. It should be used only *very* rarely.
  26. $left_field = $this->left_field;
  27. }
  28. $condition = "$left_field = $table[alias].$this->field";
  29. // Check whether setting view is set.
  30. $arguments = array();
  31. $weight_key = draggable_views_get_draggable_sort($view_query->view);
  32. if (!empty($view_query->view->sort[$weight_key]->options['draggableviews_setting_view'])) {
  33. $condition .= " AND $table[alias].view_name = :view_name";
  34. $condition .= " AND $table[alias].view_display = :view_display";
  35. // If it is setting view, set current view name and display name.
  36. if ($view_query->view->sort[$weight_key]->options['draggableviews_setting_view'] == 'self') {
  37. $arguments[':view_name'] = $view_query->view->name;
  38. $arguments[':view_display'] = $view_query->view->current_display;
  39. }
  40. else {
  41. list($setting_view_name, $setting_view_display) = explode(':', $view_query->view->sort[$weight_key]->options['draggableviews_setting_view']);
  42. $arguments[':view_name'] = $setting_view_name;
  43. $arguments[':view_display'] = $setting_view_display;
  44. }
  45. // Arguments passed to view (including exposed filters).
  46. $view_arguments = $view_query->view->args;
  47. if (isset($view_query->view->exposed_raw_input)) {
  48. $view_arguments += $view_query->view->exposed_raw_input;
  49. ksort($view_arguments);
  50. }
  51. // Alter arguments according to sort criteria settings.
  52. if ($view_query->view->sort[$weight_key]->options['draggableviews_setting_arguments'] == 'none') {
  53. $view_arguments = array();
  54. }
  55. // If PHP arguments processing is set.
  56. if ($view_query->view->sort[$weight_key]->options['draggableviews_setting_arguments'] == 'php') {
  57. $view_arguments = draggableviews_eval_return($view_query->view->sort[$weight_key]->options['draggableviews_setting_arguments_php'], $view_arguments);
  58. }
  59. $condition .= " AND $table[alias].args = :view_arguments";
  60. $arguments[':view_arguments'] = json_encode($view_arguments);
  61. }
  62. $select_query->addJoin($this->type, $right_table, $table['alias'], $condition, $arguments);
  63. }
  64. }