| Total Complexity | 113 |
| Total Lines | 751 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like VocabularyConfig often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use VocabularyConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class VocabularyConfig extends BaseConfig |
||
| 7 | { |
||
| 8 | private $globalPlugins; |
||
| 9 | private $pluginRegister; |
||
| 10 | private $pluginParameters = array(); |
||
| 11 | private $languageOrderCache = array(); |
||
| 12 | private $labelOverrides = array(); |
||
| 13 | |||
| 14 | public const DEFAULT_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy", |
||
| 15 | "skos:definition", "skos:broader", "isothes:broaderGeneric", |
||
| 16 | "isothes:broaderPartitive", "isothes:broaderInstantial", |
||
| 17 | "skos:narrower", "isothes:narrowerGeneric", "isothes:narrowerPartitive", |
||
| 18 | "isothes:narrowerInstantial", "skos:related", "skos:altLabel", |
||
| 19 | "skos:note", "skos:scopeNote", "skos:historyNote", "rdfs:comment", |
||
| 20 | "dc11:source", "dc:source", "skosmos:memberOf", "skosmos:memberOfArray"); |
||
| 21 | |||
| 22 | public const ISO25964_PROPERTY_ORDER = array("rdf:type", "dc:isReplacedBy", |
||
| 23 | // ISO 25964 allows placing all text fields (inc. SN and DEF) together |
||
| 24 | // so we will do that, except for HN, which is clearly administrative |
||
| 25 | "skos:note", "skos:scopeNote", "skos:definition", "rdfs:comment", |
||
| 26 | "dc11:source", "dc:source", "skos:altLabel", "skos:broader", |
||
| 27 | "isothes:broaderGeneric", "isothes:broaderPartitive", |
||
| 28 | "isothes:broaderInstantial", "skos:narrower", "isothes:narrowerGeneric", |
||
| 29 | "isothes:narrowerPartitive", "isothes:narrowerInstantial", |
||
| 30 | "skos:related", "skos:historyNote", "skosmos:memberOf", |
||
| 31 | "skosmos:memberOfArray"); |
||
| 32 | |||
| 33 | public function __construct(Model $model, EasyRdf\Resource $resource, array $globalPlugins = array()) |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Get an ordered array of plugin names with order configured in skosmos:vocabularyPlugins |
||
| 44 | * @return array of plugin names |
||
| 45 | */ |
||
| 46 | public function getPluginNames(): array |
||
| 47 | { |
||
| 48 | $this->pluginParameters = array(); |
||
| 49 | $pluginArray = array(); |
||
| 50 | $vocabularyPlugins = $this->resource->getResource('skosmos:vocabularyPlugins'); |
||
| 51 | if (!$vocabularyPlugins instanceof EasyRdf\Collection) { |
||
| 52 | $vocabularyPlugins = $this->resource->all('skosmos:vocabularyPlugins'); |
||
| 53 | } |
||
| 54 | if ($vocabularyPlugins) { |
||
| 55 | foreach ($vocabularyPlugins as $plugin) { |
||
| 56 | if ($plugin instanceof EasyRdf\Literal) { |
||
| 57 | $pluginArray[] = $plugin->getValue(); |
||
| 58 | } else { |
||
| 59 | $pluginArray[] = $plugin->getLiteral('skosmos:usePlugin')->getValue(); |
||
| 60 | // Process parameters for parameterized plugins |
||
| 61 | $this->setPluginParametersFromResource($plugin); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | $pluginArray = array_merge($pluginArray, $this->globalPlugins); |
||
| 66 | return array_values(array_unique($pluginArray)); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Updates array of parameterized plugins adding parameter values |
||
| 71 | * @param Easyrdf\Resource $pluginResource |
||
| 72 | * @return void |
||
| 73 | */ |
||
| 74 | private function setPluginParametersFromResource(Easyrdf\Resource $pluginResource): void |
||
| 75 | { |
||
| 76 | $pluginName = $pluginResource->getLiteral('skosmos:usePlugin')->getValue(); |
||
| 77 | $this->pluginParameters[$pluginName] = array(); |
||
| 78 | |||
| 79 | $pluginParams = $pluginResource->allResources('skosmos:parameters'); |
||
| 80 | foreach ($pluginParams as $parameter) { |
||
| 81 | $paramLiterals = $parameter->allLiterals('schema:value'); |
||
| 82 | foreach ($paramLiterals as $paramLiteral) { |
||
| 83 | $paramName = $parameter->getLiteral('schema:propertyID')->getValue(); |
||
| 84 | $paramValue = $paramLiteral->getValue(); |
||
| 85 | $paramLang = $paramLiteral->getLang(); |
||
| 86 | if ($paramLang) { |
||
| 87 | $paramName .= '_' . $paramLang; |
||
| 88 | } |
||
| 89 | $this->pluginParameters[$pluginName][$paramName] = $paramValue; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | |||
| 95 | /** |
||
| 96 | * Sets array of configured property label overrides |
||
| 97 | * @return void |
||
| 98 | */ |
||
| 99 | private function setPropertyLabelOverrides(): void |
||
| 100 | { |
||
| 101 | $this->labelOverrides = array(); |
||
| 102 | $overrides = $this->resource->allResources('skosmos:propertyLabelOverride'); |
||
| 103 | if (!empty($overrides)) { |
||
| 104 | foreach ($overrides as $override) { |
||
| 105 | $this->setLabelOverride($override); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Updates array of label overrides by adding a new override from the configuration file |
||
| 112 | * @param Easyrdf\Resource $labelOverride |
||
| 113 | * @return void |
||
| 114 | */ |
||
| 115 | private function setLabelOverride(Easyrdf\Resource $override): void |
||
| 116 | { |
||
| 117 | $labelProperty = $override->getResource('skosmos:property'); |
||
| 118 | $labelPropUri = $labelProperty->shorten(); |
||
| 119 | if (empty($this->labelOverrides[$labelPropUri])) { |
||
| 120 | $this->labelOverrides[$labelPropUri] = array(); |
||
| 121 | } |
||
| 122 | $newOverrides = array(); |
||
| 123 | |||
| 124 | $labels = $override->allLiterals('rdfs:label'); //property label overrides |
||
| 125 | foreach ($labels as $label) { |
||
| 126 | $newOverrides['label'][$label->getLang()] = $label->getValue(); |
||
| 127 | } |
||
| 128 | $descriptions = $override->allLiterals('rdfs:comment'); //optionally override property label tooltips |
||
| 129 | foreach ($descriptions as $description) { |
||
| 130 | $newOverrides['description'][$description->getLang()] = $description->getValue(); |
||
| 131 | } |
||
| 132 | $this->labelOverrides[$labelPropUri] = array_merge($newOverrides, $this->labelOverrides[$labelPropUri]); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Get the SPARQL endpoint URL for this vocabulary |
||
| 137 | * |
||
| 138 | * @return string|null endpoint URL, or null if not set |
||
| 139 | */ |
||
| 140 | public function getSparqlEndpoint() |
||
| 141 | { |
||
| 142 | $endpoint = $this->resource->get('void:sparqlEndpoint'); |
||
| 143 | if ($endpoint) { |
||
| 144 | return $endpoint->getUri(); |
||
| 145 | } |
||
| 146 | return null; |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Get the SPARQL graph URI for this vocabulary |
||
| 151 | * |
||
| 152 | * @return string|null graph URI, or null if not set |
||
| 153 | */ |
||
| 154 | public function getSparqlGraph() |
||
| 155 | { |
||
| 156 | $graph = $this->resource->get('skosmos:sparqlGraph'); |
||
| 157 | if ($graph) { |
||
| 158 | $graph = $graph->getUri(); |
||
| 159 | } |
||
| 160 | |||
| 161 | return $graph; |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Get the SPARQL dialect for this vocabulary |
||
| 166 | * |
||
| 167 | * @return string|null dialect name |
||
| 168 | */ |
||
| 169 | public function getSparqlDialect() |
||
| 170 | { |
||
| 171 | $dialect = $this->resource->get('skosmos:sparqlDialect'); |
||
| 172 | if ($dialect) { |
||
| 173 | $dialect = $dialect->getValue(); |
||
| 174 | } |
||
| 175 | |||
| 176 | return $dialect; |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Get the default language of this vocabulary |
||
| 181 | * @return string default language, e.g. 'en' |
||
| 182 | */ |
||
| 183 | |||
| 184 | public function getDefaultLanguage() |
||
| 185 | { |
||
| 186 | $deflang = $this->resource->getLiteral('skosmos:defaultLanguage'); |
||
| 187 | if ($deflang) { |
||
|
|
|||
| 188 | return $deflang->getValue(); |
||
| 189 | } |
||
| 190 | |||
| 191 | $langs = $this->getLanguages(); |
||
| 192 | $deflang = reset($langs); // picking the first one from the list with reset since the keys are not numeric |
||
| 193 | if (sizeof($langs) > 1) { |
||
| 194 | trigger_error("Default language for vocabulary '" . $this->getShortName() . "' unknown, choosing '$deflang'.", E_USER_WARNING); |
||
| 195 | } |
||
| 196 | |||
| 197 | return $deflang; |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Returns a short name for a vocabulary if configured. If that has not been set |
||
| 202 | * using vocabId as a fallback. |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | public function getShortName() |
||
| 206 | { |
||
| 207 | $shortname = $this->getLiteral('skosmos:shortName'); |
||
| 208 | if ($shortname) { |
||
| 209 | return $shortname; |
||
| 210 | } |
||
| 211 | |||
| 212 | // if no shortname exists fall back to the id |
||
| 213 | return $this->getId(); |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get the vocabulary feedback e-mail address and return it. |
||
| 218 | * |
||
| 219 | * @return string e-mail address or null if not defined. |
||
| 220 | */ |
||
| 221 | public function getFeedbackRecipient() |
||
| 222 | { |
||
| 223 | $email = $this->resource->get('skosmos:feedbackRecipient'); |
||
| 224 | return isset($email) ? $email->getValue() : null; |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Returns the human readable vocabulary title. |
||
| 229 | * @return string the title of the vocabulary |
||
| 230 | */ |
||
| 231 | public function getTitle($lang = null) |
||
| 232 | { |
||
| 233 | return $this->getLiteral('dc:title', false, $lang); |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Returns the human readable vocabulary description. |
||
| 238 | * @return string the description of the vocabulary |
||
| 239 | */ |
||
| 240 | public function getDescription($lang = null) |
||
| 241 | { |
||
| 242 | return $this->getLiteral('dc:description', false, $lang); |
||
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Returns the sorting strategy for notation codes set in the config.ttl |
||
| 247 | * config: either "lexical", "natural", or null if sorting by notations is |
||
| 248 | * disabled. A "true" value in the configuration file is interpreted as |
||
| 249 | * "lexical". |
||
| 250 | * @return string|bool |
||
| 251 | */ |
||
| 252 | public function getSortByNotation(): ?string |
||
| 253 | { |
||
| 254 | $value = $this->getLiteral('skosmos:sortByNotation'); |
||
| 255 | if ($value == "lexical" || $value == "natural") { |
||
| 256 | return $value; |
||
| 257 | } |
||
| 258 | // not a special value - interpret as boolean instead |
||
| 259 | $bvalue = $this->getBoolean('skosmos:sortByNotation'); |
||
| 260 | // "true" is interpreted as "lexical" |
||
| 261 | return $bvalue ? "lexical" : null; |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * get the URLs from which the vocabulary data can be downloaded |
||
| 266 | * @return array Array with MIME type as key, URL as value |
||
| 267 | */ |
||
| 268 | public function getDataURLs() |
||
| 269 | { |
||
| 270 | $ret = array(); |
||
| 271 | $urls = $this->resource->allResources("void:dataDump"); |
||
| 272 | foreach ($urls as $url) { |
||
| 273 | // first try dc:format and dc11:format |
||
| 274 | $mimetypelit = $url->getLiteral('dc:format'); |
||
| 275 | if ($mimetypelit === null) { |
||
| 276 | $mimetypelit = $url->getLiteral('dc11:format'); |
||
| 277 | } |
||
| 278 | |||
| 279 | if ($mimetypelit !== null) { |
||
| 280 | $mimetype = $mimetypelit->getValue(); |
||
| 281 | } else { |
||
| 282 | $format = EasyRdf\Format::guessFormat(null, $url->getURI()); |
||
| 283 | if ($format === null) { |
||
| 284 | trigger_error("Could not guess format for <$url>.", E_USER_WARNING); |
||
| 285 | continue; |
||
| 286 | } |
||
| 287 | $mimetypes = array_keys($format->getMimeTypes()); |
||
| 288 | $mimetype = $mimetypes[0]; |
||
| 289 | } |
||
| 290 | |||
| 291 | $langLit = $url->getLiteral('dc:language'); |
||
| 292 | |||
| 293 | if ($langLit != null) { |
||
| 294 | //when the mimetype has language variants |
||
| 295 | $dataUrlLang = $langLit->getValue(); |
||
| 296 | |||
| 297 | if (!isset($ret[$mimetype])) { |
||
| 298 | $arr = array(); |
||
| 299 | } else { |
||
| 300 | $arr = $ret[$mimetype]; |
||
| 301 | } |
||
| 302 | $arr[$dataUrlLang] = $url->getURI(); |
||
| 303 | $ret[$mimetype] = $arr; |
||
| 304 | } else { |
||
| 305 | $ret[$mimetype] = $url->getURI(); |
||
| 306 | } |
||
| 307 | } |
||
| 308 | return $ret; |
||
| 309 | } |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Returns the main Concept Scheme URI of that Vocabulary, |
||
| 313 | * or null if not set. |
||
| 314 | * @return string concept scheme URI or null |
||
| 315 | */ |
||
| 316 | |||
| 317 | public function getMainConceptSchemeURI() |
||
| 318 | { |
||
| 319 | $val = $this->resource->getResource("skosmos:mainConceptScheme"); |
||
| 320 | if ($val) { |
||
| 321 | return $val->getURI(); |
||
| 322 | } |
||
| 323 | |||
| 324 | return null; |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Returns the class URI used for concept groups in this vocabulary, |
||
| 329 | * or null if not set. |
||
| 330 | * @return string group class URI or null |
||
| 331 | */ |
||
| 332 | |||
| 333 | public function getGroupClassURI() |
||
| 334 | { |
||
| 335 | $val = $this->resource->getResource("skosmos:groupClass"); |
||
| 336 | if ($val) { |
||
| 337 | return $val->getURI(); |
||
| 338 | } |
||
| 339 | |||
| 340 | return null; |
||
| 341 | } |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Returns the class URI used for thesaurus arrays in this vocabulary, |
||
| 345 | * or null if not set. |
||
| 346 | * @return string array class URI or null |
||
| 347 | */ |
||
| 348 | |||
| 349 | public function getArrayClassURI() |
||
| 350 | { |
||
| 351 | $val = $this->resource->getResource("skosmos:arrayClass"); |
||
| 352 | if ($val) { |
||
| 353 | return $val->getURI(); |
||
| 354 | } |
||
| 355 | |||
| 356 | return null; |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Returns custom properties displayed on the search page if configured. |
||
| 361 | * @return array array class URI or null |
||
| 362 | */ |
||
| 363 | |||
| 364 | public function getAdditionalSearchProperties() |
||
| 365 | { |
||
| 366 | $resources = $this->resource->allResources("skosmos:showPropertyInSearch"); |
||
| 367 | $ret = array(); |
||
| 368 | foreach ($resources as $res) { |
||
| 369 | $prop = $res->getURI(); |
||
| 370 | if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // shortening property labels if possible |
||
| 371 | $prop = EasyRdf\RdfNamespace::shorten($prop); |
||
| 372 | } |
||
| 373 | |||
| 374 | $ret[] = $prop; |
||
| 375 | } |
||
| 376 | return $ret; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Queries whether the property should be shown with all the label language variations. |
||
| 381 | * @param string $property |
||
| 382 | * @return boolean |
||
| 383 | */ |
||
| 384 | public function hasMultiLingualProperty($property) |
||
| 385 | { |
||
| 386 | $resources = $this->resource->allResources("skosmos:hasMultiLingualProperty"); |
||
| 387 | foreach ($resources as $res) { |
||
| 388 | $prop = $res->getURI(); |
||
| 389 | if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // shortening property labels if possible |
||
| 390 | $prop = EasyRdf\RdfNamespace::shorten($prop); |
||
| 391 | } |
||
| 392 | |||
| 393 | if ($prop === $property) { |
||
| 394 | return true; |
||
| 395 | } |
||
| 396 | |||
| 397 | } |
||
| 398 | return false; |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Returns a boolean value set in the config.ttl config. |
||
| 403 | * @return boolean |
||
| 404 | */ |
||
| 405 | public function getShowTopConcepts() |
||
| 406 | { |
||
| 407 | return $this->getBoolean('skosmos:showTopConcepts'); |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Returns a boolean value set in the config.ttl config. |
||
| 412 | * @return boolean |
||
| 413 | */ |
||
| 414 | public function showConceptSchemesInHierarchy() |
||
| 415 | { |
||
| 416 | return $this->getBoolean('skosmos:conceptSchemesInHierarchy'); |
||
| 417 | } |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Returns a boolean value set in the config.ttl config. |
||
| 421 | * @return boolean defaults to true if fetching hasn't been explicitly denied. |
||
| 422 | */ |
||
| 423 | public function getExternalResourcesLoading() |
||
| 424 | { |
||
| 425 | return $this->getBoolean('skosmos:loadExternalResources', true); |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Returns a boolean value set in the config.ttl config. |
||
| 430 | * @return boolean |
||
| 431 | */ |
||
| 432 | public function getShowLangCodes() |
||
| 433 | { |
||
| 434 | return $this->getBoolean('skosmos:explicitLanguageTags'); |
||
| 435 | } |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Returns a boolean value set in the config.ttl config. |
||
| 439 | * @return boolean |
||
| 440 | */ |
||
| 441 | public function searchByNotation() |
||
| 442 | { |
||
| 443 | return $this->getBoolean('skosmos:searchByNotation'); |
||
| 444 | } |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Returns skosmos:marcSourcecode value set in config.ttl. |
||
| 448 | * @return string marcsource name |
||
| 449 | */ |
||
| 450 | public function getMarcSourceCode($lang = null) |
||
| 451 | { |
||
| 452 | return $this->getLiteral('skosmos:marcSourceCode', false, $lang); |
||
| 453 | } |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Returns the boolean value of the skosmos:showNotationAsProperty setting. |
||
| 457 | * @return boolean |
||
| 458 | */ |
||
| 459 | public function getShowNotationAsProperty() |
||
| 460 | { |
||
| 461 | return $this->getBoolean('skosmos:showNotationAsProperty', true); |
||
| 462 | } |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Returns a boolean value set in the config.ttl config. |
||
| 466 | * @return array array of concept class URIs (can be empty) |
||
| 467 | */ |
||
| 468 | public function getIndexClasses() |
||
| 469 | { |
||
| 470 | return $this->getResources("skosmos:indexShowClass"); |
||
| 471 | } |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Returns skosmos:externalProperty values set in the config.ttl config. |
||
| 475 | * @return array array of external property URIs (can be empty) |
||
| 476 | */ |
||
| 477 | public function getExtProperties() |
||
| 478 | { |
||
| 479 | return $this->getResources("skosmos:externalProperty"); |
||
| 480 | } |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Get the languages supported by this vocabulary |
||
| 484 | * @return array languages supported by this vocabulary (as language tag strings) |
||
| 485 | */ |
||
| 486 | public function getLanguages() |
||
| 487 | { |
||
| 488 | $langs = $this->resource->allLiterals('skosmos:language'); |
||
| 489 | $ret = array(); |
||
| 490 | foreach ($langs as $lang) { |
||
| 491 | $langlit = Punic\Language::getName($lang->getValue(), $this->getLang()); |
||
| 492 | $ret[$langlit] = $lang->getValue(); |
||
| 493 | } |
||
| 494 | ksort($ret); |
||
| 495 | |||
| 496 | return $ret; |
||
| 497 | } |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Returns the parameters of parameterized plugins |
||
| 501 | * @return array of plugin parameters |
||
| 502 | */ |
||
| 503 | public function getPluginParameters() |
||
| 504 | { |
||
| 505 | return $this->pluginParameters; |
||
| 506 | } |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Get the list of property label overrides |
||
| 510 | * @return array of custom property labels |
||
| 511 | */ |
||
| 512 | public function getPropertyLabelOverrides() |
||
| 513 | { |
||
| 514 | return $this->labelOverrides; |
||
| 515 | } |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Returns the vocabulary default sidebar view. |
||
| 519 | * @return string name of the view |
||
| 520 | */ |
||
| 521 | public function getDefaultSidebarView() |
||
| 522 | { |
||
| 523 | $defview = $this->resource->getLiteral('skosmos:defaultSidebarView'); |
||
| 524 | $sidebarViews = $this->getSidebarViews(); |
||
| 525 | if ($defview) { |
||
| 526 | $value = $defview->getValue(); |
||
| 527 | if (in_array($value, $sidebarViews)) { |
||
| 528 | return $value; |
||
| 529 | } else { |
||
| 530 | return $sidebarViews[0]; // if not in sidebarViews, displaying first provided view |
||
| 531 | } |
||
| 532 | } |
||
| 533 | |||
| 534 | if (in_array('alphabetical', $sidebarViews)) { |
||
| 535 | return 'alphabetical'; // if not defined, displaying alphabetical index |
||
| 536 | } else { |
||
| 537 | return $sidebarViews[0]; // if no alphabetical index, displaying first provided view |
||
| 538 | } |
||
| 539 | } |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Returns the concept page default sidebar view. |
||
| 543 | * @return string name of the view |
||
| 544 | */ |
||
| 545 | public function getDefaultConceptSidebarView() |
||
| 546 | { |
||
| 547 | $defview = $this->resource->getLiteral('skosmos:defaultConceptSidebarView'); |
||
| 548 | $sidebarViews = $this->getSidebarViews(); |
||
| 549 | if ($defview) { |
||
| 550 | $value = $defview->getValue(); |
||
| 551 | if (in_array($value, $sidebarViews)) { |
||
| 552 | return $value; |
||
| 553 | } else { |
||
| 554 | return $sidebarViews[0]; // if not in sidebarViews, displaying first provided view |
||
| 555 | } |
||
| 556 | } |
||
| 557 | |||
| 558 | if (in_array('hierarchy', $sidebarViews)) { |
||
| 559 | return 'hierarchy'; // if not defined, displaying hierarchy |
||
| 560 | } else { |
||
| 561 | return $sidebarViews[0]; // if no hierarchy, displaying first provided view |
||
| 562 | } |
||
| 563 | } |
||
| 564 | |||
| 565 | /** |
||
| 566 | * Returns sidebar views used in this vocabulary |
||
| 567 | * @return array of available views |
||
| 568 | */ |
||
| 569 | public function getSidebarViews() |
||
| 582 | |||
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Extracts the vocabulary id string from the baseuri of the vocabulary. |
||
| 587 | * @return string identifier eg. 'mesh'. |
||
| 588 | */ |
||
| 589 | public function getId() |
||
| 601 | } |
||
| 602 | |||
| 603 | public function getShowStatistics() |
||
| 604 | { |
||
| 605 | return $this->getBoolean('skosmos:showStatistics', true); |
||
| 606 | } |
||
| 607 | |||
| 608 | public function getPluginRegister() |
||
| 609 | { |
||
| 610 | return $this->pluginRegister; |
||
| 611 | } |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Returns the property/properties used for visualizing concept hierarchies. |
||
| 615 | * @return array array class URI or null |
||
| 616 | */ |
||
| 617 | |||
| 618 | public function getHierarchyProperty() |
||
| 619 | { |
||
| 620 | $resources = $this->resource->allResources("skosmos:hierarchyProperty"); |
||
| 621 | $ret = array(); |
||
| 622 | foreach ($resources as $res) { |
||
| 623 | $prop = $res->getURI(); |
||
| 624 | if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // prefixing if possible |
||
| 625 | $prop = EasyRdf\RdfNamespace::shorten($prop); |
||
| 626 | } |
||
| 627 | |||
| 628 | $ret[] = $prop; |
||
| 629 | } |
||
| 630 | return empty($ret) ? array('skos:broader') : $ret; |
||
| 631 | } |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Returns a boolean value set in the config.ttl config. |
||
| 635 | * @return boolean |
||
| 636 | */ |
||
| 637 | public function showNotation() |
||
| 638 | { |
||
| 639 | return $this->getBoolean('skosmos:showNotation', true); |
||
| 640 | } |
||
| 641 | |||
| 642 | /** |
||
| 643 | * Returns the alphabetical list qualifier in this vocabulary, |
||
| 644 | * or null if not set. |
||
| 645 | * @return EasyRdf\Resource|null alphabetical list qualifier resource or null |
||
| 646 | */ |
||
| 647 | public function getAlphabeticalListQualifier() |
||
| 648 | { |
||
| 649 | return $this->resource->getResource('skosmos:alphabeticalListQualifier'); |
||
| 650 | } |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Returns a boolean value set in the config.ttl config. |
||
| 654 | * @return boolean |
||
| 655 | */ |
||
| 656 | public function getShowDeprecated() |
||
| 657 | { |
||
| 658 | return $this->getBoolean('skosmos:showDeprecated', false); |
||
| 659 | } |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Returns a boolean value set in the config.ttl config. |
||
| 663 | * @return boolean |
||
| 664 | */ |
||
| 665 | public function getShowDeprecatedChanges() |
||
| 666 | { |
||
| 667 | return $this->getBoolean('skosmos:showDeprecatedChanges', false); |
||
| 668 | } |
||
| 669 | |||
| 670 | /** |
||
| 671 | * Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration. |
||
| 672 | * @return array of objects or an empty array |
||
| 673 | */ |
||
| 674 | public function getTypes($lang = null) |
||
| 684 | } |
||
| 685 | |||
| 686 | /** |
||
| 687 | * Returns an array of fallback languages that is ordered by priority and |
||
| 688 | * defined in the vocabulary configuration as a collection. |
||
| 689 | * Additionally, the chosen content language is inserted with the highest priority |
||
| 690 | * and the vocab default language is inserted with the lowest priority. |
||
| 691 | * @param string $clang |
||
| 692 | * @return array of language code strings |
||
| 693 | */ |
||
| 694 | public function getLanguageOrder($clang) |
||
| 695 | { |
||
| 696 | if (array_key_exists($clang, $this->languageOrderCache)) { |
||
| 697 | return $this->languageOrderCache[$clang]; |
||
| 698 | } |
||
| 699 | $ret = array($clang); |
||
| 700 | $fallbacks = !empty($this->resource->get('skosmos:fallbackLanguages')) ? $this->resource->get('skosmos:fallbackLanguages') : array(); |
||
| 701 | foreach ($fallbacks as $lang) { |
||
| 702 | if (!in_array($lang, $ret)) { |
||
| 703 | $ret[] = (string)$lang; // Literal to string conversion |
||
| 704 | } |
||
| 705 | } |
||
| 706 | if (!in_array($this->getDefaultLanguage(), $ret)) { |
||
| 707 | $ret[] = (string)$this->getDefaultLanguage(); |
||
| 708 | } |
||
| 709 | foreach ($this->getLanguages() as $lang) { |
||
| 710 | if (!in_array($lang, $ret)) { |
||
| 711 | $ret[] = $lang; |
||
| 712 | } |
||
| 713 | } |
||
| 714 | // store in cache so this doesn't have to be computed again |
||
| 715 | $this->languageOrderCache[$clang] = $ret; |
||
| 716 | return $ret; |
||
| 717 | } |
||
| 718 | |||
| 719 | /** |
||
| 720 | * @return boolean |
||
| 721 | */ |
||
| 722 | public function isUseModifiedDate() |
||
| 725 | } |
||
| 726 | |||
| 727 | /** |
||
| 728 | * @return array |
||
| 729 | */ |
||
| 730 | public function getPropertyOrder() |
||
| 731 | { |
||
| 732 | $order = $this->getResource()->getResource('skosmos:propertyOrder'); |
||
| 733 | if ($order === null) { |
||
| 734 | return self::DEFAULT_PROPERTY_ORDER; |
||
| 735 | } |
||
| 736 | |||
| 737 | $short = EasyRdf\RdfNamespace::shorten($order); |
||
| 738 | if ($short == 'skosmos:iso25964PropertyOrder') { |
||
| 739 | return self::ISO25964_PROPERTY_ORDER; |
||
| 740 | } elseif ($short == 'skosmos:defaultPropertyOrder') { |
||
| 741 | return self::DEFAULT_PROPERTY_ORDER; |
||
| 742 | } |
||
| 743 | |||
| 744 | // check for custom order definition |
||
| 745 | $orderList = $order->getResource('rdf:value'); |
||
| 746 | if ($orderList !== null && $orderList instanceof EasyRdf\Collection) { |
||
| 747 | $ret = array(); |
||
| 748 | foreach ($orderList as $prop) { |
||
| 749 | $short = $prop->shorten(); |
||
| 750 | $ret[] = ($short !== null) ? $short : $prop->getURI(); |
||
| 751 | } |
||
| 752 | return $ret; |
||
| 753 | } |
||
| 754 | |||
| 757 | } |
||
| 758 | } |
||
| 759 |