Skip to content

Commit

Permalink
add backend support for skosmos:serviceNameLong configuration setting
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed Aug 13, 2024
1 parent 951eab3 commit d09a9f3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/model/BaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions src/model/GlobalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
15 changes: 15 additions & 0 deletions tests/GlobalConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions tests/testconfig.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d09a9f3

Please sign in to comment.