geofieldProximityCurrentUser.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @file
  4. * Contains geofieldProximityCurrentUser.
  5. */
  6. class geofieldProximityCurrentUser extends geofieldProximityBase implements geofieldProximityPluginInterface {
  7. public function option_definition(&$options, $views_plugin) {
  8. $options['geofield_proximity_current_user_field'] = array(
  9. 'default' => '',
  10. );
  11. $options['geofield_proximity_current_user_delta'] = array(
  12. 'default' => 0,
  13. );
  14. }
  15. public function options_form(&$form, &$form_state, $views_plugin) {
  16. $geofields = _geofield_get_geofield_fields();
  17. $field_options = array();
  18. foreach ($geofields as $key => $field) {
  19. $field_options[$key] = $key;
  20. }
  21. $form['geofield_proximity_current_user_field'] = array(
  22. '#type' => 'select',
  23. '#title' => t('Source Field'),
  24. '#default_value' => $views_plugin->options['geofield_proximity_current_user_field'],
  25. '#options' => $field_options,
  26. '#dependency' => array(
  27. 'edit-options-source' => array('current_user'),
  28. ),
  29. );
  30. }
  31. public function getSourceValue($views_plugin) {
  32. global $user;
  33. $user_object = user_load($user->uid);
  34. $geofield_name = $views_plugin->options['geofield_proximity_current_user_field'];
  35. $delta = $views_plugin->options['geofield_proximity_current_user_delta'];
  36. if (!empty($geofield_name)) {
  37. $field_data = field_get_items('user', $user_object, $geofield_name);
  38. if ($field_data != FALSE) {
  39. return array(
  40. 'latitude' => $field_data[$delta]['lat'],
  41. 'longitude' => $field_data[$delta]['lon'],
  42. );
  43. }
  44. }
  45. return FALSE;
  46. }
  47. }