<?php

namespace App\Http\Controllers;

use \Model\NewsItem;

class HomeController extends Controller
{
    public function show()
    {
        $apiResult = $this->API('nieuws/overzicht?aantal=12');
        $news = [];
        foreach($apiResult->news as $newsItem)
        {
          $news[] = new \Model\NewsItem($newsItem);
        } 

        $apiResult = $this->API('programma/schema/nustraks');
        $comingUp = [];
        foreach($apiResult->schedule as $program)
        {
          $comingUp[] = [
            'start' => self::JsonToDateTime($program->start),
            'end' => self::JsonToDateTime($program->end),
            'program' => new \Model\Program($program->program) 
          ];
        }

        $apiResult = $this->API('podcast/overzicht?aantal=20');
        $podcasts = [];
        foreach($apiResult->podcasts as $podcast) { 
          $podcasts[] = new \Model\Podcast($podcast);
        }

        return view('home', ['news' => $news, 'podcasts' => $podcasts, 'comingUp' => $comingUp]);
    }
}
