You are here

function weather_get_display_config in Weather 7.3

Same name and namespace in other branches
  1. 7.2 weather.common.inc \weather_get_display_config()

Return display configuration for a specific display.

If there is no configuration yet, get the default configuration instead.

Parameters

string $display_type: Display type.

int $display_number: Display number.

Return value

object Display configuration.

3 calls to weather_get_display_config()
weather_block_view in ./weather.module
Implements hook_block_view().
weather_display_config_form in ./weather.forms.inc
Create a configuration form for a weather display.
weather_show_detailed_forecast in ./weather.common.inc
Display a detailed weather forecast for a given place.

File

./weather.common.inc, line 153
Common functions in a separate file to reduce size of weather.module.

Code

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

    // There is no specific configuration. Try to get custom default configuration.
    $config = db_query('SELECT * FROM {weather_displays} WHERE type=\'default\'')
      ->fetchObject();
    if (empty($config)) {

      // There is no custom default configuration. Get module's default configuration.
      $config = new stdClass();
      $config->config = array(
        'temperature' => 'celsius',
        'windspeed' => 'kmh',
        'pressure' => 'hpa',
        'distance' => 'kilometers',
        'show_sunrise_sunset' => FALSE,
        'show_windchill_temperature' => FALSE,
        'show_abbreviated_directions' => FALSE,
        'show_directions_degree' => FALSE,
      );
    }
    else {

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

    // Convert specified configuration.
    $config->config = unserialize($config->config);
  }
  return $config;
}