Bug fixes schedule
This commit is contained in:
@@ -10,9 +10,9 @@ ini_set('display_errors', true);
|
|||||||
class ProgramController extends Controller
|
class ProgramController extends Controller
|
||||||
{
|
{
|
||||||
private static $SCHEDULE_SQL = <<<QUERY
|
private static $SCHEDULE_SQL = <<<QUERY
|
||||||
SELECT `programs`.`id`, `programs`.`longname` AS `name`, `programs`.`description` AS `description`, `schedule`.`priority`,
|
SELECT `schedule`.`id`, `programs`.`longname` AS `name`, `programs`.`description` AS `description`, `programs`.`email`, `schedule`.`priority`,
|
||||||
`schedule`.`startdate`, `schedule`.`startday`, `schedule`.`starttime`,
|
`schedule`.`startdate`, `schedule`.`startday`, `schedule`.`starttime`,
|
||||||
`schedule`.`enddate`, `schedule`.`endday`, `schedule`.`endtime`
|
`schedule`.`enddate`, `schedule`.`endday`, `schedule`.`endtime`, `schedule`.`shortnamesuffix` AS `suffix`
|
||||||
FROM `programs_schedule` AS `schedule` LEFT JOIN `programs` ON `schedule`.`program` = `programs`.`id`
|
FROM `programs_schedule` AS `schedule` LEFT JOIN `programs` ON `schedule`.`program` = `programs`.`id`
|
||||||
WHERE ((`schedule`.`startdate` IS NULL) OR (`schedule`.`startdate` < :enddate)) AND
|
WHERE ((`schedule`.`startdate` IS NULL) OR (`schedule`.`startdate` < :enddate)) AND
|
||||||
((`schedule`.`enddate` IS NULL) OR (`schedule`.`enddate` >= :startdate)) AND
|
((`schedule`.`enddate` IS NULL) OR (`schedule`.`enddate` >= :startdate)) AND
|
||||||
@@ -35,7 +35,7 @@ QUERY;
|
|||||||
* Details over een specifiek programma, inclusief schema en podcasts
|
* Details over een specifiek programma, inclusief schema en podcasts
|
||||||
*/
|
*/
|
||||||
public function details($id) {
|
public function details($id) {
|
||||||
$programs = app('db')->select("SELECT `id`, `longname`, `description`, `email` FROM `programs` WHERE `id` = :id", ['id' => (int)$id]);
|
$programs = app('db')->select("SELECT `id`, `longname` AS `name`, `description`, `email` FROM `programs` WHERE `id` = :id", ['id' => (int)$id]);
|
||||||
if(count($programs) != 1) {
|
if(count($programs) != 1) {
|
||||||
return abort(404);
|
return abort(404);
|
||||||
}
|
}
|
||||||
@@ -55,12 +55,9 @@ QUERY;
|
|||||||
}
|
}
|
||||||
|
|
||||||
$schedule = app('db')->select(<<<QUERY
|
$schedule = app('db')->select(<<<QUERY
|
||||||
SELECT `schedule`.`startdate`, `schedule`.`startday`, `schedule`.`starttime`, `schedule`.`enddate`, `schedule`.`endday`, `schedule`.`endtime`
|
SELECT `schedule`.`startdate`, `schedule`.`startday`, `schedule`.`starttime`, `schedule`.`enddate`, `schedule`.`endday`, `schedule`.`endtime`, `schedule`.`shortnamesuffix` AS `suffix`, `schedule`.`priority`
|
||||||
FROM `programs_schedule` AS `schedule`
|
FROM `programs_schedule` AS `schedule`
|
||||||
WHERE (schedule.`program` = :program) AND (`schedule`.`active` = 1) AND (`schedule`.`final` = 1) AND
|
WHERE (schedule.`program` = :program) AND (`schedule`.`active` = 1) AND (`schedule`.`final` = 1)
|
||||||
-- ((`schedule`.`startdate` IS NULL) OR (`schedule`.`startdate` < :enddate)) AND
|
|
||||||
-- ((`schedule`.`enddate` IS NULL) OR (`schedule`.`enddate` >= :startdate)) AND
|
|
||||||
1=1
|
|
||||||
ORDER BY `schedule`.`priority` DESC, MOD(`startday` + 6, 7) + 1, `schedule`.`starttime` ASC
|
ORDER BY `schedule`.`priority` DESC, MOD(`startday` + 6, 7) + 1, `schedule`.`starttime` ASC
|
||||||
QUERY
|
QUERY
|
||||||
, ['program' => $program->id] );
|
, ['program' => $program->id] );
|
||||||
@@ -80,8 +77,10 @@ QUERY
|
|||||||
// Vind voor elke regel in de uitzendmomenten de eerstvolgende en twee meest recente.
|
// Vind voor elke regel in de uitzendmomenten de eerstvolgende en twee meest recente.
|
||||||
$isCurrent = false;
|
$isCurrent = false;
|
||||||
foreach($schedule as $broadcast) {
|
foreach($schedule as $broadcast) {
|
||||||
|
$broadcast->startdate = ($broadcast->startdate == null) ? null : new \DateTimeImmutable($broadcast->startdate);
|
||||||
|
$broadcast->enddate = ($broadcast->enddate == null) ? null : new \DateTimeImmutable($broadcast->enddate);
|
||||||
$startTijd = new \DateTimeImmutable($broadcast->starttime);
|
$startTijd = new \DateTimeImmutable($broadcast->starttime);
|
||||||
$endDate = ($broadcast->enddate == null) ? $now : new \DateTimeImmutable($broadcast->enddate);
|
$endDate = ($broadcast->enddate == null) ? $now : $broadcast->enddate;
|
||||||
$endDate = $endDate->setTime($startTijd->format('H'), $startTijd->format('i'), $startTijd->format('s'));
|
$endDate = $endDate->setTime($startTijd->format('H'), $startTijd->format('i'), $startTijd->format('s'));
|
||||||
$endDateWeekday = $endDate->format('N');
|
$endDateWeekday = $endDate->format('N');
|
||||||
|
|
||||||
@@ -102,29 +101,35 @@ QUERY
|
|||||||
// Als de uitzending niet al afgelopen is, telt hij als volgende.
|
// Als de uitzending niet al afgelopen is, telt hij als volgende.
|
||||||
// Dit gebeurt als de uitzending later vandaag is of nu loopt.
|
// Dit gebeurt als de uitzending later vandaag is of nu loopt.
|
||||||
if($endOfBroadcast >= $now) {
|
if($endOfBroadcast >= $now) {
|
||||||
$next[] = $endDate;
|
|
||||||
$endDate = $endDate->sub($ONE_WEEK);
|
$endDate = $endDate->sub($ONE_WEEK);
|
||||||
$endOfBroadcast = $endOfBroadcast->sub($ONE_WEEK);
|
$endOfBroadcast = $endOfBroadcast->sub($ONE_WEEK);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($broadcast->startdate == null) || ($broadcast->startdate <= $endDate)) {
|
if((($broadcast->startdate == null) || ($broadcast->startdate <= $endDate))
|
||||||
$recent[] = $endDate;
|
&& (($broadcast->enddate == null) || ($broadcast->enddate >= $endDate->setTime(0,0,0)))) {
|
||||||
|
$recent[] = ['time' => $endDate, 'suffix' => $broadcast->suffix, 'isSpecial' => ($broadcast->priority < 2)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$previous = $endDate->sub($ONE_WEEK);
|
$previous = $endDate->sub($ONE_WEEK);
|
||||||
if(($broadcast->startdate == null) || ($broadcast->startdate <= $previous)) {
|
if((($broadcast->startdate == null) || ($broadcast->startdate <= $previous))
|
||||||
$recent[] = $previous;
|
&& (($broadcast->enddate == null) || ($broadcast->enddate >= $previous->setTime(0,0,0)))) {
|
||||||
|
$recent[] = ['time' => $previous, 'suffix' => $broadcast->suffix, 'isSpecial' => ($broadcast->priority < 2)];
|
||||||
}
|
}
|
||||||
|
|
||||||
$following = $endDate->add($ONE_WEEK);
|
$following = $endDate->add($ONE_WEEK);
|
||||||
if(($broadcast->enddate == null) || ($broadcast->enddate >= $following)) {
|
if(($broadcast->enddate == null) || ($broadcast->enddate->setTime(23,59,59) > $following)) {
|
||||||
$next[] = $following;
|
if($following < $now) {
|
||||||
|
$isCurrent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$next[] = ['time' => $following, 'suffix' => $broadcast->suffix, 'isSpecial' => ($broadcast->priority < 2)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort($next);
|
sort($next);
|
||||||
rsort($recent);
|
rsort($recent);
|
||||||
return ['recent' => array_splice($recent, 0, 2), 'next' => array_splice($next, 0, 1), 'iscurrent' => $isCurrent];
|
return ['recent' => array_reverse(array_splice($recent, 0, 2)), 'next' => $next, 'iscurrent' => $isCurrent];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,7 +167,6 @@ QUERY
|
|||||||
|
|
||||||
$oneWeek = \DateInterval::createFromDateString('1 week');
|
$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')]);
|
||||||
$programmaInfo = [];
|
$programmaInfo = [];
|
||||||
@@ -171,6 +175,7 @@ QUERY
|
|||||||
$startEinde = [];
|
$startEinde = [];
|
||||||
$startMaandag = $start->modify('Monday this week');
|
$startMaandag = $start->modify('Monday this week');
|
||||||
foreach($programmas as $programma) {
|
foreach($programmas as $programma) {
|
||||||
|
if($programma->suffix) $programma->name .= ' ' . $programma->suffix;
|
||||||
$programmaInfo[$programma->id] = new \Model\Program($programma);
|
$programmaInfo[$programma->id] = new \Model\Program($programma);
|
||||||
|
|
||||||
$programmaStart = $startMaandag->add(\DateInterval::createFromDateString(($programma->startday - 1) % 7 . ' days'));
|
$programmaStart = $startMaandag->add(\DateInterval::createFromDateString(($programma->startday - 1) % 7 . ' days'));
|
||||||
@@ -193,7 +198,7 @@ QUERY
|
|||||||
|
|
||||||
while($programmaStart < $einde) {
|
while($programmaStart < $einde) {
|
||||||
if((($programma->startdate == null) || ($programmaStart >= new \DateTime($programma->startdate)))
|
if((($programma->startdate == null) || ($programmaStart >= new \DateTime($programma->startdate)))
|
||||||
&& (($programma->enddate == null) || ($programmaStart <= new \DateTime($programma->enddate)))
|
&& (($programma->enddate == null) || ($programmaStart <= (new \DateTimeImmutable($programma->enddate))->setTime(23,59,59)))
|
||||||
&& (($programmaEinde >= $start) && ($programmaStart <= $einde)))
|
&& (($programmaEinde >= $start) && ($programmaStart <= $einde)))
|
||||||
{
|
{
|
||||||
$startEinde[] = [$programmaStart, PROGRAMMA_START, $programma];
|
$startEinde[] = [$programmaStart, PROGRAMMA_START, $programma];
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class Program extends Model {
|
|||||||
public $name;
|
public $name;
|
||||||
public $description;
|
public $description;
|
||||||
public $email;
|
public $email;
|
||||||
|
public $isSpecial;
|
||||||
|
|
||||||
// TODO: Implementeren
|
// TODO: Implementeren
|
||||||
public $hosts;
|
public $hosts;
|
||||||
@@ -15,6 +16,9 @@ class Program extends Model {
|
|||||||
public function __construct($data) {
|
public function __construct($data) {
|
||||||
parent::__construct($data);
|
parent::__construct($data);
|
||||||
|
|
||||||
$this->email = explode(',', $data->email);
|
$this->isSpecial = ($data->priority < 2);
|
||||||
|
if(($mailComma = strpos($data->email, ',')) !== false) {
|
||||||
|
$this->email = substr($data->email, 0, $mailComma);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user