geofieldProximityOtherGeofield.inc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * @file
  4. * Contains geofieldProximityOtherGeofield.
  5. */
  6. class geofieldProximityOtherGeofield extends geofieldProximityBase implements geofieldProximityPluginInterface {
  7. public function option_definition(&$options, $views_plugin) {
  8. $options['geofield_proximity_other_geofield'] = array(
  9. 'default' => '',
  10. );
  11. }
  12. public function options_form(&$form, &$form_state, $views_plugin) {
  13. $handlers = $views_plugin->view->display_handler->get_handlers('field');
  14. $other_geofield_options = array(
  15. '' => '- None -',
  16. );
  17. foreach ($handlers as $handle) {
  18. if (!empty($handle->field_info['type']) && $handle->field_info['type'] == 'geofield') {
  19. $other_geofield_options[$handle->options['id']] = (!empty($handle->options['label'])) ? $handle->options['label'] : $handle->options['id'];
  20. }
  21. }
  22. $form['geofield_proximity_other_geofield'] = array(
  23. '#type' => 'select',
  24. '#title' => t('Other Geofield'),
  25. '#description' => t('List of other geofields attached to this view.'),
  26. '#default_value' => $views_plugin->options['geofield_proximity_other_geofield'],
  27. '#options' => $other_geofield_options,
  28. '#dependency' => array(
  29. 'edit-options-source' => array('other_geofield'),
  30. ),
  31. );
  32. }
  33. public function options_validate(&$form, &$form_state, $views_plugin) {
  34. if ($form_state['values']['options']['geofield_proximity_other_geofield'] == '') {
  35. form_set_error('options][geofield_proximity_other_geofield', t('Please select a geofield.'));
  36. }
  37. }
  38. public function getSourceValue($views_plugin) {
  39. if (!empty($views_plugin->options['geofield_proximity_other_geofield'])) {
  40. $other_geofield = $views_plugin->view->display_handler->get_handler('field', $views_plugin->options['geofield_proximity_other_geofield']);
  41. $views_plugin->query->add_field($other_geofield->table, $other_geofield->definition['field_name'] . '_lat');
  42. $views_plugin->query->add_field($other_geofield->table, $other_geofield->definition['field_name'] . '_lon'); // @TODO: Not sure if we need 2nd add field.
  43. return array(
  44. 'latitude' => $other_geofield->table . '.' . $other_geofield->definition['field_name'] . '_lat',
  45. 'longitude' => $other_geofield->table . '.' . $other_geofield->definition['field_name'] . '_lon',
  46. );
  47. }
  48. return FALSE;
  49. }
  50. }