programma/nustraks toegevoegd.
This commit is contained in:
@@ -31,31 +31,50 @@ QUERY;
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Programmas nu en straks (24 uur vooruit)
|
||||||
|
*/
|
||||||
|
public function comingup() {
|
||||||
|
$start = new \DateTimeImmutable('now');
|
||||||
|
$einde = $start->add(\DateInterval::createFromDateString('today + 48 hours'));
|
||||||
|
$schema = $this->createSchedule($start, $einde);
|
||||||
|
|
||||||
|
return response()->json($schema);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Programmaschema per week
|
* Programmaschema per week
|
||||||
*/
|
*/
|
||||||
public function schedule(Request $request, $weeksAhead = null) {
|
public function schedule(Request $request, $weeksAhead = null) {
|
||||||
define('PROGRAMMA_START', 1);
|
|
||||||
define('PROGRAMMA_EINDE', -1);
|
|
||||||
|
|
||||||
define('PW_TIJDSTIP', 0);
|
|
||||||
define('PW_TYPE', 1);
|
|
||||||
define('PW_PROGRAMMA', 2);
|
|
||||||
|
|
||||||
$oneWeek = \DateInterval::createFromDateString('1 week');
|
|
||||||
|
|
||||||
if($weeksAhead <= 0) { $weeksAhead = 1; }
|
if($weeksAhead <= 0) { $weeksAhead = 1; }
|
||||||
$start = new \DateTimeImmutable('Monday this week');
|
$start = new \DateTimeImmutable('Monday this week');
|
||||||
$einde = $start->add(\DateInterval::createFromDateString((int)$weeksAhead . ' weeks'));
|
$einde = $start->add(\DateInterval::createFromDateString((int)$weeksAhead . ' weeks'));
|
||||||
|
|
||||||
|
return response()->json($this->createSchedule($start, $einde));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createSchedule($start, $einde) {
|
||||||
|
if(!defined('PROGRAMMA_START')) {
|
||||||
|
define('PROGRAMMA_START', 1);
|
||||||
|
define('PROGRAMMA_EINDE', -1);
|
||||||
|
|
||||||
|
define('PW_TIJDSTIP', 0);
|
||||||
|
define('PW_TYPE', 1);
|
||||||
|
define('PW_PROGRAMMA', 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
$oneWeek = \DateInterval::createFromDateString('1 week');
|
||||||
|
|
||||||
|
|
||||||
$programmas = app('db')->select(self::$SCHEDULE_SQL,
|
$programmas = app('db')->select(self::$SCHEDULE_SQL,
|
||||||
['enddate' => $einde->format('Y-m-d'), 'startdate' => $start->format('Y-m-d')]);
|
['enddate' => $einde->format('Y-m-d'), 'startdate' => $start->format('Y-m-d')]);
|
||||||
|
|
||||||
// Maak een lijstje van alle start en eindtijden en welk programma dan begint/eindigt
|
// Maak een lijstje van alle start en eindtijden en welk programma dan begint/eindigt
|
||||||
$startEinde = [];
|
$startEinde = [];
|
||||||
|
$startMaandag = $start->modify('Monday this week');
|
||||||
foreach($programmas as $programma) {
|
foreach($programmas as $programma) {
|
||||||
$programmaStart = $start->add(\DateInterval::createFromDateString(($programma->startday - 1) % 7 . ' days'));
|
$programmaStart = $startMaandag->add(\DateInterval::createFromDateString(($programma->startday - 1) % 7 . ' days'));
|
||||||
$programmaEinde = $start->add(\DateInterval::createFromDateString(($programma->endday - 1) % 7 . ' days'));
|
$programmaEinde = $startMaandag->add(\DateInterval::createFromDateString(($programma->endday - 1) % 7 . ' days'));
|
||||||
|
|
||||||
$startTijd = new \DateTime($programma->starttime);
|
$startTijd = new \DateTime($programma->starttime);
|
||||||
$eindTijd = new \DateTime($programma->endtime);
|
$eindTijd = new \DateTime($programma->endtime);
|
||||||
@@ -73,11 +92,13 @@ QUERY;
|
|||||||
}
|
}
|
||||||
|
|
||||||
while($programmaStart < $einde) {
|
while($programmaStart < $einde) {
|
||||||
if(($programma->startdate != null) && ($programmaStart < new \DateTime($programma->startdate))) { continue; }
|
if((($programma->startdate == null) || ($programmaStart >= new \DateTime($programma->startdate)))
|
||||||
if(($programma->enddate != null) && ($programmaStart > new \DateTime($programma->enddate))) { continue; }
|
&& (($programma->enddate == null) || ($programmaStart <= new \DateTime($programma->enddate)))
|
||||||
|
&& (($programmaEinde >= $start) && ($programmaStart <= $einde)))
|
||||||
$startEinde[] = [$programmaStart, PROGRAMMA_START, $programma];
|
{
|
||||||
$startEinde[] = [$programmaEinde, PROGRAMMA_EINDE, $programma];
|
$startEinde[] = [$programmaStart, PROGRAMMA_START, $programma];
|
||||||
|
$startEinde[] = [$programmaEinde, PROGRAMMA_EINDE, $programma];
|
||||||
|
}
|
||||||
|
|
||||||
$programmaStart = $programmaStart->add($oneWeek);
|
$programmaStart = $programmaStart->add($oneWeek);
|
||||||
$programmaEinde = $programmaEinde->add($oneWeek);
|
$programmaEinde = $programmaEinde->add($oneWeek);
|
||||||
@@ -86,8 +107,6 @@ QUERY;
|
|||||||
|
|
||||||
array_multisort($startEinde);
|
array_multisort($startEinde);
|
||||||
|
|
||||||
// return response()->json($startEinde);
|
|
||||||
|
|
||||||
$actieveProgrammas = [null, null, null, null];
|
$actieveProgrammas = [null, null, null, null];
|
||||||
$schema = [];
|
$schema = [];
|
||||||
$fouten = [];
|
$fouten = [];
|
||||||
@@ -125,14 +144,14 @@ QUERY;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(false) {
|
if(false) {
|
||||||
for($i = 1; $i <= count($schema); $i++) {
|
for($i = 1; $i <= count($schema); $i++) {
|
||||||
$eindTijd = ($i == count($schema)) ? $einde : $schema[$i]['tijdstip'];
|
$eindTijd = ($i == count($schema)) ? $einde : $schema[$i]['tijdstip'];
|
||||||
$programma = $schema[$i-1]['programma'];
|
$programma = $schema[$i-1]['programma'];
|
||||||
print $schema[$i-1]['tijdstip']->format('D d-m-Y, H:i:s') . " - " . $eindTijd->format('D d-m-Y, H:i:s') . ": " . ($programma != null ? $programma->longname : "NULL") . "\n";
|
print $schema[$i-1]['tijdstip']->format('D d-m-Y, H:i:s') . " - " . $eindTijd->format('D d-m-Y, H:i:s') . ": " . ($programma != null ? $programma->longname : "NULL") . "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return response()->json(['wah' => $weeksAhead, 'startdate' => $start, 'enddate' => $einde, 'schema' => $schema, 'fouten' => $fouten, 'programmas' => $programmas]);
|
return ['startdate' => $start, 'enddate' => $einde, 'schema' => $schema, 'fouten' => $fouten];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ $app->get('podcast/overzicht', 'PodcastController@overview' );
|
|||||||
$app->get('podcast/download/{id:\d+}/[{title}]', 'PodcastController@download' );
|
$app->get('podcast/download/{id:\d+}/[{title}]', 'PodcastController@download' );
|
||||||
$app->get('podcast/stream/{id:\d+}/[{title}]', 'PodcastController@stream' );
|
$app->get('podcast/stream/{id:\d+}/[{title}]', 'PodcastController@stream' );
|
||||||
|
|
||||||
// programma/nustraks
|
$app->get('programma/schema/nustraks', 'ProgramController@comingup' );
|
||||||
$app->get('programma/schema/week[/{weeksAhead:\d+}]', 'ProgramController@schedule' );
|
$app->get('programma/schema/week[/{weeksAhead:\d+}]', 'ProgramController@schedule' );
|
||||||
// programma/details/{id:\d+}
|
// programma/details/{id:\d+}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user