geofield.views.inc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * @file
  4. * Hooks for Views integration.
  5. *
  6. * In addition to the usual views hooks, Geofield defines a set of classes that allows
  7. * us to break out the code needed to handle the wide variety of proximity searches
  8. * the module supports. We define api functions here to allow for very basic autoloading.
  9. *
  10. * Our mini-plugin system we're using here is not designed for external (non-geofield) use,
  11. * but as a programming convenience for the maintainers.
  12. */
  13. /**
  14. * Implements hook_field_views_data().
  15. *
  16. * Views integration for geofields.
  17. *
  18. */
  19. function geofield_field_views_data($field) {
  20. $data = field_views_field_default_views_data($field);
  21. $field_name = $field['field_name'];
  22. foreach ($data as $table_name => $table_data) {
  23. if (isset($table_data[$field_name])) {
  24. $group_name = $table_data[$field_name]['group'];
  25. $title = $table_data[$field_name]['title'] . " ($field_name) - proximity";
  26. $data[$table_name]['field_geofield_distance'] = array(
  27. 'group' => $group_name,
  28. 'title' => $title,
  29. 'title short' => $title,
  30. 'help' => $table_data[$field_name]['help'],
  31. 'sort' => array(
  32. 'field' => 'field_geofield_distance',
  33. 'table' => $table_name,
  34. 'handler' => 'geofield_handler_sort',
  35. 'field_name' => $field['field_name'],
  36. 'real_field' => $table_name,
  37. ),
  38. 'field' => array(
  39. 'field' => 'field_geofield_distance',
  40. 'table' => $table_name,
  41. 'handler' => 'geofield_handler_field',
  42. 'field_name' => $field['field_name'],
  43. 'real_field' => $table_name,
  44. 'float' => TRUE,
  45. 'click sortable' => TRUE,
  46. ),
  47. 'filter' => array(
  48. 'field' => 'field_geofield_distance',
  49. 'table' => $table_name,
  50. 'handler' => 'geofield_handler_filter',
  51. 'field_name' => $field['field_name'],
  52. 'real_field' => $table_name,
  53. ),
  54. 'argument' => array(
  55. 'handler' => 'geofield_handler_argument_proximity',
  56. 'field_name' => $field['field_name'],
  57. ),
  58. );
  59. }
  60. }
  61. return $data;
  62. }
  63. /**
  64. * Implements hook proximity_views_handlers().
  65. *
  66. * Returns metainfo about each of the geofield proximity views classes.
  67. */
  68. function geofield_proximity_views_handlers() {
  69. $handlers = array(
  70. 'manual' => array(
  71. 'name' => t('Manually Enter Point'),
  72. 'class' => 'geofieldProximityManual',
  73. 'module' => 'geofield',
  74. 'path' => 'views/proximity_plugins',
  75. ),
  76. 'entity_from_url' => array(
  77. 'name' => t('Entity From URL'),
  78. 'class' => 'geofieldProximityEntityURL',
  79. 'module' => 'geofield',
  80. 'path' => 'views/proximity_plugins',
  81. ),
  82. 'current_user' => array(
  83. 'name' => t('Current User'),
  84. 'class' => 'geofieldProximityCurrentUser',
  85. 'module' => 'geofield',
  86. 'path' => 'views/proximity_plugins',
  87. ),
  88. 'other_geofield' => array(
  89. 'name' => t('Other Geofield'),
  90. 'class' => 'geofieldProximityOtherGeofield',
  91. 'module' => 'geofield',
  92. 'path' => 'views/proximity_plugins',
  93. ),
  94. 'exposed_geofield_filter' => array(
  95. 'name' => t('Exposed Geofield Proximity Filter'),
  96. 'class' => 'geofieldProximityExposedFilter',
  97. 'module' => 'geofield',
  98. 'path' => 'views/proximity_plugins',
  99. ),
  100. 'contextual_geofield_filter' => array(
  101. 'name' => t('Contextual Geofield Proximity Filter'),
  102. 'class' => 'geofieldProximityContextualFilter',
  103. 'module' => 'geofield',
  104. 'path' => 'views/proximity_plugins',
  105. ),
  106. );
  107. if (module_exists('geocoder')) {
  108. $handlers['geocoder'] = array(
  109. 'name' => t('Geocoded Location'),
  110. 'class' => 'geofieldProximityGeocoder',
  111. 'module' => 'geofield',
  112. 'path' => 'views/proximity_plugins',
  113. );
  114. }
  115. return $handlers;
  116. }
  117. /**
  118. * Loads an individual geofield proximity views class.
  119. *
  120. * @return
  121. * An instance of a class defined by $plugin (see keys for geofield_proximity_views_handlers), or FALSE
  122. * if no such class exists.
  123. */
  124. function geofield_proximity_load_plugin($plugin) {
  125. $handlers = module_invoke_all('proximity_views_handlers');
  126. //module_load_include('inc', 'geofield', 'views/proximity_plugins/geofieldProximityManual');
  127. module_load_include('inc', $handlers[$plugin]['module'], $handlers[$plugin]['path'] . '/' . $handlers[$plugin]['class']);
  128. if (class_exists($handlers[$plugin]['class'])) {
  129. return new $handlers[$plugin]['class'];
  130. }
  131. else {
  132. return FALSE;
  133. }
  134. }