function _weather_es_contents in Weather_es 7
Weather_es contents
@author jmsirvent
1 call to _weather_es_contents()
File
- ./
weather_es.module, line 466
Code
function _weather_es_contents($delta) {
global $user;
$wid = $user->uid;
if ($delta == 'system') {
$wid = 0;
}
// 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 = :wid";
$usrcnfresult = db_query($sql, array(
':wid' => $wid,
));
$content = '';
while ($usrcnf = $usrcnfresult
->fetchObject()) {
// Update ancient data
if ($usrcnf->nex_upd < time()) {
// Get data from AEMET
$aemet = new weather_es_Aemet($usrcnf->cit_cod);
if ($aemet
->isLoadOk()) {
// Delete the previous city data and save the new one
db_delete('weather_es_data')
->condition('cit_cod', array(
':cit_cod' => $usrcnf->cit_cod,
))
->execute();
_weather_es_data_save($usrcnf->cit_cod, $usrcnf->cit_nam, serialize($aemet));
/*
// Next connectio to AEMET in 4h
db_update('weather_es_data')
->condition('cit_cod', array(':cit_cod' => $usrcnf->cit_cod))
->fields(array('nex_upd' => (time() + (4 * 3600))))
->execute();
*/
}
else {
// The connection with AEMET has failt, try in 10'
db_update('weather_es_data')
->condition('cit_cod', array(
':cit_cod' => $usrcnf->cit_cod,
))
->fields(array(
'nex_upd' => time() + 10 * 60,
))
->execute();
}
}
$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 = :wid AND wec.cit_cod = :cit_cod";
$result = db_query($sql, array(
':wid' => $wid,
':cit_cod' => $usrcnf->cit_cod,
))
->fetchObject();
// 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', array(
'inf_amo' => $result->inf_amo,
'day' => $day,
'obj' => $obj,
'inf_typ' => $inf_typ,
'page' => $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;
}