Test version

This commit is contained in:
Jorit Tijsen
2024-03-05 17:22:55 +01:00
parent 8acacc0c68
commit 55aa88c0f6
128 changed files with 46700 additions and 9645 deletions

View File

@@ -27,39 +27,39 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$this->API_URL = env('API_URL', 'https://api.nhgooi.nl/');
// Update latest news (3 items)
$schedule->call(function() {
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'));
Storage::disk('local')->put('zojuist.json', file_get_contents($this->API_URL . 'programma/schema/recent'));
})->everyMinute();
// Update latest podcasts (6 items)
$schedule->call(function() {
Storage::disk('local')->put('laatste_podcasts.json', file_get_contents($this->API_URL . 'podcast/overzicht?pagina=1&aantal=6'));
})->everyMinute();
// Update calendar items
$schedule->call(function() {
Storage::disk('local')->put('regioagenda.json', file_get_contents($this->API_URL . 'agenda/overzicht'));
})->everyMinute();
// Update blogs
$schedule->call(function() {
Storage::disk('local')->put('blogs.json', file_get_contents($this->API_URL . 'blog/overzicht'));
})->everyMinute();
// Update featured images
$schedule->call(function() {
Storage::disk('local')->put('beelden.json', file_get_contents($this->API_URL . 'beelden/overzicht'));
})->everyMinute();
// $this->API_URL = env('API_URL', 'https://api.nhgooi.nl/');
//
// // Update latest news (3 items)
// $schedule->call(function() {
// 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'));
// Storage::disk('local')->put('zojuist.json', file_get_contents($this->API_URL . 'programma/schema/recent'));
// })->everyMinute();
//
// // Update latest podcasts (6 items)
// $schedule->call(function() {
// Storage::disk('local')->put('laatste_podcasts.json', file_get_contents($this->API_URL . 'podcast/overzicht?pagina=1&aantal=6'));
// })->everyMinute();
//
// // Update calendar items
// $schedule->call(function() {
// Storage::disk('local')->put('regioagenda.json', file_get_contents($this->API_URL . 'agenda/overzicht'));
// })->everyMinute();
//
// // Update blogs
// $schedule->call(function() {
// Storage::disk('local')->put('blogs.json', file_get_contents($this->API_URL . 'blog/overzicht'));
// })->everyMinute();
//
// // Update featured images
// $schedule->call(function() {
// Storage::disk('local')->put('beelden.json', file_get_contents($this->API_URL . 'beelden/overzicht'));
// })->everyMinute();
}
/**

View File

@@ -14,15 +14,15 @@ use Illuminate\Support\Facades\View;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $API_URL;
private function getDataFromFileAndConvert($file, $path, $class, $maxItems = 0)
private function getDataFromFileAndConvert($file, $path, $class, $maxItems = 0)
{
$data = json_decode(Storage::disk('local')->get($file));
foreach($path as $subobject) { $data = $data->$subobject; }
$items = [];
foreach($data as $item_data)
foreach($data as $item_data)
{
$items[] = new $class($item_data);
if($maxItems && count($items) == $maxItems) { break; }
@@ -51,7 +51,7 @@ class Controller extends BaseController
View::composer('widgets.nustraks', function($view) {
$data = json_decode(Storage::disk('local')->get('nu_straks.json'))->schedule;
$programs = [];
foreach($data as $item_data)
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));
@@ -62,7 +62,7 @@ class Controller extends BaseController
$now = new \DateTimeImmutable('2 minutes ago');
$data = json_decode(Storage::disk('local')->get('zojuist.json'))->schedule;
$i = 0;
foreach(array_reverse($data) as $item_data)
foreach(array_reverse($data) as $item_data)
{
$recent = $program = new \Model\Program($item_data->program);
$recent->start = new \DateTimeImmutable($item_data->start->date, new \DateTimeZone($item_data->start->timezone));
@@ -90,10 +90,10 @@ class Controller extends BaseController
->with('podcasts', $this->getDataFromFileAndConvert('laatste_podcasts.json', ['podcasts'], '\Model\Podcast'));
});
}
protected function registerView(Request $request, $type, $id)
{
if(config('app.env') == 'local') {
if(config('app.env') == 'local') {
return;
}
@@ -108,16 +108,28 @@ class Controller extends BaseController
protected function API($url)
{
return json_decode(file_get_contents($this->API_URL . $url));
// if (strpos($url, 'nieuws/overzicht') !== false) {
// return json_decode(file_get_contents(__DIR__ . '/../../../storage/app/laatste_nieuws.json'));
// }
// return [];
$arrContextOptions= [
'ssl' => [
"verify_peer"=>false,
"verify_peer_name"=>false,
],
];
return json_decode(file_get_contents($this->API_URL . $url, false, stream_context_create($arrContextOptions)));
}
protected static function JsonToDateTime($obj)
protected static function JsonToDateTime($obj)
{
return new \DateTime($obj->date, new \DateTimeZone($obj->timezone));
}
public function __call($method, $arguments) {
if(substr($method, 0, 5) == 'view_') {
if(substr($method, 0, 5) == 'view_') {
$view = substr($method, 5);
if(view()->exists($view)) { return view($view); }
}