Sidebar widgets
This commit is contained in:
@@ -31,18 +31,19 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
// Update latest news (3 items)
|
||||
$schedule->call(function() {
|
||||
$latest_news = json_decode(file_get_contents($this->API_URL . 'nieuws/overzicht?pagina=1&aantal=3'));
|
||||
|
||||
$news = [];
|
||||
foreach($latest_news->news as $item_data)
|
||||
{
|
||||
$news[] = new \Model\NewsItem($item_data);
|
||||
}
|
||||
|
||||
Storage::disk('local')->put('laatste_nieuws.json', json_encode($news));
|
||||
Storage::disk('local')->put('laatste_nieuws.json', file_get_contents($this->API_URL . 'nieuws/overzicht?pagina=1&aantal=3'));
|
||||
Storage::disk('local')->put('populair_nieuws.json', file_get_contents($this->API_URL . 'nieuws/populair'));
|
||||
})->everyMinute();
|
||||
|
||||
// Update now / later
|
||||
$schedule->call(function() {
|
||||
Storage::disk('local')->put('nu_straks.json', file_get_contents($this->API_URL . 'programma/schema/nustraks'));
|
||||
})->everyMinute();
|
||||
|
||||
// Update latest podcasts (3 items)
|
||||
$schedule->call(function() {
|
||||
Storage::disk('local')->put('laatste_podcasts.json', file_get_contents($this->API_URL . 'podcast/overzicht?pagina=1&aantal=3'));
|
||||
})->everyMinute();
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,8 @@ use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
@@ -15,9 +17,44 @@ class Controller extends BaseController
|
||||
|
||||
protected $API_URL;
|
||||
|
||||
private function getDataFromFileAndConvert($file, $path, $class)
|
||||
{
|
||||
$data = json_decode(Storage::disk('local')->get($file));
|
||||
foreach($path as $subobject) { $data = $data->$subobject; }
|
||||
$items = [];
|
||||
foreach($data as $item_data)
|
||||
{
|
||||
$items[] = new $class($item_data);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
\Illuminate\Support\Facades\View::share('apiUrl', $this->API_URL = env('API_URL', 'http://api.6fm.nl/'));
|
||||
View::share('apiUrl', $this->API_URL = env('API_URL', 'http://api.6fm.nl/'));
|
||||
View::composer('widgets.laatstenieuws', function($view) {
|
||||
$view->with('data', $this->getDataFromFileAndConvert('laatste_nieuws.json', ['news'], '\Model\NewsItem'));
|
||||
});
|
||||
View::composer('widgets.populairnieuws', function($view) {
|
||||
$view->with('data', $this->getDataFromFileAndConvert('populair_nieuws.json', [], '\Model\NewsItem'));
|
||||
});
|
||||
View::composer('widgets.nustraks', function($view) {
|
||||
$data = json_decode(Storage::disk('local')->get('nu_straks.json'))->schedule;
|
||||
$programs = [];
|
||||
foreach($data as $item_data)
|
||||
{
|
||||
$programs[] = $program = new \Model\Program($item_data->program);
|
||||
$program->start = new \DateTimeImmutable($item_data->start->date, new \DateTimeZone($item_data->start->timezone));
|
||||
$program->end = new \DateTimeImmutable($item_data->end->date, new \DateTimeZone($item_data->end->timezone));
|
||||
}
|
||||
|
||||
|
||||
$view->with('data', $programs);
|
||||
});
|
||||
View::composer('widgets.laatstepodcasts', function($view) {
|
||||
$view->with('data', $this->getDataFromFileAndConvert('laatste_podcasts.json', ['podcasts'], '\Model\Podcast'));
|
||||
});
|
||||
}
|
||||
|
||||
protected function registerView(Request $request, $type, $id)
|
||||
|
||||
Reference in New Issue
Block a user