references_plugin_display.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @file
  4. * Handler for references_plugin_display.
  5. */
  6. class references_plugin_display extends views_plugin_display {
  7. function option_definition() {
  8. $options = parent::option_definition();
  9. // Force the style plugin to 'references_style' and the row plugin to
  10. // 'fields'.
  11. $options['style_plugin']['default'] = 'references_style';
  12. $options['defaults']['default']['style_plugin'] = FALSE;
  13. $options['defaults']['default']['style_options'] = FALSE;
  14. $options['row_plugin']['default'] = 'references_fields';
  15. $options['defaults']['default']['row_plugin'] = FALSE;
  16. $options['defaults']['default']['row_options'] = FALSE;
  17. // Set the display title to an empty string (not used in this display type).
  18. $options['title']['default'] = '';
  19. $options['defaults']['default']['title'] = FALSE;
  20. return $options;
  21. }
  22. function get_style_type() {
  23. return 'references';
  24. }
  25. function execute() {
  26. return $this->view->render($this->display->id);
  27. }
  28. function render() {
  29. if (!empty($this->view->result) || !empty($this->view->style_plugin->definition['even empty'])) {
  30. return $this->view->style_plugin->render($this->view->result);
  31. }
  32. return '';
  33. }
  34. function uses_exposed() {
  35. return FALSE;
  36. }
  37. function query() {
  38. $options = $this->get_option('references_options');
  39. // Play nice with View UI 'preview' : if the view is not executed through
  40. // _*_reference_potential_references_views(), don't alter the query.
  41. if (empty($options)) {
  42. return;
  43. }
  44. // Make sure the id field is included in the results, and save its alias
  45. // so that references_plugin_style can retrieve it.
  46. $this->id_field_alias = $this->view->query->add_field($this->view->base_table, $this->view->base_field);
  47. // Restrict on the incoming string, or incoming ids.
  48. if ($options['string'] !== '') {
  49. switch ($options['match']) {
  50. case 'equals':
  51. $operator = '=';
  52. $value = $options['string'];
  53. break;
  54. case 'starts_with':
  55. $operator = 'LIKE';
  56. $value = db_like($options['string']) . '%';
  57. break;
  58. case 'contains':
  59. default:
  60. $operator = 'LIKE';
  61. $value = '%' . db_like($options['string']) . '%';
  62. break;
  63. }
  64. $table_alias = $this->view->query->ensure_table($this->view->base_table);
  65. $this->view->query->add_where(NULL, $table_alias . '.' . $options['title_field'], $value, $operator);
  66. }
  67. elseif ($options['ids']) {
  68. $table_alias = $this->view->query->ensure_table($this->view->base_table);
  69. $this->view->query->add_where(NULL, $table_alias . '.' . $this->view->base_field, $options['ids'], 'IN');
  70. }
  71. }
  72. }