From d09a9f35933959a56d91ba52b92df51a0f411fa8 Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Tue, 13 Aug 2024 16:25:02 +0300 Subject: [PATCH] add backend support for skosmos:serviceNameLong configuration setting --- src/model/BaseConfig.php | 9 ++++++++- src/model/GlobalConfig.php | 16 ++++++++++++++++ tests/GlobalConfigTest.php | 15 +++++++++++++++ tests/testconfig.ttl | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/model/BaseConfig.php b/src/model/BaseConfig.php index 4e34bb14e..322d3f4ad 100644 --- a/src/model/BaseConfig.php +++ b/src/model/BaseConfig.php @@ -54,7 +54,14 @@ protected function getLiteral($property, $default=null, $lang=null) return $literal->getValue(); } - // not found with selected language, try any language + // not found with selected language, try to find one without a language tag + foreach ($this->getResource()->allLiterals($property) as $literal) { + if ($literal->getLang() === null) { + return $literal->getValue(); + } + } + + // not found with selected language or no language tag, try any language $literal = $this->getResource()->getLiteral($property); if ($literal) { return $literal->getValue(); diff --git a/src/model/GlobalConfig.php b/src/model/GlobalConfig.php index 874a59a5c..b1a6152c2 100644 --- a/src/model/GlobalConfig.php +++ b/src/model/GlobalConfig.php @@ -289,6 +289,22 @@ public function getServiceName() return $this->getLiteral('skosmos:serviceName', 'Skosmos'); } + /** + * Returns the long version of the service name in the requested language. + * @return string the long name of the service + */ + public function getServiceNameLong($lang) + { + $val = $this->getLiteral('skosmos:serviceNameLong', false, $lang); + + if ($val === false) { + // fall back to short service name if not configured + return $this->getServiceName(); + } + + return $val; + } + /** * @return string */ diff --git a/tests/GlobalConfigTest.php b/tests/GlobalConfigTest.php index 3b1e4f059..881698d0c 100644 --- a/tests/GlobalConfigTest.php +++ b/tests/GlobalConfigTest.php @@ -54,6 +54,21 @@ public function testGetServiceName() $this->assertEquals("Skosmos being tested", $this->config->getServiceName()); } + public function testGetServiceNameLongEn() + { + $this->assertEquals("Skosmos being tested, long title", $this->config->getServiceNameLong('en')); + } + + public function testGetServiceNameLongNoLanguageFallback() + { + $this->assertEquals("Skosmos-long", $this->config->getServiceNameLong('fr')); + } + + public function testGetServiceNameLongNotSetFallback() + { + $this->assertEquals("Skosmos", $this->configWithDefaults->getServiceNameLong('en')); + } + public function testGetBaseHref() { $this->assertEquals("http://tests.localhost/Skosmos/", $this->configWithBaseHref->getBaseHref()); diff --git a/tests/testconfig.ttl b/tests/testconfig.ttl index 730840f12..6ec942653 100644 --- a/tests/testconfig.ttl +++ b/tests/testconfig.ttl @@ -33,6 +33,7 @@ skosmos:httpTimeout 2 ; # customize the service name skosmos:serviceName "Skosmos being tested" ; + skosmos:serviceNameLong "Skosmos being tested, long title"@en, "Skosmos-long" ; # customize the base element. Set this if the automatic base url detection doesn't work. For example setups behind a proxy. #skosmos:baseHref "http://localhost/Skosmos/" ; # interface languages available, and the corresponding system locales