Bug fixes schedule
This commit is contained in:
@@ -10,9 +10,9 @@ ini_set('display_errors', true);
|
||||
class ProgramController extends Controller
|
||||
{
|
||||
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`.`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`
|
||||
WHERE ((`schedule`.`startdate` IS NULL) OR (`schedule`.`startdate` < :enddate)) AND
|
||||
((`schedule`.`enddate` IS NULL) OR (`schedule`.`enddate` >= :startdate)) AND
|
||||
@@ -35,7 +35,7 @@ QUERY;
|
||||
* Details over een specifiek programma, inclusief schema en podcasts
|
||||
*/
|
||||
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) {
|
||||
return abort(404);
|
||||
}
|
||||
@@ -55,12 +55,9 @@ 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`
|
||||
WHERE (schedule.`program` = :program) AND (`schedule`.`active` = 1) AND (`schedule`.`final` = 1) AND
|
||||
-- ((`schedule`.`startdate` IS NULL) OR (`schedule`.`startdate` < :enddate)) AND
|
||||
-- ((`schedule`.`enddate` IS NULL) OR (`schedule`.`enddate` >= :startdate)) AND
|
||||
1=1
|
||||
WHERE (schedule.`program` = :program) AND (`schedule`.`active` = 1) AND (`schedule`.`final` = 1)
|
||||
ORDER BY `schedule`.`priority` DESC, MOD(`startday` + 6, 7) + 1, `schedule`.`starttime` ASC
|
||||
QUERY
|
||||
, ['program' => $program->id] );
|
||||
@@ -80,8 +77,10 @@ QUERY
|
||||
// Vind voor elke regel in de uitzendmomenten de eerstvolgende en twee meest recente.
|
||||
$isCurrent = false;
|
||||
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);
|
||||
$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'));
|
||||
$endDateWeekday = $endDate->format('N');
|
||||
|
||||
@@ -102,29 +101,35 @@ QUERY
|
||||
// Als de uitzending niet al afgelopen is, telt hij als volgende.
|
||||
// Dit gebeurt als de uitzending later vandaag is of nu loopt.
|
||||
if($endOfBroadcast >= $now) {
|
||||
$next[] = $endDate;
|
||||
$endDate = $endDate->sub($ONE_WEEK);
|
||||
$endOfBroadcast = $endOfBroadcast->sub($ONE_WEEK);
|
||||
}
|
||||
|
||||
if(($broadcast->startdate == null) || ($broadcast->startdate <= $endDate)) {
|
||||
$recent[] = $endDate;
|
||||
if((($broadcast->startdate == null) || ($broadcast->startdate <= $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);
|
||||
if(($broadcast->startdate == null) || ($broadcast->startdate <= $previous)) {
|
||||
$recent[] = $previous;
|
||||
if((($broadcast->startdate == null) || ($broadcast->startdate <= $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);
|
||||
if(($broadcast->enddate == null) || ($broadcast->enddate >= $following)) {
|
||||
$next[] = $following;
|
||||
if(($broadcast->enddate == null) || ($broadcast->enddate->setTime(23,59,59) > $following)) {
|
||||
if($following < $now) {
|
||||
$isCurrent = true;
|
||||
}
|
||||
|
||||
$next[] = ['time' => $following, 'suffix' => $broadcast->suffix, 'isSpecial' => ($broadcast->priority < 2)];
|
||||
}
|
||||
}
|
||||
|
||||
sort($next);
|
||||
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');
|
||||
|
||||
|
||||
$programmas = app('db')->select(self::$SCHEDULE_SQL,
|
||||
['enddate' => $einde->format('Y-m-d'), 'startdate' => $start->format('Y-m-d')]);
|
||||
$programmaInfo = [];
|
||||
@@ -171,6 +175,7 @@ QUERY
|
||||
$startEinde = [];
|
||||
$startMaandag = $start->modify('Monday this week');
|
||||
foreach($programmas as $programma) {
|
||||
if($programma->suffix) $programma->name .= ' ' . $programma->suffix;
|
||||
$programmaInfo[$programma->id] = new \Model\Program($programma);
|
||||
|
||||
$programmaStart = $startMaandag->add(\DateInterval::createFromDateString(($programma->startday - 1) % 7 . ' days'));
|
||||
@@ -193,7 +198,7 @@ QUERY
|
||||
|
||||
while($programmaStart < $einde) {
|
||||
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)))
|
||||
{
|
||||
$startEinde[] = [$programmaStart, PROGRAMMA_START, $programma];
|
||||
|
||||
@@ -7,6 +7,7 @@ class Program extends Model {
|
||||
public $name;
|
||||
public $description;
|
||||
public $email;
|
||||
public $isSpecial;
|
||||
|
||||
// TODO: Implementeren
|
||||
public $hosts;
|
||||
@@ -15,6 +16,9 @@ class Program extends Model {
|
||||
public function __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