You are here

function weather_get_display_settings in Weather 7

Return display settings for a specific display.

If there are no settings yet, get the default settings instead.

Parameters

string $display_type: Display type.

int $display_number: Display number.

Return value

Display configuration.

3 calls to weather_get_display_settings()
weather_block_view in ./weather.module
Implement hook_block_view().
weather_display_settings_form in ./weather.forms.inc
Create a settings form for a weather display.
weather_search_location in ./weather.forms.inc
Search for a given location.

File

./weather.module, line 450
Display current weather data from many places in the world.

Code

function weather_get_display_settings($display_type, $display_number = NULL) {
  $settings = db_query('SELECT * FROM {weather_display} WHERE type=:type AND number=:number', array(
    ':type' => $display_type,
    ':number' => $display_number,
  ))
    ->fetchObject();
  if (empty($settings)) {

    // There are no specific settings. Try to get custom default settings.
    $settings = db_query('SELECT * FROM {weather_display} WHERE type=:type', array(
      ':type' => 'default',
    ))
      ->fetchObject();
    if (empty($settings)) {

      // There are no custom default settings. Get module's default settings.
      $settings = new stdClass();
      $settings->units = array(
        'temperature' => 'celsius',
        'windspeed' => 'kmh',
        'pressure' => 'hpa',
        'distance' => 'kilometers',
      );
      $settings->settings = array(
        'data' => array(
          'temperature' => 'temperature',
          'wind' => 'wind',
          'pressure' => 'pressure',
          'humidity' => 'humidity',
          'visibility' => 'visibility',
        ),
        'show_apparent_temperature' => FALSE,
        'show_abbreviated_directions' => FALSE,
        'show_directions_degree' => FALSE,
        'show_compact_block' => FALSE,
      );
    }
    else {

      // Convert custom default settings.
      $settings->units = unserialize($settings->units);
      $settings->settings = unserialize($settings->settings);
    }
  }
  else {

    // Convert specified settings.
    $settings->units = unserialize($settings->units);
    $settings->settings = unserialize($settings->settings);
  }
  return $settings;
}