| Total Complexity | 124 |
| Total Lines | 789 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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()) |
||
| 34 | { |
||
| 35 | parent::__construct($model, $resource); |
||
| 36 | $this->globalPlugins = $globalPlugins; |
||
| 37 | $this->setPropertyLabelOverrides(); |
||
| 38 | $pluginArray = $this->getPluginArray(); |
||
| 39 | $this->pluginRegister = new PluginRegister($pluginArray); |
||
| 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 getPluginArray(): array |
||
| 47 | { |
||
| 48 | $this->setParameterizedPlugins(); |
||
| 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 | } |
||
| 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 | * Returns a short name for a vocabulary if configured. If that has not been set |
||
| 240 | * using vocabId as a fallback. |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | public function getShortName() |
||
| 244 | { |
||
| 245 | $shortname = $this->getLiteral('skosmos:shortName'); |
||
| 246 | if ($shortname) { |
||
| 247 | return $shortname; |
||
| 248 | } |
||
| 249 | |||
| 250 | // if no shortname exists fall back to the id |
||
| 251 | return $this->getId(); |
||
| 252 | } |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Get the vocabulary feedback e-mail address and return it. |
||
| 256 | * |
||
| 257 | * @return string e-mail address or null if not defined. |
||
| 258 | */ |
||
| 259 | public function getFeedbackRecipient() |
||
| 260 | { |
||
| 261 | $email = $this->resource->get('skosmos:feedbackRecipient'); |
||
| 262 | return isset($email) ? $email->getValue() : null; |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Returns the human readable vocabulary title. |
||
| 267 | * @return string the title of the vocabulary |
||
| 268 | */ |
||
| 269 | public function getTitle($lang = null) |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Returns the human readable vocabulary description. |
||
| 276 | * @return string the description of the vocabulary |
||
| 277 | */ |
||
| 278 | public function getDescription($lang = null) |
||
| 279 | { |
||
| 280 | return $this->getLiteral('dc:description', false, $lang); |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Returns the sorting strategy for notation codes set in the config.ttl |
||
| 285 | * config: either "lexical", "natural", or null if sorting by notations is |
||
| 286 | * disabled. A "true" value in the configuration file is interpreted as |
||
| 287 | * "lexical". |
||
| 288 | * @return string|bool |
||
| 289 | */ |
||
| 290 | public function getSortByNotation(): ?string |
||
| 291 | { |
||
| 292 | $value = $this->getLiteral('skosmos:sortByNotation'); |
||
| 293 | if ($value == "lexical" || $value == "natural") { |
||
| 294 | return $value; |
||
| 295 | } |
||
| 296 | // not a special value - interpret as boolean instead |
||
| 297 | $bvalue = $this->getBoolean('skosmos:sortByNotation'); |
||
| 298 | // "true" is interpreted as "lexical" |
||
| 299 | return $bvalue ? "lexical" : null; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * get the URLs from which the vocabulary data can be downloaded |
||
| 304 | * @return array Array with MIME type as key, URL as value |
||
| 305 | */ |
||
| 306 | public function getDataURLs() |
||
| 307 | { |
||
| 308 | $ret = array(); |
||
| 309 | $urls = $this->resource->allResources("void:dataDump"); |
||
| 310 | foreach ($urls as $url) { |
||
| 311 | // first try dc:format and dc11:format |
||
| 312 | $mimetypelit = $url->getLiteral('dc:format'); |
||
| 313 | if ($mimetypelit === null) { |
||
| 314 | $mimetypelit = $url->getLiteral('dc11:format'); |
||
| 315 | } |
||
| 316 | |||
| 317 | if ($mimetypelit !== null) { |
||
| 318 | $mimetype = $mimetypelit->getValue(); |
||
| 319 | } else { |
||
| 320 | $format = EasyRdf\Format::guessFormat(null, $url->getURI()); |
||
| 321 | if ($format === null) { |
||
| 322 | trigger_error("Could not guess format for <$url>.", E_USER_WARNING); |
||
| 323 | continue; |
||
| 324 | } |
||
| 325 | $mimetypes = array_keys($format->getMimeTypes()); |
||
| 326 | $mimetype = $mimetypes[0]; |
||
| 327 | } |
||
| 328 | |||
| 329 | $langLit = $url->getLiteral('dc:language'); |
||
| 330 | |||
| 331 | if ($langLit != null) { |
||
| 332 | //when the mimetype has language variants |
||
| 333 | $dataUrlLang = $langLit->getValue(); |
||
| 334 | |||
| 335 | if (!isset($ret[$mimetype])) { |
||
| 336 | $arr = array(); |
||
| 337 | } else { |
||
| 338 | $arr = $ret[$mimetype]; |
||
| 339 | } |
||
| 340 | $arr[$dataUrlLang] = $url->getURI(); |
||
| 341 | $ret[$mimetype] = $arr; |
||
| 342 | } else { |
||
| 343 | $ret[$mimetype] = $url->getURI(); |
||
| 344 | } |
||
| 345 | } |
||
| 346 | return $ret; |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Returns the main Concept Scheme URI of that Vocabulary, |
||
| 351 | * or null if not set. |
||
| 352 | * @return string concept scheme URI or null |
||
| 353 | */ |
||
| 354 | |||
| 355 | public function getMainConceptSchemeURI() |
||
| 356 | { |
||
| 357 | $val = $this->resource->getResource("skosmos:mainConceptScheme"); |
||
| 358 | if ($val) { |
||
| 359 | return $val->getURI(); |
||
| 360 | } |
||
| 361 | |||
| 362 | return null; |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Returns the class URI used for concept groups in this vocabulary, |
||
| 367 | * or null if not set. |
||
| 368 | * @return string group class URI or null |
||
| 369 | */ |
||
| 370 | |||
| 371 | public function getGroupClassURI() |
||
| 372 | { |
||
| 373 | $val = $this->resource->getResource("skosmos:groupClass"); |
||
| 374 | if ($val) { |
||
| 375 | return $val->getURI(); |
||
| 376 | } |
||
| 377 | |||
| 378 | return null; |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Returns the class URI used for thesaurus arrays in this vocabulary, |
||
| 383 | * or null if not set. |
||
| 384 | * @return string array class URI or null |
||
| 385 | */ |
||
| 386 | |||
| 387 | public function getArrayClassURI() |
||
| 388 | { |
||
| 389 | $val = $this->resource->getResource("skosmos:arrayClass"); |
||
| 390 | if ($val) { |
||
| 391 | return $val->getURI(); |
||
| 392 | } |
||
| 393 | |||
| 394 | return null; |
||
| 395 | } |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Returns custom properties displayed on the search page if configured. |
||
| 399 | * @return array array class URI or null |
||
| 400 | */ |
||
| 401 | |||
| 402 | public function getAdditionalSearchProperties() |
||
| 403 | { |
||
| 404 | $resources = $this->resource->allResources("skosmos:showPropertyInSearch"); |
||
| 405 | $ret = array(); |
||
| 406 | foreach ($resources as $res) { |
||
| 407 | $prop = $res->getURI(); |
||
| 408 | if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // shortening property labels if possible |
||
| 409 | $prop = EasyRdf\RdfNamespace::shorten($prop); |
||
| 410 | } |
||
| 411 | |||
| 412 | $ret[] = $prop; |
||
| 413 | } |
||
| 414 | return $ret; |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Queries whether the property should be shown with all the label language variations. |
||
| 419 | * @param string $property |
||
| 420 | * @return boolean |
||
| 421 | */ |
||
| 422 | public function hasMultiLingualProperty($property) |
||
| 423 | { |
||
| 424 | $resources = $this->resource->allResources("skosmos:hasMultiLingualProperty"); |
||
| 425 | foreach ($resources as $res) { |
||
| 426 | $prop = $res->getURI(); |
||
| 427 | if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // shortening property labels if possible |
||
| 428 | $prop = EasyRdf\RdfNamespace::shorten($prop); |
||
| 429 | } |
||
| 430 | |||
| 431 | if ($prop === $property) { |
||
| 432 | return true; |
||
| 433 | } |
||
| 434 | |||
| 435 | } |
||
| 436 | return false; |
||
| 437 | } |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Returns a boolean value set in the config.ttl config. |
||
| 441 | * @return boolean |
||
| 442 | */ |
||
| 443 | public function getShowTopConcepts() |
||
| 444 | { |
||
| 445 | return $this->getBoolean('skosmos:showTopConcepts'); |
||
| 446 | } |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Returns a boolean value set in the config.ttl config. |
||
| 450 | * @return boolean |
||
| 451 | */ |
||
| 452 | public function showConceptSchemesInHierarchy() |
||
| 453 | { |
||
| 454 | return $this->getBoolean('skosmos:conceptSchemesInHierarchy'); |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * Returns a boolean value set in the config.ttl config. |
||
| 459 | * @return boolean defaults to true if fetching hasn't been explicitly denied. |
||
| 460 | */ |
||
| 461 | public function getExternalResourcesLoading() |
||
| 462 | { |
||
| 463 | return $this->getBoolean('skosmos:loadExternalResources', true); |
||
| 464 | } |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Returns a boolean value set in the config.ttl config. |
||
| 468 | * @return boolean |
||
| 469 | */ |
||
| 470 | public function getShowLangCodes() |
||
| 471 | { |
||
| 472 | return $this->getBoolean('skosmos:explicitLanguageTags'); |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Returns a boolean value set in the config.ttl config. |
||
| 477 | * @return boolean |
||
| 478 | */ |
||
| 479 | public function searchByNotation() |
||
| 480 | { |
||
| 481 | return $this->getBoolean('skosmos:searchByNotation'); |
||
| 482 | } |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Returns skosmos:marcSourcecode value set in config.ttl. |
||
| 486 | * @return string marcsource name |
||
| 487 | */ |
||
| 488 | public function getMarcSourceCode($lang = null) |
||
| 489 | { |
||
| 490 | return $this->getLiteral('skosmos:marcSourceCode', false, $lang); |
||
| 491 | } |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Returns the boolean value of the skosmos:showNotationAsProperty setting. |
||
| 495 | * @return boolean |
||
| 496 | */ |
||
| 497 | public function getShowNotationAsProperty() |
||
| 498 | { |
||
| 499 | return $this->getBoolean('skosmos:showNotationAsProperty', true); |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Returns a boolean value set in the config.ttl config. |
||
| 504 | * @return array array of concept class URIs (can be empty) |
||
| 505 | */ |
||
| 506 | public function getIndexClasses() |
||
| 507 | { |
||
| 508 | return $this->getResources("skosmos:indexShowClass"); |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Returns skosmos:externalProperty values set in the config.ttl config. |
||
| 513 | * @return array array of external property URIs (can be empty) |
||
| 514 | */ |
||
| 515 | public function getExtProperties() |
||
| 516 | { |
||
| 517 | return $this->getResources("skosmos:externalProperty"); |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Get the languages supported by this vocabulary |
||
| 522 | * @return array languages supported by this vocabulary (as language tag strings) |
||
| 523 | */ |
||
| 524 | public function getLanguages() |
||
| 525 | { |
||
| 526 | $langs = $this->resource->allLiterals('skosmos:language'); |
||
| 527 | $ret = array(); |
||
| 528 | foreach ($langs as $lang) { |
||
| 529 | $langlit = Punic\Language::getName($lang->getValue(), $this->getLang()); |
||
| 530 | $ret[$langlit] = $lang->getValue(); |
||
| 531 | } |
||
| 532 | ksort($ret); |
||
| 533 | |||
| 534 | return $ret; |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Returns the parameters of parameterized plugins |
||
| 539 | * @return array of plugin parameters |
||
| 540 | */ |
||
| 541 | public function getPluginParameters() |
||
| 542 | { |
||
| 543 | return $this->pluginParameters; |
||
| 544 | } |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Get the list of property label overrides |
||
| 548 | * @return array of custom property labels |
||
| 549 | */ |
||
| 550 | public function getPropertyLabelOverrides() |
||
| 551 | { |
||
| 552 | return $this->labelOverrides; |
||
| 553 | } |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Returns the vocabulary default sidebar view. |
||
| 557 | * @return string name of the view |
||
| 558 | */ |
||
| 559 | public function getDefaultSidebarView() |
||
| 560 | { |
||
| 561 | $defview = $this->resource->getLiteral('skosmos:defaultSidebarView'); |
||
| 562 | $sidebarViews = $this->getSidebarViews(); |
||
| 563 | if ($defview) { |
||
| 564 | $value = $defview->getValue(); |
||
| 565 | if (in_array($value, $sidebarViews)) { |
||
| 566 | return $value; |
||
| 567 | } else { |
||
| 568 | return $sidebarViews[0]; // if not in sidebarViews, displaying first provided view |
||
| 569 | } |
||
| 570 | } |
||
| 571 | |||
| 572 | if (in_array('alphabetical', $sidebarViews)) { |
||
| 573 | return 'alphabetical'; // if not defined, displaying alphabetical index |
||
| 574 | } else { |
||
| 575 | return $sidebarViews[0]; // if no alphabetical index, displaying first provided view |
||
| 576 | } |
||
| 577 | } |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Returns the concept page default sidebar view. |
||
| 581 | * @return string name of the view |
||
| 582 | */ |
||
| 583 | public function getDefaultConceptSidebarView() |
||
| 584 | { |
||
| 585 | $defview = $this->resource->getLiteral('skosmos:defaultConceptSidebarView'); |
||
| 586 | $sidebarViews = $this->getSidebarViews(); |
||
| 587 | if ($defview) { |
||
| 588 | $value = $defview->getValue(); |
||
| 589 | if (in_array($value, $sidebarViews)) { |
||
| 590 | return $value; |
||
| 591 | } else { |
||
| 592 | return $sidebarViews[0]; // if not in sidebarViews, displaying first provided view |
||
| 593 | } |
||
| 594 | } |
||
| 595 | |||
| 596 | if (in_array('hierarchy', $sidebarViews)) { |
||
| 597 | return 'hierarchy'; // if not defined, displaying hierarchy |
||
| 598 | } else { |
||
| 599 | return $sidebarViews[0]; // if no hierarchy, displaying first provided view |
||
| 600 | } |
||
| 601 | } |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Returns sidebar views used in this vocabulary |
||
| 605 | * @return array of available views |
||
| 606 | */ |
||
| 607 | public function getSidebarViews() |
||
| 620 | |||
| 621 | } |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Extracts the vocabulary id string from the baseuri of the vocabulary. |
||
| 625 | * @return string identifier eg. 'mesh'. |
||
| 626 | */ |
||
| 627 | public function getId() |
||
| 639 | } |
||
| 640 | |||
| 641 | public function getShowStatistics() |
||
| 642 | { |
||
| 643 | return $this->getBoolean('skosmos:showStatistics', true); |
||
| 644 | } |
||
| 645 | |||
| 646 | public function getPluginRegister() |
||
| 647 | { |
||
| 648 | return $this->pluginRegister; |
||
| 649 | } |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Returns the property/properties used for visualizing concept hierarchies. |
||
| 653 | * @return array array class URI or null |
||
| 654 | */ |
||
| 655 | |||
| 656 | public function getHierarchyProperty() |
||
| 657 | { |
||
| 658 | $resources = $this->resource->allResources("skosmos:hierarchyProperty"); |
||
| 659 | $ret = array(); |
||
| 660 | foreach ($resources as $res) { |
||
| 661 | $prop = $res->getURI(); |
||
| 662 | if (EasyRdf\RdfNamespace::shorten($prop) !== null) { // prefixing if possible |
||
| 663 | $prop = EasyRdf\RdfNamespace::shorten($prop); |
||
| 664 | } |
||
| 665 | |||
| 666 | $ret[] = $prop; |
||
| 667 | } |
||
| 668 | return empty($ret) ? array('skos:broader') : $ret; |
||
| 669 | } |
||
| 670 | |||
| 671 | /** |
||
| 672 | * Returns a boolean value set in the config.ttl config. |
||
| 673 | * @return boolean |
||
| 674 | */ |
||
| 675 | public function showNotation() |
||
| 676 | { |
||
| 677 | return $this->getBoolean('skosmos:showNotation', true); |
||
| 678 | } |
||
| 679 | |||
| 680 | /** |
||
| 681 | * Returns the alphabetical list qualifier in this vocabulary, |
||
| 682 | * or null if not set. |
||
| 683 | * @return EasyRdf\Resource|null alphabetical list qualifier resource or null |
||
| 684 | */ |
||
| 685 | public function getAlphabeticalListQualifier() |
||
| 686 | { |
||
| 687 | return $this->resource->getResource('skosmos:alphabeticalListQualifier'); |
||
| 688 | } |
||
| 689 | |||
| 690 | /** |
||
| 691 | * Returns a boolean value set in the config.ttl config. |
||
| 692 | * @return boolean |
||
| 693 | */ |
||
| 694 | public function getShowDeprecated() |
||
| 695 | { |
||
| 696 | return $this->getBoolean('skosmos:showDeprecated', false); |
||
| 697 | } |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Returns a boolean value set in the config.ttl config. |
||
| 701 | * @return boolean |
||
| 702 | */ |
||
| 703 | public function getShowDeprecatedChanges() |
||
| 704 | { |
||
| 705 | return $this->getBoolean('skosmos:showDeprecatedChanges', false); |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Returns the vocabulary dc:type value(s) with their labels and uris, if set in the vocabulary configuration. |
||
| 710 | * @return array of objects or an empty array |
||
| 711 | */ |
||
| 712 | public function getTypes($lang = null) |
||
| 713 | { |
||
| 714 | $resources = $this->resource->allResources("dc:type"); |
||
| 715 | $ret = array(); |
||
| 716 | foreach ($resources as $res) { |
||
| 717 | $prop = $res->getURI(); |
||
| 718 | $label = $res->label($lang) ? $res->label($lang) : $res->label($this->getDefaultLanguage()); |
||
| 719 | $ret[] = array('uri' => $prop, 'prefLabel' => $label->getValue()); |
||
| 720 | } |
||
| 721 | return $ret; |
||
| 722 | } |
||
| 723 | |||
| 724 | /** |
||
| 725 | * Returns an array of fallback languages that is ordered by priority and |
||
| 726 | * defined in the vocabulary configuration as a collection. |
||
| 727 | * Additionally, the chosen content language is inserted with the highest priority |
||
| 728 | * and the vocab default language is inserted with the lowest priority. |
||
| 729 | * @param string $clang |
||
| 730 | * @return array of language code strings |
||
| 731 | */ |
||
| 732 | public function getLanguageOrder($clang) |
||
| 733 | { |
||
| 734 | if (array_key_exists($clang, $this->languageOrderCache)) { |
||
| 735 | return $this->languageOrderCache[$clang]; |
||
| 736 | } |
||
| 737 | $ret = array($clang); |
||
| 738 | $fallbacks = !empty($this->resource->get('skosmos:fallbackLanguages')) ? $this->resource->get('skosmos:fallbackLanguages') : array(); |
||
| 739 | foreach ($fallbacks as $lang) { |
||
| 740 | if (!in_array($lang, $ret)) { |
||
| 741 | $ret[] = (string)$lang; // Literal to string conversion |
||
| 742 | } |
||
| 743 | } |
||
| 744 | if (!in_array($this->getDefaultLanguage(), $ret)) { |
||
| 745 | $ret[] = (string)$this->getDefaultLanguage(); |
||
| 746 | } |
||
| 747 | foreach ($this->getLanguages() as $lang) { |
||
| 748 | if (!in_array($lang, $ret)) { |
||
| 749 | $ret[] = $lang; |
||
| 750 | } |
||
| 751 | } |
||
| 752 | // store in cache so this doesn't have to be computed again |
||
| 753 | $this->languageOrderCache[$clang] = $ret; |
||
| 754 | return $ret; |
||
| 755 | } |
||
| 756 | |||
| 757 | /** |
||
| 758 | * @return boolean |
||
| 759 | */ |
||
| 760 | public function isUseModifiedDate() |
||
| 763 | } |
||
| 764 | |||
| 765 | /** |
||
| 766 | * @return array |
||
| 767 | */ |
||
| 768 | public function getPropertyOrder() |
||
| 769 | { |
||
| 770 | $order = $this->getResource()->getResource('skosmos:propertyOrder'); |
||
| 771 | if ($order === null) { |
||
| 772 | return self::DEFAULT_PROPERTY_ORDER; |
||
| 773 | } |
||
| 774 | |||
| 775 | $short = EasyRdf\RdfNamespace::shorten($order); |
||
| 776 | if ($short == 'skosmos:iso25964PropertyOrder') { |
||
| 777 | return self::ISO25964_PROPERTY_ORDER; |
||
| 778 | } elseif ($short == 'skosmos:defaultPropertyOrder') { |
||
| 779 | return self::DEFAULT_PROPERTY_ORDER; |
||
| 780 | } |
||
| 781 | |||
| 782 | // check for custom order definition |
||
| 783 | $orderList = $order->getResource('rdf:value'); |
||
| 784 | if ($orderList !== null && $orderList instanceof EasyRdf\Collection) { |
||
| 795 | } |
||
| 796 | } |
||
| 797 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.