aboutsummaryrefslogtreecommitdiff
path: root/model/Room.php
diff options
context:
space:
mode:
authorBenjamin Peter2017-12-12 14:07:49 +0100
committerGitHub2017-12-12 14:07:49 +0100
commit3229c9e8af148575d87b4dfbd878ffb300a2ddd2 (patch)
tree52a824f118f99f14d7079d2c05e9f3035350e1ee /model/Room.php
parent65397e5734b1439df4d68be40ffe994f26e551ec (diff)
parent0b73843d5e0d0ac22a46db28090e707566668ae4 (diff)
Merge pull request #56 from voc/feature/multitranslations
Feature/multitranslations
Diffstat (limited to '')
-rw-r--r--model/Room.php63
1 files changed, 55 insertions, 8 deletions
diff --git a/model/Room.php b/model/Room.php
index 4b251cd..24d87cb 100644
--- a/model/Room.php
+++ b/model/Room.php
@@ -175,10 +175,40 @@ class Room
return 'Adaptive multi-format-multi-bitrate-Stream to rule the World!!1elf';
}
- public function hasTranslation() {
+ public function getTranslations() {
return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TRANSLATION');
}
+ private function getTranslationEndpoints() {
+ return array_map(
+ function ($translation) {
+ return $translation['endpoint'];
+ },
+ $this->getTranslations()
+ );
+ }
+
+ private function isTranslationEndpoint($endpoint) {
+ return in_array($endpoint, $this->getTranslationEndpoints());
+ }
+
+ private function findTranslationLabel($language) {
+ foreach($this->getTranslations() as $translation) {
+ if ($translation['endpoint'] === $language) {
+ return $translation['label'];
+ }
+ }
+ return null;
+ }
+
+ public function hasTranslation() {
+ return count($this->getTranslations()) > 0;
+ }
+
+ public function isValidLanguage($language) {
+ return ($language === 'native' || $this->isTranslationEndpoint($language));
+ }
+
public function getSelectionNames()
{
$selections = array();
@@ -203,6 +233,11 @@ class Room
return $selections;
}
+ public function isSelectionTranslated($selection) {
+ # dash is special, has langs included
+ return $selection !== 'dash' && $selection !== 'music';
+ }
+
public function getTabNames()
{
$tabs = array();
@@ -284,8 +319,11 @@ class Room
foreach ($selections as $selection) {
$streams[] = $this->createStreamObject($selection, 'native');
- if($this->hasTranslation())
- $streams[] = $this->createStreamObject($selection, 'translated');
+ if ($this->isSelectionTranslated($selection)) {
+ foreach ($this->getTranslations() as $translation) {
+ $streams[] = $this->createStreamObject($selection, $translation['endpoint'], $translation['label']);
+ }
+ }
}
return $streams;
@@ -305,17 +343,26 @@ class Room
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());
+ $translation_label = null;
+ if ($language !== 'native' && $language !== 'stereo') {
+ if (! $this->hasTranslation()) {
+ throw new NotFoundException('Translated Streams of Room '. $this->getSlug());
+ }
+ if (! $this->isValidLanguage($language)) {
+ throw new NotFoundException('Selected translation');
+ }
+
+ $translation_label = $this->findTranslationLabel($language);
+ }
- return $this->createStreamObject($selection, $language);
+ return $this->createStreamObject($selection, $language, $translation_label);
}
- public function createStreamObject($selection, $language = 'native')
+ public function createStreamObject($selection, $language = 'native', $languageLabel = null)
{
if($language == 'native' && $this->hasStereo())
$language = 'stereo';
- return new Stream($this, $selection, $language);
+ return new Stream($this, $selection, $language, $languageLabel);
}
}