Accueil/modules/worldweatheronline/Worldweatheronline.php

38 lines
1.4 KiB
PHP
Raw Normal View History

<?php
class worldweatheronline extends Module
{
protected $moduleTitle = 'Météo';
protected $paramsList = array(
'visibility',
'city',
'x',
'y'
);
public function __construct($params){
parent::__construct(__CLASS__, $params);
}
public function build(){
$ville = $this->getParam('city');
$future_weather = [];
include $this->pathToModule.'includes/WorldweatheronlineApi.php';
$api = new WorldweatheronlineApi($ville);
if ($api->isFound()) {
$forecast = $api->getForecast();
$current = $api->getCurrent();
echo '<script type="text/javascript" src="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
<link rel="stylesheet" type="text/css" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css">';
echo '<div id="worldweatheronline" style="left:'.$this->getParam("x").'; top:'.$this->getParam("y").';">
'.$ville.'<br/>
<div class="weatherpic"><img src="'.$api->getIcon().'"/></div>
<strong>'.'Actuellement : ' . $current['temp_c'] . '°C - ' . $current['condition'].'</strong><br/>
'.implode('<br/>', array_map(function($f) {
return sprintf('%s : %s°C | %s°C - %s', $f['day_of_week'], $f['low'], $f['high'], $f['condition']);
}, $forecast)).'
</div>';
}
}
}