You are here

function _yr_verdata_get_all in Yr Weatherdata 6.2

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

Function for getting all locations into an array of objects. Used for the block and overview page for all locations. Will sort and group the returned array according to the settings in yr_verdata's configuration page.

Parameters

$block: If this is TRUE, no paging is performed in the query, because for the block with all locations, we are loading all of them.

Return value

Returns an array of locations as objects from the database. Sorted and grouped as per the settings.

2 calls to _yr_verdata_get_all()
yr_verdata_block in ./yr_verdata.module
Implementation of hook_block().
yr_verdata_page_all in ./yr_verdata.module
Function for generating the main forecast page.

File

./yr_verdata.module, line 1039
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_get_all($block = FALSE) {
  $grouping = variable_get('yr_verdata_group', 'off');

  // Are we grouping locations in some way?
  $order = variable_get('yr_verdata_order', 'weight');
  $placeholders = array();
  $records = array();
  $query = "SELECT * FROM {yr_verdata} ORDER BY";

  //  $query .= " country, name";
  if ($grouping != 'off') {
    $query .= " %s,";
    $placeholders[] = $grouping;
  }
  $query .= " %s";
  $placeholders[] = $order;
  $npp = variable_get('yr_verdata_npp', 0);

  // If we are loading for a block, we shouldn't page the results.
  if ($block == TRUE) {
    $npp = 0;
  }
  if ($npp > 0) {
    $result = pager_query($query, $npp, 0, NULL, $placeholders);
  }
  else {
    $result = db_query($query, $placeholders);
  }
  while ($record = db_fetch_object($result)) {
    $records[] = $record;
  }
  return $records;
}