You are here

function openlayers_presets in Openlayers 6

Same name and namespace in other branches
  1. 6.2 openlayers.module \openlayers_presets()
  2. 7.2 openlayers.module \openlayers_presets()

Get Presets Array

Get Presets from DB or code, via cache

Parameters

$reset: Boolean whether to reset or not

Return value

Return formatted data

Related topics

1 call to openlayers_presets()
openlayers_get_presets in ./openlayers.module
Get Formatted Presets

File

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

Code

function openlayers_presets($reset = FALSE) {
  static $presets = array();

  // If reset, reset cache
  if ($reset) {
    $presets = array();
    cache_clear_all('openlayers:presets', 'cache');

    // Clear the content.module cache
    // (refreshes the list of formatters)
    if (module_exists('content')) {
      content_clear_type_cache();
    }
  }

  // Return presets if already exists (page request cache)
  if (!empty($presets)) {
    return $presets;
  }

  // Attempt to get presets from cache
  if ($cache = cache_get('openlayers:presets', 'cache')) {
    $presets = $cache->data;
  }
  else {

    // Get data from hooks
    $defaults = module_invoke_all('openlayers_presets');

    // Since data from hooks cannot be edited or deleted, we mark now
    foreach ($defaults as $name => $preset) {
      $preset['type'] = OPENLAYERS_STORAGE_DEFAULT;
      $presets[$name] = $preset;
    }

    // Get data from DB
    $db_data = array();
    $query = "SELECT * FROM {openlayers_map_presets} ORDER BY preset_title";
    $results = db_query($query);
    while ($row = db_fetch_array($results)) {
      $db_data[$row['preset_name']] = $row;
    }

    // Check for conflicting preset names, use DB over hook
    foreach ($db_data as $name => $preset) {
      if (!empty($presets[$name])) {
        $preset['type'] = OPENLAYERS_STORAGE_OVERRIDE;
        $presets[$name] = $preset;
      }
      else {
        $preset['type'] = OPENLAYERS_STORAGE_NORMAL;
        $presets[$name] = $preset;
      }
    }

    // Cache data
    cache_set('openlayers:presets', $presets);
  }
  return $presets;
}