Recent shows go back 2 weeks, next show only shows next week f or now

This commit is contained in:
2017-08-01 02:26:14 +02:00
parent 3ad71819a4
commit d04baa0367
2 changed files with 20 additions and 8 deletions

View File

@@ -203,6 +203,20 @@ QUERY;
$program->hosts[] = new \Model\ProgramHost($host);
}
$now = new \DateTimeImmutable('now');
$past = $this->createSchedule($now->add(\DateInterval::createFromDateString('-3 weeks')), $now->add(\DateInterval::createFromDateString('+1 week')));
$program->recent = [];
$program->next = [];
foreach($past['schedule'] as $item) {
if($item['program']->id == $id) {
if(($item['start'] > $now) && !($program->next)) {
$program->next = $item['start'];
} else if(($item['start'] < $now) && count($program->recent) < 2) {
$program->recent[] = $item['start'];
}
}
}
return response()->json($program);
}

View File

@@ -10,7 +10,8 @@ class Program extends Model {
public $priority;
public $hosts;
public $schedule;
public $recent;
public $next;
public function __construct($data) {
parent::__construct($data);
@@ -19,13 +20,10 @@ class Program extends Model {
$this->name .= ' ' . $data->suffix;
}
if($this->schedule && $this->schedule->next && $this->schedule->next->time) {
parent::ConvertToDateTime($this->schedule->next->time);
}
if($this->schedule && $this->schedule->recent) {
foreach($this->schedule->recent as &$recent) {
parent::ConvertToDateTime($recent->time);
parent::ConvertToDateTime($this->next);
if($this->recent && $this->recent) {
foreach($this->recent as &$recent) {
parent::ConvertToDateTime($recent);
}
}