You are here

function openlayers_save_preset in Openlayers 6

OpenLayers Save Preset

Given an array of data, save the preset

Parameters

$preset: Array of data for preset

Return value

Boolean of whether successful

Related topics

1 call to openlayers_save_preset()
openlayers_presets_ui_presets_manage_add_submit in modules/openlayers_presets_ui/includes/openlayers_presets_ui.ui.inc
Form submit for preset add form

File

./openlayers.module, line 327
Main OpenLayers API File

Code

function openlayers_save_preset($preset = array()) {
  $successful = FALSE;

  // Check for name
  if (empty($preset['preset_name'])) {
    return $successful;
  }

  // Check the map array for errors
  $map_processed = openlayers_render_map($preset['preset_data'], FALSE);
  if (isset($map_processed['errors']) && count($map_processed['errors'])) {
    foreach ($map_processed['errors'] as $error) {
      drupal_set_message($error, 'error');
    }
    return $successful;
  }

  // Serialize
  $preset['preset_data'] = is_array($preset['preset_data']) ? serialize($preset['preset_data']) : '';

  // Check for existing preset
  $query = "SELECT preset_id FROM {openlayers_map_presets} WHERE preset_name = '%s'";
  $preset_id = db_result(db_query($query, $preset['preset_name']));

  // Check id
  if (!empty($preset_id)) {
    $preset['preset_id'] = $preset_id;
    $successful = drupal_write_record('openlayers_map_presets', $preset, 'preset_id');
  }
  else {
    $successful = drupal_write_record('openlayers_map_presets', $preset);
  }
  return $successful;
}