You are here

function yr_verdata_load_location in Yr Weatherdata 6.2

Same name and namespace in other branches
  1. 7 yr_verdata.module \yr_verdata_load_location()

Function for loading a location from the database, and adding the path to the file.

Parameters

$yid: The location's yid in the {yr_verdata} table. If this is set to -1, a random location will be fetched.

Return value

Returns an array with the basic location information in an object and a status. If no location was found, the status is FALSE, and the data returned is a message.

4 calls to yr_verdata_load_location()
yr_verdata_block in ./yr_verdata.module
Implementation of hook_block().
yr_verdata_cron in ./yr_verdata.module
Implementation of hook_cron().
yr_verdata_delete_confirm in ./yr_verdata.admin.inc
Function for deleting locations from the database table.
yr_verdata_page_single in ./yr_verdata.module
Function for generating a forecast page for a single location.

File

./yr_verdata.module, line 609
yr_verdata.module This file contains the code for getting the forecast from yr.no and displaying it on a Drupal site.

Code

function yr_verdata_load_location($yid) {
  if ($yid == -1) {
    $result = db_query("SELECT * FROM {yr_verdata} ORDER BY rand() LIMIT 1");

    // This might be slow on large tables, but we'll probably never see anyone going over two digits on their drupal site. If so, they can post an issue, or simply not use the random block.
  }
  else {
    $result = db_query("SELECT * FROM {yr_verdata} WHERE yid = %d", $yid);
  }
  if ($record = db_fetch_object($result)) {
    $record->filepath = _yr_verdata_local_file($record);
    return array(
      'data' => $record,
      'status' => TRUE,
    );
  }
  else {
    $msg = t('No location found with the given ID.');
    if (user_access('administer yr_verdata')) {
      $msg .= ' ' . _yr_verdata_addmore_msg();
    }
    return array(
      'data' => $msg,
      'status' => FALSE,
    );
  }
}