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