From f7d9d592745d1cb5cb2de76ed6ae99be974f1807 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Mon, 30 Mar 2015 16:20:30 +0200 Subject: Implement MVT Pattern based on simple Config options --- model/Room.php | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 192 insertions(+), 1 deletion(-) (limited to 'model/Room.php') diff --git a/model/Room.php b/model/Room.php index c7e51f9..f428d87 100644 --- a/model/Room.php +++ b/model/Room.php @@ -35,11 +35,202 @@ class Room extends ModelBase + public function hasStereo() { + return $this->get('ROOMS.'.$this->getSlug().'.STEREO'); + } + public function hasPreview() { - return get('ROOMS.'.$this->getSlug().'.PREVIEW'); + return $this->get('ROOMS.'.$this->getSlug().'.PREVIEW'); } public function hasSchedule() { return $this->get('ROOMS.'.$this->getSlug().'.SCHEDULE') && $this->has('SCHEDULE'); } + + public function hasFeedback() { + return $this->get('ROOMS.'.$this->getSlug().'.FEEDBACK') && $this->has('FEEDBACK'); + } + + + public function hasTwitter() { + return $this->get('ROOMS.'.$this->getSlug().'.TWITTER') && $this->has('TWITTER'); + } + + public function getTwitterDisplay() { + return sprintf( + $this->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.DISPLAY', $this->get('TWITTER.DISPLAY')), + $this->getSlug() + ); + } + + public function getTwitterUrl() { + return sprintf( + 'https://twitter.com/intent/tweet?text=%s', + rawurlencode($this->getTwitterText()) + ); + } + + public function getTwitterText() { + return sprintf( + $this->get('ROOMS.'.$this->getSlug().'.TWITTER_CONFIG.TEXT', $this->get('TWITTER.TEXT')), + $this->getSlug() + ); + } + + + public function hasIrc() { + return $this->get('ROOMS.'.$this->getSlug().'.IRC') && $this->has('IRC'); + } + + public function getIrcDisplay() { + return sprintf( + $this->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.DISPLAY', $this->get('IRC.DISPLAY')), + $this->getSlug() + ); + } + + public function getIrcUrl() { + return sprintf( + $this->get('ROOMS.'.$this->getSlug().'.IRC_CONFIG.URL', $this->get('IRC.URL')), + rawurlencode($this->getSlug()) + ); + } + + + public function hasChat() { + return $this->hasTwitter() || $this->hasIrc(); + } + + + public function hasSdVideo() { + return $this->get('ROOMS.'.$this->getSlug().'.SD_VIDEO'); + } + + public function hasHdVideo() { + return $this->get('ROOMS.'.$this->getSlug().'.HD_VIDEO'); + } + + public function hasVideo() { + return $this->hasSdVideo() || $this->hasHdVideo(); + } + + public function hasAudio() { + return $this->get('ROOMS.'.$this->getSlug().'.AUDIO'); + } + + public function hasSlides() { + return $this->get('ROOMS.'.$this->getSlug().'.SLIDES'); + } + + public function hasMusic() { + return $this->get('ROOMS.'.$this->getSlug().'.MUSIC'); + } + + public function hasTranslation() { + return $this->get('ROOMS.'.$this->getSlug().'.TRANSLATION'); + } + + public function getSelectionNames() + { + $selections = array(); + if($this->hasHdVideo()) + $selections[] = 'hd'; + + if($this->hasSdVideo()) + $selections[] = 'sd'; + + if($this->hasSlides()) + $selections[] = 'slides'; + + if($this->hasAudio()) + $selections[] = 'audio'; + + if($this->hasMusic()) + $selections[] = 'music'; + + return $selections; + } + + public function getTabNames() + { + $tabs = array(); + if($this->hasVideo()) + $tabs[] = 'video'; + + if($this->hasSlides()) + $tabs[] = 'slides'; + + if($this->hasAudio()) + $tabs[] = 'audio'; + + if($this->hasMusic()) + $tabs[] = 'music'; + + return $tabs; + } + + public function getSelections() + { + $selections = array(); + foreach($this->getSelectionNames() as $selection) + $selections[$tab] = $this->createSelectionObject($selection); + + return $selections; + } + + public function createSelectionObject($selection) + { + return new RoomSelection($this, $selection); + } + + public function getTabs() + { + $tabs = array(); + foreach($this->getTabNames() as $tab) + $tabs[$tab] = $this->createTabObject($tab); + + return $tabs; + } + + public function createTabObject($tab) + { + return new RoomTab($this, $tab); + } + + public function getVideoResolutions() + { + $res = array(); + if($this->hasHdVideo()) + $res[] = 'hd'; + + if($this->hasSdVideo()) + $res[] = 'sd'; + + return $res; + } + + public function selectStream($selection, $language = 'native') + { + $selections = $this->getSelectionNames(); + + // default page + if(!$selection) + $selection = $selections[0]; + + if(!in_array($selection, $selections)) + throw new NotFoundException('Selection '.$selection.' in Room '.$this->getSlug()); + + if($language == 'translated' && !$this->hasTranslation()) + throw new NotFoundException('Translated Streams of Room '.$this->getSlug()); + + return $this->createStreamObject($selection, $language); + } + + public function createStreamObject($selection, $language = 'native') + { + if($language == 'native' && $this->hasStereo()) + $language = 'stereo'; + + return new Stream($this, $selection, $language); + } } -- cgit v1.2.3