diff options
author | MaZderMind | 2016-12-18 10:37:58 +0100 |
---|---|---|
committer | MaZderMind | 2016-12-18 10:37:58 +0100 |
commit | 23c70f3042251675796ebff7f3568005a335fa73 (patch) | |
tree | 547688e0ef964adb2eb28e1419e62f796f28ddd6 /model | |
parent | 738878b8b060b3cfcdde2d88a1a28d5ce83e4aa7 (diff) | |
parent | da739f3b60a30d5dd5c7877742f8b5c292f25f46 (diff) |
Merge branch 'feature/20-declarative-downloading'
fixes #20
Diffstat (limited to 'model')
-rw-r--r-- | model/Conference.php | 30 | ||||
-rw-r--r-- | model/Conferences.php | 4 | ||||
-rw-r--r-- | model/Relive.php | 7 | ||||
-rw-r--r-- | model/Schedule.php | 18 |
4 files changed, 39 insertions, 20 deletions
diff --git a/model/Conference.php b/model/Conference.php index 07d72dd..8d387a0 100644 --- a/model/Conference.php +++ b/model/Conference.php @@ -19,7 +19,7 @@ class Conference extends ModelBase } public function isPreviewEnabled() { - if($GLOBALS['forceopen']) + if(@$GLOBALS['forceopen']) return true; if($this->has('PREVIEW_DOMAIN') && ($this->get('PREVIEW_DOMAIN') == $_SERVER['SERVER_NAME'])) @@ -32,12 +32,22 @@ class Conference extends ModelBase return !$this->hasBegun() || $this->hasEnded(); } + public function isOpen() { + return !$this->isClosed(); + } + public function startsAt() { - return $this->get('CONFERENCE.STARTS_AT'); + if(!$this->has('CONFERENCE.STARTS_AT')) + return null; + + return DateTime::createFromFormat('U', $this->get('CONFERENCE.STARTS_AT')); } public function endsAt() { - return $this->get('CONFERENCE.ENDS_AT'); + if(!$this->has('CONFERENCE.ENDS_AT')) + return null; + + return DateTime::createFromFormat('U', $this->get('CONFERENCE.ENDS_AT')); } public function hasBegun() { @@ -62,7 +72,8 @@ class Conference extends ModelBase } if($this->has('CONFERENCE.STARTS_AT')) { - return time() >= $this->get('CONFERENCE.STARTS_AT'); + $now = new DateTime('now'); + return $now >= $this->startsAt(); } else { return true; } @@ -84,7 +95,8 @@ class Conference extends ModelBase } if($this->has('CONFERENCE.ENDS_AT')) { - return time() >= $this->get('CONFERENCE.ENDS_AT'); + $now = new DateTime('now'); + return $now >= $this->endsAt(); } else { return false; } @@ -128,10 +140,10 @@ class Conference extends ModelBase } public function hasRelive() { - return $this->has('CONFERENCE.RELIVE_JSON'); + return $this->getRelive()->isEnabled(); } public function getReliveUrl() { - if($this->has('CONFERENCE.RELIVE_JSON')) + if($this->getRelive()->isEnabled()) return joinpath([$this->getSlug(), 'relive']).url_params(); else @@ -209,4 +221,8 @@ class Conference extends ModelBase public function getRelive() { return new Relive($this); } + + public function getExtraFiles() { + return $this->get('EXTRA_FILES', []); + } } diff --git a/model/Conferences.php b/model/Conferences.php index 2dc9f35..f930e32 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -33,7 +33,7 @@ class Conferences public static function getActiveConferences() { return array_values(array_filter( - Conferences::getConferences(), + Conferences::getConferencesSorted(), function($conference) { return !$conference->isClosed(); } @@ -48,7 +48,7 @@ class Conferences $sorted = Conferences::getConferences(); usort($sorted, function($a, $b) { - return $b->startsAt() - $a->endsAt(); + return $b->startsAt() > $a->endsAt() ? 1 : -1; }); return $sorted; diff --git a/model/Relive.php b/model/Relive.php index 7f0e747..542836d 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -24,9 +24,14 @@ class Relive return $this->getConference()->get('CONFERENCE.RELIVE_JSON'); } + public function getJsonCache() + { + return sprintf('/tmp/relive-cache-%s.json', $this->getConference()->getSlug()); + } + public function getTalks() { - if(!file_exists($this->getJsonUrl())) + if(!file_exists($this->getJsonCache())) return array(); $talks = file_get_contents($this->getJsonUrl()); diff --git a/model/Schedule.php b/model/Schedule.php index eb9fe05..b54709e 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -36,17 +36,10 @@ class Schedule private function fetchSchedule() { - $opts = array( - 'http' => array( - 'timeout' => 2, - 'user_agent' => 'C3VOC Universal Streaming-Website Backend @ '.$_SERVER['HTTP_HOST'], - ) - ); - $context = stream_context_create($opts); - $schedule = file_get_contents($this->getScheduleUrl(), false, $context); + $schedule = file_get_contents($this->getScheduleCache()); if(!$schedule) - throw new ScheduleException("Error Downloading Schedule from ".$this->getConference()->getScheduleUrl()); + throw new ScheduleException("Error Loading Schedule from ".$this->getScheduleCache()); return simplexml_load_string($schedule); } @@ -265,11 +258,16 @@ class Schedule return ((int)$parts[0] * 60 + (int)$parts[1]) * 60; } - private function getScheduleUrl() + public function getScheduleUrl() { return $this->getConference()->get('SCHEDULE.URL'); } + public function getScheduleCache() + { + return sprintf('/tmp/schedule-cache-%s.xml', $this->getConference()->getSlug()); + } + public function getScheduleToRoomSlugMapping() { $mapping = array(); |