You are here

function location_map_link_dk_rejseplanen in Location 7.3

Same name and namespace in other branches
  1. 5.3 supported/location.dk.inc \location_map_link_dk_rejseplanen()
  2. 6.3 supported/location.dk.inc \location_map_link_dk_rejseplanen()
  3. 7.5 supported/location.dk.inc \location_map_link_dk_rejseplanen()
  4. 7.4 supported/location.dk.inc \location_map_link_dk_rejseplanen()

Generate a link to Rejseplanen.

Rejseplanen is a route planner for Danish public transportation.

Parameters

array $location: The location array we're trying to generate a link for.

Return value

string|null Map link if generation successful, otherwise null.

File

supported/location.dk.inc, line 81
Denmark.

Code

function location_map_link_dk_rejseplanen($location = array()) {
  $keys = array();

  // Iterate over all the possible details, and if set, add them to an array.
  foreach (array(
    'street',
    'postal_code',
    'city',
  ) as $name) {
    if (isset($location[$name]) && !empty($location[$name])) {
      $keys[$name] = $location[$name];
    }
  }

  // Merge postal code and city if both are available, since they,
  // shouldn't be comma separated in Danish addresses.
  if (isset($keys['postal_code']) && isset($keys['city'])) {
    $keys['postal_code'] = $keys['postal_code'] . ' ' . $keys['city'];
    unset($keys['city']);
  }

  // If any of the key values were available, generate a URL.
  if (!empty($keys)) {
    return url('http://www.rejseplanen.dk/bin/query.exe/mn?Z=' . implode(', ', $keys) . '&ZADR=1');
  }
  else {
    return NULL;
  }
}