You are here

function yr_verdata_page in Yr Weatherdata 6

Function to display a page with yr_verdata stuff.

Parameters

$yid: The {yr_verdata}.yid for this location, used to get info from the database, and subsequently from yr.no. If == 0, a list is displayed of all locations.

Return value

Returns either a formatted page with forecast for a location, or a list of all locations.

1 string reference to 'yr_verdata_page'
yr_verdata_menu in ./yr_verdata.module
Implementation of hook_menu().

File

./yr_verdata.module, line 77
yr_verdata.module This file provides the yr_verdata forecast module.

Code

function yr_verdata_page($yid = 0) {
  $sql = "SELECT * FROM {yr_verdata}";
  if ($yid == 0) {
    $sql .= " ORDER BY '%s', 'location' ASC";
    $order = variable_get('yr_verdata_order', 'subregion');
    $result = db_query($sql, $order);
    $rows = array();
    while ($row = db_fetch_array($result)) {
      $tmp = explode('/', $row['url']);
      $row['title'] = isset($tmp[4]) ? $tmp[4] : '';
      $sep = isset($tmp[4]) ? ' - ' : '';
      $row['title'] .= $tmp[4] == $tmp[3] ? '' : $sep . $tmp[3];
      $row['title'] .= variable_get('yr_verdata_display_countryname', 'off') == 'on' ? ', ' . $tmp[2] . ', ' . $tmp[1] : '';
      $row['title'] = str_replace('_', ' ', $row['title']);
      $rows[] = l($row['title'], 'yr_verdata/' . $row['yid']);
    }
    if (count($rows) == 0) {
      drupal_set_message(t('No locations are stored in the database.'), 'warning');
      return FALSE;
    }
    else {
      return theme('item_list', $rows);
    }
  }
  elseif ($yid > 0) {
    $sql .= " WHERE yid = %d";
    $row = db_fetch_object(db_query($sql, $yid));
    $output = db_affected_rows() == 1 ? theme('yr_verdata_location_page', $row) : t('No matching location was found.');
    return $output;
  }
  else {
    drupal_set_message(t('The location ID @id is unknown', array(
      '@id' => $yid,
    )));
  }
}