You are here

function getlocations_fields_insert_record in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_fields/getlocations_fields.module \getlocations_fields_insert_record()

Create a location

Parameters

array $location: The new location

array $relations: Relationship information

2 calls to getlocations_fields_insert_record()
getlocations_fields_save_locations in modules/getlocations_fields/getlocations_fields.module
getlocations_fields_update_record in modules/getlocations_fields/getlocations_fields.module
Create a location

File

modules/getlocations_fields/getlocations_fields.module, line 2186
getlocations_fields.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_fields_insert_record($location, $relations) {
  $noaddress = t('Enter an address');
  if (!isset($location['address']) || $location['address'] == $noaddress) {
    $location['address'] = '';
  }
  if (empty($location['latitude']) && empty($location['longitude'])) {
    return FALSE;
  }
  $query = db_insert('getlocations_fields');
  $query
    ->fields(array(
    'name' => getlocations_apoclean($location['name']),
    'street' => getlocations_apoclean($location['street']),
    'additional' => getlocations_apoclean($location['additional']),
    'city' => getlocations_apoclean($location['city']),
    'province' => getlocations_apoclean($location['province']),
    'postal_code' => getlocations_apoclean($location['postal_code']),
    'country' => check_plain($location['country']),
    'address' => getlocations_apoclean($location['address']),
    'latitude' => (double) $location['latitude'],
    'longitude' => (double) $location['longitude'],
    'marker' => $location['marker'] ? $location['marker'] : '',
    'data' => !empty($location['data']) ? serialize($location['data']) : '',
  ));
  $result = $query
    ->execute();

  // $result should contain glid
  // new insert id
  if ($result) {
    $relations['glid'] = $result;
    getlocations_fields_insert_record_relations($relations);
    return $result;
  }
  return FALSE;
}