From f6c0270d40f6730fe1e1820f2866b08792df1db6 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 10 Dec 2016 18:22:34 +0100 Subject: rewrite data-model so that every configuration option is accessed through the conference --- model/Conference.php | 84 ++++++++++++++++++++++++++++++++++++++++++-- model/Conferences.php | 67 +++++++++++++++-------------------- model/Feedback.php | 22 +++++++----- model/GenericConference.php | 5 +++ model/ModelBase.php | 20 +++++------ model/Overview.php | 15 ++++++-- model/Relive.php | 17 +++++++-- model/Room.php | 85 +++++++++++++++++++-------------------------- model/RoomSelection.php | 10 +++--- model/RoomTab.php | 8 +++-- model/Schedule.php | 39 +++++++++++++-------- model/Subtitles.php | 21 ++++++++--- 12 files changed, 250 insertions(+), 143 deletions(-) (limited to 'model') diff --git a/model/Conference.php b/model/Conference.php index c6afa98..07d72dd 100644 --- a/model/Conference.php +++ b/model/Conference.php @@ -2,6 +2,18 @@ class Conference extends ModelBase { + private $slug; + + public function __construct($config, $slug) + { + parent::__construct($config); + $this->slug = $slug; + } + + public function getSlug() { + return $this->slug; + } + public function getTitle() { return $this->get('CONFERENCE.TITLE', 'C3VOC'); } @@ -20,6 +32,14 @@ class Conference extends ModelBase return !$this->hasBegun() || $this->hasEnded(); } + public function startsAt() { + return $this->get('CONFERENCE.STARTS_AT'); + } + + public function endsAt() { + return $this->get('CONFERENCE.ENDS_AT'); + } + public function hasBegun() { // on the preview-domain all conferences are always open if($this->isPreviewEnabled()) @@ -101,10 +121,10 @@ class Conference extends ModelBase } public function getLink() { - return url_params(); + return forceslash($this->getSlug()).url_params(); } public function getAboutLink() { - return 'about/'.url_params(); + return joinpath([$this->getSlug(), 'about']).url_params(); } public function hasRelive() { @@ -112,12 +132,26 @@ class Conference extends ModelBase } public function getReliveUrl() { if($this->has('CONFERENCE.RELIVE_JSON')) - return 'relive/'.url_params(); + return joinpath([$this->getSlug(), 'relive']).url_params(); else return null; } + public function hasFeedback() { + return $this->has('FEEDBACK'); + } + public function getFeedbackUrl() { + return joinpath([$this->getSlug(), 'feedback']).url_params(); + } + public function getFeedbackReadUrl() { + return joinpath([$this->getSlug(), 'feedback', 'read']).url_params(); + } + + public function getScheduleJsonUrl() { + return joinpath([$this->getSlug(), 'schedule.json']).url_params(); + } + public function hasBannerHtml() { return $this->has('CONFERENCE.BANNER_HTML'); } @@ -131,4 +165,48 @@ class Conference extends ModelBase public function getFooterHtml() { return $this->get('CONFERENCE.FOOTER_HTML'); } + + + public function getRooms() + { + $rooms = array(); + foreach($this->get('ROOMS') as $slug => $room) + $rooms[] = $this->getRoom($slug); + + return $rooms; + } + + public function getRoomIfExists($room) + { + if($this->hasRoom($room)) + return $this->getRoom($room); + + return null; + } + + public function hasRoom($slug) + { + return $this->has('ROOMS.'.$slug); + } + + public function getRoom($room) { + return new Room($this, $room); + } + + + public function getFeedback() { + return new Feedback($this); + } + public function getSchedule() { + return new Schedule($this); + } + public function getSubtitles() { + return new Subtitles($this); + } + public function getOverview() { + return new Overview($this); + } + public function getRelive() { + return new Relive($this); + } } diff --git a/model/Conferences.php b/model/Conferences.php index 461186f..4919345 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -4,27 +4,38 @@ class Conferences extends ModelBase { const MANDATOR_DIR = 'configs/conferences/'; + public static function listConferences() { + $directories = scandir(forceslash(Conferences::MANDATOR_DIR)); + $conferences = array_filter($directories, function($dirname) { + return $dirname[0] != '.'; + }); + + return $conferences; + } + public static function getConferences() { $conferences = []; - foreach(scandir(forceslash(Conferences::MANDATOR_DIR)) as $el) + foreach(Conferences::listConferences() as $conference) { - if($el[0] == '.') - continue; - - $conferences[$el] = Conferences::getConferenceInformation($el); + try { + $conferences[$conference] = Conferences::getConference($conference); + } + catch(Exception $e) { + // ignore unloadable conferences + } } return $conferences; } public static function getConferencesCount() { - return count(Conferences::getConferences()); + return count(Conferences::listConferences()); } public static function getActiveConferences() { return array_values(array_filter( Conferences::getConferences(), - function($info) { - return $info['active']; + function($conference) { + return !$conference->isClosed(); } )); } @@ -37,7 +48,7 @@ class Conferences extends ModelBase $sorted = Conferences::getConferences(); usort($sorted, function($a, $b) { - return @$b['CONFIG']['CONFERENCE']['STARTS_AT'] - @$a['CONFIG']['CONFERENCE']['STARTS_AT']; + return $b->startsAt() - $a->endsAt(); }); return $sorted; @@ -47,7 +58,7 @@ class Conferences extends ModelBase $sorted = Conferences::getConferencesSorted(); $finished = array_values(array_filter($sorted, function($c) { - return @$c['CONFIG']['CONFERENCE']['ENDS_AT'] < time(); + return $c->hasEnded(); })); return $finished; @@ -58,33 +69,16 @@ class Conferences extends ModelBase } public static function exists($mandator) { - return array_key_exists($mandator, Conferences::getConferences()); + return in_array($mandator, Conferences::listConferences()); } - public static function getConferenceInformation($mandator) { - if(isset($GLOBALS['CONFIG'])) - $saved_config = $GLOBALS['CONFIG']; - - Conferences::load($mandator); - $conf = new Conference(); - $info = [ - 'slug' => $mandator, - 'link' => forceslash($mandator).url_params(), - 'active' => !$conf->isClosed(), - 'title' => $conf->getTitle(), - 'description' => $conf->getDescription(), - - 'relive' => $conf->hasRelive() ? forceslash($mandator).$conf->getReliveUrl() : null, - 'releases' => $conf->hasReleases() ? $conf->getReleasesUrl() : null, - - 'CONFIG' => $GLOBALS['CONFIG'], - ]; - unset($GLOBALS['CONFIG']); - - if(isset($saved_config)) - $GLOBALS['CONFIG'] = $saved_config; + public static function loadConferenceConfig($mandator) { + $config = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'; + return include($config); + } - return $info; + public static function getConference($mandator) { + return new Conference(Conferences::loadConferenceConfig($mandator), $mandator); } public static function hasCustomStyles($mandator) { @@ -96,9 +90,4 @@ class Conferences extends ModelBase public static function getCustomStylesDir($mandator) { return forceslash(Conferences::MANDATOR_DIR).forceslash($mandator); } - - public static function load($mandator) { - include(forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php'); - return isset($GLOBALS['CONFIG']); - } } diff --git a/model/Feedback.php b/model/Feedback.php index 578650a..9475fe8 100644 --- a/model/Feedback.php +++ b/model/Feedback.php @@ -1,12 +1,16 @@ has('FEEDBACK'); + private $conference; + + public function __construct(Conference $conference) + { + $this->conference = $conference; } - public function getUrl() { - return 'feedback/'; + + public function getConference() { + return $this->conference; } public function validate($info) @@ -23,7 +27,7 @@ class Feedback extends ModelBase public function store($info) { - $db = new PDO($this->get('FEEDBACK.DSN')); + $db = new PDO($this->getConference()->get('FEEDBACK.DSN')); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stm = $db->prepare(' @@ -50,8 +54,8 @@ class Feedback extends ModelBase { return isset($_SERVER['PHP_AUTH_USER']) && - $_SERVER['PHP_AUTH_USER'] == $this->get('FEEDBACK.USERNAME') && - $_SERVER['PHP_AUTH_PW'] == $this->get('FEEDBACK.PASSWORD'); + $_SERVER['PHP_AUTH_USER'] == $this->getConference()->get('FEEDBACK.USERNAME') && + $_SERVER['PHP_AUTH_PW'] == $this->getConference()->get('FEEDBACK.PASSWORD'); } public function requestLogin() @@ -64,7 +68,7 @@ class Feedback extends ModelBase public function read($from, $to) { - $db = new PDO($this->get('FEEDBACK.DSN')); + $db = new PDO($this->getConference()->get('FEEDBACK.DSN')); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stm = $db->prepare(' diff --git a/model/GenericConference.php b/model/GenericConference.php index 5f134fc..63faf8f 100644 --- a/model/GenericConference.php +++ b/model/GenericConference.php @@ -2,6 +2,11 @@ class GenericConference extends Conference { + public function __construct() + { + $this->config = null; + } + public function hasBegun() { return true; } diff --git a/model/ModelBase.php b/model/ModelBase.php index 7b1370b..41f329b 100644 --- a/model/ModelBase.php +++ b/model/ModelBase.php @@ -2,14 +2,17 @@ class ModelBase { - protected function has($keychain) + protected $config; + public function __construct($config) { - return ModelBase::_has($GLOBALS['CONFIG'], $keychain); + $this->config = $config; } - protected static function staticHas($keychain) + + public function has($keychain) { - return ModelBase::_has($GLOBALS['CONFIG'], $keychain); + return ModelBase::_has($this->config, $keychain); } + private static function _has($array, $keychain) { if(!is_array($keychain)) @@ -25,14 +28,11 @@ class ModelBase return ModelBase::_has($array[$key], array_slice($keychain, 1)); } - protected function get($keychain, $default = null) + public function get($keychain, $default = null) { - return ModelBase::_get($GLOBALS['CONFIG'], $keychain, $default); - } - protected static function staticGet($keychain, $default = null) - { - return ModelBase::_get($GLOBALS['CONFIG'], $keychain, $default); + return ModelBase::_get($this->config, $keychain, $default); } + private static function _get($array, $keychain, $default) { if(!is_array($keychain)) diff --git a/model/Overview.php b/model/Overview.php index 03ef8b4..8a467bc 100644 --- a/model/Overview.php +++ b/model/Overview.php @@ -1,16 +1,25 @@ conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function getGroups() { $groups = array(); - foreach($this->get('OVERVIEW.GROUPS') as $group => $rooms) + foreach($this->getConference()->get('OVERVIEW.GROUPS') as $group => $rooms) { foreach($rooms as $room) { try { - $groups[$group][] = new Room($room); + $groups[$group][] = $this->getConference()->getRoom($room); } catch(NotFoundException $e) { diff --git a/model/Relive.php b/model/Relive.php index d0e7522..ca32f19 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -1,16 +1,27 @@ conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function isEnabled() { // having CONFERENCE.RELIVE is not enough! - return $this->has('CONFERENCE.RELIVE_JSON'); + return $this->getConference()->has('CONFERENCE.RELIVE_JSON'); } public function getJsonUrl() { - return $this->get('CONFERENCE.RELIVE_JSON'); + return $this->getConference()->get('CONFERENCE.RELIVE_JSON'); } public function getTalks() diff --git a/model/Room.php b/model/Room.php index df3d92c..aa72630 100644 --- a/model/Room.php +++ b/model/Room.php @@ -1,107 +1,92 @@ conference = $conference; + if(preg_match('/[^a-z0-9_\-]/i', $slug)) throw new Exception('Room Slug contains invalid Characters: "'.$slug.'"'); - if(! $this->has('ROOMS.'.$slug)) + if(!$this->getConference()->hasRoom($slug)) throw new NotFoundException('Room '.$slug); $this->slug = $slug; } - public static function exists($slug) - { - return ModelBase::staticHas('ROOMS.'.$slug); - } - - public static function createIfExists($room) - { - if(Room::exists($room)) - return new Room($room); - - return null; - } - - public static function rooms() - { - $rooms = array(); - foreach(ModelBase::staticGet('ROOMS') as $slug => $room) - $rooms[] = new Room($slug); - return $rooms; + public function getConference() { + return $this->conference; } - public function getSlug() { return $this->slug; } public function getThumb() { - return '../thumbs/'.$this->getStream().'.png'; + return joinpath(['/', 'thumbs', $this->getStream().'.png']); } public function getLink() { - return rawurlencode($this->getSlug()).'/'.url_params(); + return joinpath([$this->getConference()->getSlug(), $this->getSlug()]).url_params(); } public function getStream() { - return $this->get('ROOMS.'.$this->getSlug().'.STREAM', $this->getSlug()); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.STREAM', $this->getSlug()); } public function getScheduleName() { - return $this->get('ROOMS.'.$this->getSlug().'.SCHEDULE_NAME', $this->getSlug()); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SCHEDULE_NAME', $this->getSlug()); } public function getDisplay() { - return $this->get('ROOMS.'.$this->getSlug().'.DISPLAY', $this->getSlug()); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.DISPLAY', $this->getSlug()); } public function hasStereo() { - return $this->get('ROOMS.'.$this->getSlug().'.STEREO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.STEREO'); } public function hasPreview() { - return $this->get('ROOMS.'.$this->getSlug().'.PREVIEW'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.PREVIEW'); } public function requestsWide() { - return $this->get('ROOMS.'.$this->getSlug().'.WIDE'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.WIDE'); } public function hasSchedule() { - return $this->get('ROOMS.'.$this->getSlug().'.SCHEDULE') && $this->has('SCHEDULE'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SCHEDULE') && $this->getConference()->has('SCHEDULE'); } public function hasSubtitles() { return - $this->get('ROOMS.'.$this->getSlug().'.SUBTITLES') && - $this->has('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID') && - $this->has('SUBTITLES'); + $this->getConference()->get('ROOMS.'.$this->getSlug().'.SUBTITLES') && + $this->getConference()->has('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID') && + $this->getConference()->has('SUBTITLES'); } public function getSubtitlesRoomId() { - return $this->get('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SUBTITLES_ROOM_ID'); } public function hasFeedback() { - return $this->get('ROOMS.'.$this->getSlug().'.FEEDBACK') && $this->has('FEEDBACK'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.FEEDBACK') && $this->getConference()->has('FEEDBACK'); } public function hasTwitter() { - return $this->get('ROOMS.'.$this->getSlug().'.TWITTER') && $this->has('TWITTER'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TWITTER') && $this->getConference()->has('TWITTER'); } public function getTwitterDisplay() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.DISPLAY', $this->get('TWITTER.DISPLAY')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.DISPLAY', $this->getConference()->get('TWITTER.DISPLAY')), $this->getSlug() ); } @@ -115,26 +100,26 @@ class Room extends ModelBase public function getTwitterText() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.TEXT', $this->get('TWITTER.TEXT')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.TEXT', $this->getConference()->get('TWITTER.TEXT')), $this->getSlug() ); } public function hasIrc() { - return $this->get('ROOMS.'.$this->getSlug().'.IRC') && $this->has('IRC'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.IRC') && $this->getConference()->has('IRC'); } public function getIrcDisplay() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.DISPLAY', $this->get('IRC.DISPLAY')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.DISPLAY', $this->getConference()->get('IRC.DISPLAY')), $this->getSlug() ); } public function getIrcUrl() { return sprintf( - $this->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.URL', $this->get('IRC.URL')), + $this->getConference()->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.URL', $this->getConference()->get('IRC.URL')), rawurlencode($this->getSlug()) ); } @@ -146,16 +131,16 @@ class Room extends ModelBase public function hasEmbed() { - return $this->get('ROOMS.'.$this->getSlug().'.EMBED') && $this->get('EMBED'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.EMBED') && $this->getConference()->get('EMBED'); } public function hasSdVideo() { - return $this->get('ROOMS.'.$this->getSlug().'.SD_VIDEO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SD_VIDEO'); } public function hasHdVideo() { - return $this->get('ROOMS.'.$this->getSlug().'.HD_VIDEO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.HD_VIDEO'); } public function hasVideo() { @@ -163,19 +148,19 @@ class Room extends ModelBase } public function hasAudio() { - return $this->get('ROOMS.'.$this->getSlug().'.AUDIO'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.AUDIO'); } public function hasSlides() { - return $this->get('ROOMS.'.$this->getSlug().'.SLIDES'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SLIDES'); } public function hasMusic() { - return $this->get('ROOMS.'.$this->getSlug().'.MUSIC'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.MUSIC'); } public function hasTranslation() { - return $this->get('ROOMS.'.$this->getSlug().'.TRANSLATION'); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TRANSLATION'); } public function getSelectionNames() diff --git a/model/RoomSelection.php b/model/RoomSelection.php index 9f0b16d..9211c31 100644 --- a/model/RoomSelection.php +++ b/model/RoomSelection.php @@ -20,16 +20,18 @@ class RoomSelection public function getLink() { + $path = [$this->getRoom()->getConference()->getSlug(), $this->getRoom()->getSlug()]; + $selection = $this->getRoom()->getSelectionNames(); - if($selection[0] == $this->getSelection()) - return rawurlencode($this->getRoom()->getSlug()).'/'; + if($selection[0] != $this->getSelection()) + $path[] = $this->getSelection(); - return rawurlencode($this->getRoom()->getSlug()).'/'.rawurlencode($this->getSelection()).'/'; + return joinpath($path).url_params(); } public function getTranslatedLink() { - return $this->getLink().'translated/'; + return joinpath([$this->getLink(), 'translated']); } public function getDisplay() diff --git a/model/RoomTab.php b/model/RoomTab.php index 16a8359..c7b564f 100644 --- a/model/RoomTab.php +++ b/model/RoomTab.php @@ -20,11 +20,13 @@ class RoomTab public function getLink() { + $path = [$this->getRoom()->getConference()->getSlug(), $this->getRoom()->getSlug()]; + $tabs = $this->getRoom()->getTabNames(); - if($tabs[0] == $this->getTab()) - return rawurlencode($this->getRoom()->getSlug()).'/'.url_params(); + if($tabs[0] != $this->getTab()) + $path[] = $this->getTab(); - return rawurlencode($this->getRoom()->getSlug()).'/'.rawurlencode($this->getTab()).'/'.url_params(); + return joinpath($path).url_params(); } public function getDisplay() diff --git a/model/Schedule.php b/model/Schedule.php index c0ff69b..0b789f2 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -1,26 +1,37 @@ conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function isEnabled() { - return $this->has('SCHEDULE'); + return $this->getConference()->has('SCHEDULE'); } private function isRoomFiltered($room) { - if(!$this->has('SCHEDULE.ROOMFILTER')) + if(!$this->getConference()->has('SCHEDULE.ROOMFILTER')) return false; - $rooms = $this->get('SCHEDULE.ROOMFILTER'); + $rooms = $this->getConference()->get('SCHEDULE.ROOMFILTER'); return !in_array($room, $rooms); } public function getSimulationOffset() { - return $this->get('SCHEDULE.SIMULATE_OFFSET', 0); + return $this->getConference()->get('SCHEDULE.SIMULATE_OFFSET', 0); } public function getScale() { - return floatval($this->get('SCHEDULE.SCALE', 7)); + return floatval($this->getConference()->get('SCHEDULE.SCALE', 7)); } private function fetchSchedule() @@ -35,7 +46,7 @@ class Schedule extends ModelBase $schedule = file_get_contents($this->getScheduleUrl(), false, $context); if(!$schedule) - throw new ScheduleException("Error Downloading Schedule from ".$this->getScheduleUrl()); + throw new ScheduleException("Error Downloading Schedule from ".$this->getConference()->getScheduleUrl()); return simplexml_load_string($schedule); } @@ -49,10 +60,10 @@ class Schedule extends ModelBase } catch(Exception $e) { - return array(); + return array('_error' => (string)$e); } - $mapping = $this->getScheduleToRoomSlugMapping(); + $mapping = $this->getConference()->getScheduleToRoomSlugMapping(); $program = array(); // re-calculate day-ends @@ -220,10 +231,10 @@ class Schedule extends ModelBase } - if($this->has('SCHEDULE.ROOMFILTER')) + if($this->getConference()->has('SCHEDULE.ROOMFILTER')) { // sort by roomfilter - $roomfilter = $this->get('SCHEDULE.ROOMFILTER'); + $roomfilter = $this->getConference()->get('SCHEDULE.ROOMFILTER'); // map roomfilter-rooms to room-slugs $roomfilter = array_map(function($e) use ($mapping) { @@ -246,7 +257,7 @@ class Schedule extends ModelBase public function getDurationSum() { $sum = 0; - $schedule = $this->getSchedule(); + $schedule = $this->getConference()->getSchedule(); foreach(reset($schedule) as $event) $sum += $event['duration']; @@ -263,13 +274,13 @@ class Schedule extends ModelBase private function getScheduleUrl() { - return $this->get('SCHEDULE.URL'); + return $this->getConference()->get('SCHEDULE.URL'); } public function getScheduleToRoomSlugMapping() { $mapping = array(); - foreach($this->get('ROOMS') as $slug => $room) + foreach($this->getConference()->get('ROOMS') as $slug => $room) { if(isset($room['SCHEDULE_NAME'])) $mapping[ $room['SCHEDULE_NAME'] ] = $slug; diff --git a/model/Subtitles.php b/model/Subtitles.php index e1878f2..1d401b8 100644 --- a/model/Subtitles.php +++ b/model/Subtitles.php @@ -1,14 +1,25 @@ conference = $conference; + } + + public function getConference() { + return $this->conference; + } + public function isEnabled() { - return $this->has('SUBTITLES'); + return $this->getConference()->has('SUBTITLES'); } public function getEnabledRooms($slug) { $rooms = []; - foreach(Room::rooms() as $room) + foreach($this->getConference()->getOverview()->getRooms() as $room) { if($room->hasSubtitles()) $rooms[] = $room; @@ -18,9 +29,9 @@ class Subtitles extends ModelBase } public function getPrimusURL() { - return $this->get('SUBTITLES.PRIMUS_URL'); + return $this->getConference()->get('SUBTITLES.PRIMUS_URL'); } public function getFrontendURL() { - return $this->get('SUBTITLES.FRONTEND_URL'); + return $this->getConference()->get('SUBTITLES.FRONTEND_URL'); } } -- cgit v1.2.3 From b137ccc18be2f8addf10b0db5257da8c3767dba9 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 10 Dec 2016 18:24:03 +0100 Subject: repair indentation --- model/Relive.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'model') diff --git a/model/Relive.php b/model/Relive.php index ca32f19..7f0e747 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -34,22 +34,22 @@ class Relive $mapping = $this->getScheduleToRoomMapping(); - usort($talks, function($a, $b) { - // first, make sure that live talks are always on top - if($a['status'] == 'live' && $b['status'] != 'live') { - return -1; - } else if($a['status'] != 'live' && $b['status'] == 'live') { - return 1; - } else if($a['status'] == 'live' && $b['status'] == 'live') { - // sort live talks by room - - return strcmp($a['room'], $b['room']); - } - - // all other talks get sorted by their name - - return strcmp($a['title'], $b['title']); - }); + usort($talks, function($a, $b) { + // first, make sure that live talks are always on top + if($a['status'] == 'live' && $b['status'] != 'live') { + return -1; + } + else if($a['status'] != 'live' && $b['status'] == 'live') { + return 1; + } + else if($a['status'] == 'live' && $b['status'] == 'live') { + // sort live talks by room + return strcmp($a['room'], $b['room']); + } + + // all other talks get sorted by their name + return strcmp($a['title'], $b['title']); + }); $talks_by_id = array(); foreach ($talks as $talk) -- cgit v1.2.3 From f499d4d53a31011d523d8ebaf8c4f7f0fcea43b7 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 20:36:46 +0100 Subject: repair schedule view --- model/Schedule.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'model') diff --git a/model/Schedule.php b/model/Schedule.php index 0b789f2..eb9fe05 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -54,16 +54,9 @@ class Schedule public function getSchedule() { // download schedule-xml - try - { - $schedule = $this->fetchSchedule(); - } - catch(Exception $e) - { - return array('_error' => (string)$e); - } + $schedule = $this->fetchSchedule(); - $mapping = $this->getConference()->getScheduleToRoomSlugMapping(); + $mapping = $this->getScheduleToRoomSlugMapping(); $program = array(); // re-calculate day-ends @@ -257,7 +250,7 @@ class Schedule public function getDurationSum() { $sum = 0; - $schedule = $this->getConference()->getSchedule(); + $schedule = $this->getSchedule(); foreach(reset($schedule) as $event) $sum += $event['duration']; -- cgit v1.2.3 From a38a7fcc85c99fa8bd17dd591a5dcad07577c306 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 19:56:36 +0100 Subject: conferences does not use ModelBase --- model/Conferences.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'model') diff --git a/model/Conferences.php b/model/Conferences.php index 4919345..77069ad 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -1,6 +1,6 @@ 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 +68,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 +91,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; } diff --git a/model/Conferences.php b/model/Conferences.php index 2dc9f35..8de4029 100644 --- a/model/Conferences.php +++ b/model/Conferences.php @@ -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; -- cgit v1.2.3 From 4c9cc1f8e6bcb8c68e5106437fcb41bbbc380885 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 20:27:58 +0100 Subject: list conferences sorted on startpage --- model/Conferences.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'model') diff --git a/model/Conferences.php b/model/Conferences.php index 8de4029..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(); } -- cgit v1.2.3 From 6e0f7423769174b83d6b5618db7c33d54967099a Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 21:17:30 +0100 Subject: download files of forced-open conferences --- model/Conference.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'model') diff --git a/model/Conference.php b/model/Conference.php index ae5ab41..be62fdb 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,6 +32,10 @@ class Conference extends ModelBase return !$this->hasBegun() || $this->hasEnded(); } + public function isOpen() { + return !$this->isClosed(); + } + public function startsAt() { if(!$this->has('CONFERENCE.STARTS_AT')) return null; -- cgit v1.2.3 From 284878f0f9917b55359cd464b86508cacc472653 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 21:46:01 +0100 Subject: add cache-file getters and download preparations --- model/Conference.php | 4 ++++ model/Relive.php | 5 +++++ model/Schedule.php | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'model') diff --git a/model/Conference.php b/model/Conference.php index be62fdb..6c14746 100644 --- a/model/Conference.php +++ b/model/Conference.php @@ -221,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/Relive.php b/model/Relive.php index 7f0e747..5676b62 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -24,6 +24,11 @@ class Relive return $this->getConference()->get('CONFERENCE.RELIVE_JSON'); } + public function getJsonCache() + { + return sprintf('/tmp/relive-cache-%s', $this->getConference()->getSlug()); + } + public function getTalks() { if(!file_exists($this->getJsonUrl())) diff --git a/model/Schedule.php b/model/Schedule.php index eb9fe05..4032ecb 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -265,11 +265,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', $this->getConference()->getSlug()); + } + public function getScheduleToRoomSlugMapping() { $mapping = array(); -- cgit v1.2.3 From 9c7bccc3f2cc226cd5043752403e4c5d39c8b5b5 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 11 Dec 2016 21:46:54 +0100 Subject: access relive config through relive-model --- model/Conference.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'model') diff --git a/model/Conference.php b/model/Conference.php index 6c14746..8d387a0 100644 --- a/model/Conference.php +++ b/model/Conference.php @@ -140,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 -- cgit v1.2.3 From 3384e963da66e9089b71c546750c8981be8c6ed8 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sat, 17 Dec 2016 14:11:47 +0100 Subject: change storage paths according to issue description --- model/Relive.php | 2 +- model/Schedule.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'model') diff --git a/model/Relive.php b/model/Relive.php index 5676b62..1e8266a 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -26,7 +26,7 @@ class Relive public function getJsonCache() { - return sprintf('/tmp/relive-cache-%s', $this->getConference()->getSlug()); + return sprintf('/tmp/relive-cache-%s.json', $this->getConference()->getSlug()); } public function getTalks() diff --git a/model/Schedule.php b/model/Schedule.php index 4032ecb..6536864 100644 --- a/model/Schedule.php +++ b/model/Schedule.php @@ -272,7 +272,7 @@ class Schedule public function getScheduleCache() { - return sprintf('/tmp/schedule-cache-%s', $this->getConference()->getSlug()); + return sprintf('/tmp/schedule-cache-%s.xml', $this->getConference()->getSlug()); } public function getScheduleToRoomSlugMapping() -- cgit v1.2.3 From da739f3b60a30d5dd5c7877742f8b5c292f25f46 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 18 Dec 2016 10:37:10 +0100 Subject: use the new cache-files for viewing --- model/Relive.php | 2 +- model/Schedule.php | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'model') diff --git a/model/Relive.php b/model/Relive.php index 1e8266a..542836d 100644 --- a/model/Relive.php +++ b/model/Relive.php @@ -31,7 +31,7 @@ class Relive 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 6536864..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); } -- cgit v1.2.3 From 1e6353b9fa405d9c85833a77e329be88cac09fcc Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 18 Dec 2016 13:33:09 +0100 Subject: change default of schedule-name to display-name --- model/Room.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'model') diff --git a/model/Room.php b/model/Room.php index aa72630..782c91d 100644 --- a/model/Room.php +++ b/model/Room.php @@ -40,7 +40,7 @@ class Room } public function getScheduleName() { - return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SCHEDULE_NAME', $this->getSlug()); + return $this->getConference()->get('ROOMS.'.$this->getSlug().'.SCHEDULE_NAME', $this->getDisplay()); } public function getDisplay() { -- cgit v1.2.3