Completed weather and local time plugin
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
<?php namespace JasonWilliams\CalgaryConditions\Components;
|
||||
|
||||
use Cms\Classes\ComponentBase;
|
||||
use October\Rain\Network\Http;
|
||||
use JasonWilliams\CalgaryConditions\Models\Settings;
|
||||
use Cache;
|
||||
use ApplicationException;
|
||||
|
||||
class CurrentInfo extends ComponentBase
|
||||
{
|
||||
public $fields;
|
||||
//public $fields;
|
||||
|
||||
public function componentDetails()
|
||||
{
|
||||
@@ -18,6 +21,23 @@ class CurrentInfo extends ComponentBase
|
||||
public function onRun()
|
||||
{
|
||||
date_default_timezone_set('America/Edmonton');
|
||||
$this->fields['time'] = date('g:ia');
|
||||
$fields['time'] = date('g:ia');
|
||||
$this->page['conditions'] = $fields;
|
||||
$this->addJs('/plugins/jasonwilliams/calgaryconditions/assets/javascript/currentinfo.js');
|
||||
}
|
||||
|
||||
public function onUpdateRequested()
|
||||
{
|
||||
$settings = Settings::instance();
|
||||
|
||||
$response = Cache::remember('weatherdata', 60, function() {
|
||||
return json_decode(Http::get('http://api.weatherstack.com/current?access_key='.$settings->weatherstack_api_key.'&query=Calgary'));
|
||||
});
|
||||
|
||||
date_default_timezone_set('America/Edmonton');
|
||||
$fields['time'] = date('g:ia');
|
||||
$fields['temperature'] = $response->current->temperature;
|
||||
$fields['weather'] = strtolower($response->current->weather_descriptions[0]);
|
||||
$this->page['conditions'] = $fields;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
{% set conditions = __SELF__.fields %}
|
||||
|
||||
<p>Right now in Calgary the time is {{ conditions.time }}</p>
|
||||
<p id="currentinfo">Right now it's {{ conditions.time }} here in Calgary.</p>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Right now it's {{ conditions.time }} here in Calgary, it's {{ conditions.temperature }}°c and it's {{ conditions.weather }}.
|
||||
Reference in New Issue
Block a user