You are here

function location_calc_difference in Location 7.3

Same name and namespace in other branches
  1. 5.3 location.module \location_calc_difference()
  2. 6.3 location.module \location_calc_difference()
  3. 7.5 location.module \location_calc_difference()
  4. 7.4 location.module \location_calc_difference()

Computes the differences between two locations.

Parameters

array $oldloc: Original location.

array $newloc: New location.

array|bool &$changes: Array of changes. The keys are field names, and the values are boolean FALSE and TRUE.

Return value

bool Whether or not there were any changes.

2 calls to location_calc_difference()
location_is_empty in ./location.module
Checks if a location is empty, and sets up an array of filled fields.
location_save in ./location.module
Save a location.

File

./location.module, line 1625
Location module main routines. An implementation of a universal API for location manipulation. Provides functions for postal_code proximity searching, deep-linking into online mapping services. Currently, some options are configured through an…

Code

function location_calc_difference($oldloc, $newloc, &$changes) {
  location_strip($oldloc);
  location_strip($newloc);
  $location_changed = FALSE;
  foreach ($newloc as $k => $v) {
    if (!isset($oldloc[$k])) {

      // Field missing from old location, automatic save.
      $changes[$k] = TRUE;
      $location_changed = TRUE;
      continue;
    }
    elseif ($oldloc[$k] === $v) {
      $changes[$k] = FALSE;

      // Exact match, no change.
      continue;
    }

    // It wasn't equal, but perhaps it was equivilent?
    $results = location_invoke_locationapi($newloc, 'isunchanged', $k, $oldloc[$k]);

    // First, assume changed.
    $waschanged = TRUE;
    foreach ($results as $r) {
      if ($r) {
        $waschanged = FALSE;
        $changes[$k] = FALSE;
      }
    }
    if ($waschanged) {

      // Nobody okayed this difference.
      $changes[$k] = TRUE;
      $location_changed = TRUE;
    }
  }
  if (!$location_changed) {
    return FALSE;
  }
  return TRUE;
}