From 4ff0d7acc219c1199b85d1f8c27d08e7b643deaa Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Thu, 27 Jul 2017 00:06:57 +0200 Subject: [PATCH] Changes to schedule for frontend --- .../Http/Controllers/ProgramController.php | 27 +++++++++---------- api/routes/web.php | 2 +- common/classes/NewsImage.php | 2 +- common/classes/NewsItem.php | 9 ++++++- common/classes/Program.php | 7 ++++- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/api/app/Http/Controllers/ProgramController.php b/api/app/Http/Controllers/ProgramController.php index cb5a65d..18612c0 100644 --- a/api/app/Http/Controllers/ProgramController.php +++ b/api/app/Http/Controllers/ProgramController.php @@ -146,11 +146,9 @@ QUERY /** * Programmaschema per week */ - public function schedule(Request $request, $weeksAhead = null) { - if($weeksAhead === null) { $weeksAhead = 1; } - else if($weeksAhead <= 0) { return abort(400); } - $start = new \DateTimeImmutable('Monday this week'); - $einde = $start->add(\DateInterval::createFromDateString((int)$weeksAhead . ' weeks')); + public function schedule(Request $request, $shiftWeeks = null) { + $start = (new \DateTimeImmutable('Monday this week'))->add(\DateInterval::createFromDateString((int)$shiftWeeks . ' weeks')); + $einde = $start->add(\DateInterval::createFromDateString('1 week')); return response()->json($this->createSchedule($start, $einde)); } @@ -231,30 +229,29 @@ QUERY $actieveProgrammas[$programma->priority] = $programma; for($prio = $programma->priority; $prio >= 0; --$prio) { if($actieveProgrammas[$prio] != null) { - if(($index == -1) || ($schema[$index]['time'] != $tijdstip)) { $index++; } - $schema[$index] = ['time' => $tijdstip, 'program' => $programmaInfo[$actieveProgrammas[$prio]->id]]; + if(($index == -1) || ($schema[$index]['starttime'] != $tijdstip)) { $index++; } + $schema[$index] = ['starttime' => $tijdstip, 'endtime' => null, 'program' => $programmaInfo[$actieveProgrammas[$prio]->id]]; break; } } } else /*if($programmaWissel[PW_TYPE] == PROGRAMMA_EINDE)*/ { $actieveProgrammas[$programma->priority] = null; if(($index == -1) || ($schema[$index]['program'] != null)) { $index++; } - $schema[$index] = ['time' => $tijdstip, 'program' => null]; + $schema[$index] = ['starttime' => $tijdstip, 'program' => null]; for($prio = $programma->priority; $prio < count($actieveProgrammas); ++$prio) { if($actieveProgrammas[$prio] != null) { - $schema[$index] = ['time' => $tijdstip, 'program' => $programmaInfo[$actieveProgrammas[$prio]->id]]; + $schema[$index] = ['starttime' => $tijdstip, 'endtime' => null, 'program' => $programmaInfo[$actieveProgrammas[$prio]->id]]; break; } } } } - if(false) { - for($i = 1; $i <= count($schema); $i++) { - $eindTijd = ($i == count($schema)) ? $einde : $schema[$i]['time']; - $programma = $schema[$i-1]['program']; - print $schema[$i-1]['time']->format('D d-m-Y, H:i:s') . " - " . $eindTijd->format('D d-m-Y, H:i:s') . ": " . ($programma != null ? $programma->name : "NULL") . "\n"; - } + for($i = 1; $i <= count($schema); $i++) { + $eindTijd = ($i == count($schema)) ? $einde : $schema[$i]['starttime']; + $schema[$i - 1]['endtime'] = $eindTijd; + //$programma = $schema[$i-1]['program']; + //print $schema[$i-1]['starttime']->format('D d-m-Y, H:i:s') . " - " . $eindTijd->format('D d-m-Y, H:i:s') . ": " . ($programma != null ? $programma->name : "NULL") . "\n"; } return ['startdate' => $start, 'enddate' => $einde, 'schedule' => $schema, 'errors' => $fouten]; diff --git a/api/routes/web.php b/api/routes/web.php index b154359..1daeaf1 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -30,7 +30,7 @@ $app->get('podcast/download/{id:\d+}/[{title}]', 'PodcastController@download' ); $app->get('podcast/stream/{id:\d+}/[{title}]', 'PodcastController@stream' ); $app->get('programma/schema/nustraks', 'ProgramController@comingup' ); -$app->get('programma/schema/week[/{weeksAhead:\d+}]', 'ProgramController@schedule' ); +$app->get('programma/schema/week[/{shiftWeeks:-?\d+}]', 'ProgramController@schedule' ); $app->get('/programma/details/{id:\d+}', 'ProgramController@details' ); // live/onair diff --git a/common/classes/NewsImage.php b/common/classes/NewsImage.php index 44adaa1..9214f9a 100644 --- a/common/classes/NewsImage.php +++ b/common/classes/NewsImage.php @@ -13,7 +13,7 @@ class NewsImage extends Model { // Deserialisatie van JSON heeft url in data, // lezen uit database heeft file en (als het goed is) urlPrefix if(isset($data->file)) { - $this->url = $urlPrefix . $data->file; + $this->url = 'http://www.6fm.nl' . $urlPrefix . $data->file; } } } diff --git a/common/classes/NewsItem.php b/common/classes/NewsItem.php index 69979fb..ad7d622 100644 --- a/common/classes/NewsItem.php +++ b/common/classes/NewsItem.php @@ -36,7 +36,14 @@ class NewsItem extends Model { ? new \Model\NewsSource($data->source->title, $data->source->url, $data->source->url) : new \Model\NewsSource($data->source, $data->source_url, $data->showsource); } - $this->keywords = !is_array($data->keywords) && trim($data->keywords) ? explode(' ', $data->keywords) : null; + + $this->keywords = null; + if(is_array($data->keywords)) { + $this->keywords = $data->keywords; + } else if(trim($data->keywords)) { + $this->keywords = explode(' ', $data->keywords); + } + $this->podcast = $data->podcast ? $data->podcast : null; $images = ($images != null) ? $images diff --git a/common/classes/Program.php b/common/classes/Program.php index 8432a11..7230bd8 100644 --- a/common/classes/Program.php +++ b/common/classes/Program.php @@ -16,9 +16,14 @@ class Program extends Model { public function __construct($data) { parent::__construct($data); - $this->isSpecial = ($data->priority < 2); + if(!isset($data->isSpecial) && isset($data->priority)) { + $this->isSpecial = ($data->priority < 2); + } + if(($mailComma = strpos($data->email, ',')) !== false) { $this->email = substr($data->email, 0, $mailComma); } + + $this->url = "/{$this->id}/" . parent::url_slug($this->name); } }