function block_weather_es_contents in Weather_es 6.3
Same name and namespace in other branches
- 5 weather_es.module \block_weather_es_contents()
- 6 weather_es.module \block_weather_es_contents()
- 6.2 weather_es.module \block_weather_es_contents()
Show the weather_es contents
@author jmsirvent
1 call to block_weather_es_contents()
File
- ./
weather_es.module, line 384
Code
function block_weather_es_contents($which_block) {
global $user;
// Cities data for that weather_es user
$sql = "SELECT wed.cit_cod, wed.cit_nam, wed.nex_upd FROM {weather_es_data} wed LEFT JOIN {weather_es_conf} wec ON wec.cit_cod = wed.cit_cod WHERE wec.wid = %d";
// Block 0 is about the site, 1 is about the user
$wid = $user->uid;
if ($which_block == 0) {
$wid = 0;
}
$usrcnfresult = db_query($sql, $wid);
$content = '';
while ($usrcnf = db_fetch_object($usrcnfresult)) {
// Update ancient data
if ($usrcnf->nex_upd < time()) {
// Get data from AEMET (de momento el código a pelo...)
$aemet = new weather_es_Aemet('03083');
if ($aemet != -1) {
// Delete the previous city data and save the new one
db_query("DELETE FROM {weather_es_data} WHERE cit_cod = %d", $usrcnf->cit_cod);
_weather_es_data_save($usrcnf->cit_cod, $usrcnf->cit_nam, serialize($aemet));
// Next connectio to AEMET in 4h
db_query("UPDATE {weather_es_data} SET nex_upd = %d WHERE cit_cod = %d", time() + 4 * 3600, $usrcnf->cit_cod);
}
else {
// The connection with AEMET has failt, try in 10'
db_query("UPDATE {weather_es_data} SET nex_upd = %d WHERE cit_cod = %d", time() + 10 * 60, $usrcnf->cit_cod);
}
}
$content .= '<strong>' . check_markup($usrcnf->cit_nam) . '</strong>';
$content .= t('<small><strong>Weather forecast by AEMET.</strong></small>');
$sql = "SELECT * FROM {weather_es_data} wed INNER JOIN {weather_es_conf} wec ON wed.cit_cod = wec.cit_cod WHERE wec.wid = %d AND wec.cit_cod = %d";
$result = db_fetch_object(db_query($sql, $wid, $usrcnf->cit_cod));
// What information the user wants
$inf_typ = unserialize($result->inf_typ);
$objWea = unserialize($result->dat_dat);
$data = $objWea
->getInfo();
// Day0 and day1 have information every 6h
// Day2 and day3 every 12h
// Day4, day5 and day6 every 24h
foreach ($data as $day => $obj) {
$page = ceil(($day + 1) / 2);
$content .= theme('weather_es', $result->inf_amo, $day, $obj, $inf_typ, $page);
}
$content .= '<div class="item-list"><ul class="pager">';
$content .= '<li class="pager-item weather_es-pager-item"><a class="active" rel="1">1</a></li>';
$content .= '<li class="pager-item weather_es-pager-item"><a class="active" rel="2">2</a></li>';
$content .= '<li class="pager-item weather_es-pager-item"><a class="active" rel="3">3</a></li>';
$content .= '<li class="pager-item weather_es-pager-item"><a class="active" rel="4">4</a></li>';
$content .= '</ul></div>';
}
return $content;
}