function _yr_verdata_get_all in Yr Weatherdata 7
Same name and namespace in other branches
- 6.2 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_view in ./
yr_verdata.module - Implementation of hook_block_view().
- yr_verdata_page_all in ./
yr_verdata.module - Function for generating the main forecast page.
File
- ./
yr_verdata.module, line 1115 - 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');
$npp = variable_get('yr_verdata_npp', 0);
// Add a pager, unless $block is TRUE.
if ($npp == 0 || $block == TRUE) {
$query = db_select('yr_verdata', 'y');
}
else {
$query = db_select('yr_verdata', 'y')
->extend('PagerDefault')
->limit($npp);
}
$query
->fields('y', array(
'yid',
'name',
'region',
'country',
'url',
'file',
'weight',
'updated',
'lang',
));
if ($grouping != 'off') {
$query
->orderBy($grouping);
}
$query
->orderBy($order, 'ASC');
if ($order != 'weight') {
$query
->orderBy('weight');
}
// If we are not using weight as primary ordering, we still order by that in the end.
$result = $query
->execute();
$records = $result
->fetchAll();
return $records;
}