diff --git a/src/Object/ResourceObject.php b/src/Object/ResourceObject.php index 1a38f74..89dfde8 100644 --- a/src/Object/ResourceObject.php +++ b/src/Object/ResourceObject.php @@ -4,8 +4,8 @@ use Drupal\acdh_repo_gui\Helper\ArcheHelper as Helper; -class ResourceObject { - +class ResourceObject +{ private $config; private $properties; private $acdhid; @@ -14,7 +14,8 @@ class ResourceObject { private $thumbUrl = 'https://arche-thumbnails.acdh.oeaw.ac.at/'; private $biblatexUrl = 'https://arche-biblatex.acdh.oeaw.ac.at/'; - public function __construct(array $data, $config, string $language = 'en') { + public function __construct(array $data, $config, string $language = 'en') + { $this->properties = array(); $this->config = $config; $this->language = $language; @@ -39,7 +40,8 @@ public function __construct(array $data, $config, string $language = 'en') { * Get the biblatex disserv url * @return string */ - public function getBiblatexUrl(): string { + public function getBiblatexUrl(): string + { return $this->biblatexUrl . '?id=' . $this->getAcdhID() . '&lang=' . $this->language; } @@ -49,7 +51,8 @@ public function getBiblatexUrl(): string { * @param string $property * @return array */ - public function getData(string $property): array { + public function getData(string $property): array + { return (isset($this->properties[$property]) && !empty($this->properties[$property])) ? $this->properties[$property] : array(); } @@ -60,7 +63,8 @@ public function getData(string $property): array { * @param string $prop * @param array $v */ - private function setData(string $prop = null, array $v = array()) { + private function setData(string $prop = null, array $v = array()) + { if ( isset($prop) && count((array) $v) > 0 ) { @@ -73,7 +77,8 @@ private function setData(string $prop = null, array $v = array()) { * * @return string */ - public function getTitle(): string { + public function getTitle(): string + { if (isset($this->properties["acdh:hasTitle"][0]->title) && !empty($this->properties["acdh:hasTitle"][0]->title)) { return $this->properties["acdh:hasTitle"][0]->title; } @@ -90,7 +95,8 @@ public function getTitle(): string { * * @return array */ - public function getIdentifiers(): array { + public function getIdentifiers(): array + { return (isset($this->properties["acdh:hasIdentifier"]) && !empty($this->properties["acdh:hasIdentifier"])) ? $this->properties["acdh:hasIdentifier"] : array(); } @@ -99,7 +105,8 @@ public function getIdentifiers(): array { * * @return type */ - public function getNonAcdhIdentifiers(): array { + public function getNonAcdhIdentifiers(): array + { $result = array(); if (isset($this->properties["acdh:hasIdentifier"]) && !empty($this->properties["acdh:hasIdentifier"])) { foreach ($this->properties["acdh:hasIdentifier"] as $k => $v) { @@ -119,10 +126,11 @@ public function getNonAcdhIdentifiers(): array { * * @return string */ - public function getPid(): string { + public function getPid(): string + { return ( isset($this->properties["acdh:hasPid"][0]->value) && !empty($this->properties["acdh:hasPid"][0]->value) && ( - (strpos($this->properties["acdh:hasPid"][0]->value, 'http://') !== false) || + (strpos($this->properties["acdh:hasPid"][0]->value, 'http://') !== false) || (strpos($this->properties["acdh:hasPid"][0]->value, 'https://') !== false) ) ) ? $this->properties["acdh:hasPid"][0]->value : ""; @@ -133,7 +141,8 @@ public function getPid(): string { * * @return string */ - public function getInsideUrl(): string { + public function getInsideUrl(): string + { if (isset($this->properties["acdh:hasIdentifier"])) { foreach ($this->properties["acdh:hasIdentifier"] as $v) { if (isset($v->acdhid) && !empty($v->acdhid)) { @@ -148,7 +157,8 @@ public function getInsideUrl(): string { * Get the available date in a specified format * @return string */ - public function getAvailableDate(): string { + public function getAvailableDate(): string + { if (isset($this->properties["acdh:hasAvailableDate"])) { foreach ($this->properties["acdh:hasAvailableDate"] as $v) { if (isset($v->value)) { @@ -165,7 +175,8 @@ public function getAvailableDate(): string { * * @return string */ - public function getUUID(): string { + public function getUUID(): string + { if (isset($this->properties["acdh:hasIdentifier"])) { foreach ($this->properties["acdh:hasIdentifier"] as $v) { if (isset($v->acdhid) && !empty($v->acdhid)) { @@ -181,7 +192,8 @@ public function getUUID(): string { * * @return string */ - public function getAcdhID(): string { + public function getAcdhID(): string + { if (isset($this->properties["acdh:hasIdentifier"])) { foreach ($this->properties["acdh:hasIdentifier"] as $v) { if (strpos($v->value, '/id.acdh.oeaw.ac.at/') !== false) { @@ -197,7 +209,8 @@ public function getAcdhID(): string { * * @return string */ - public function getRepoUrl(): string { + public function getRepoUrl(): string + { if (!isset($this->repoid) && empty($this->repoid)) { $this->getRepoID(); } @@ -208,7 +221,8 @@ public function getRepoUrl(): string { * Get the Gui related url for the resource * @return string */ - public function getRepoGuiUrl(): string { + public function getRepoGuiUrl(): string + { if (!isset($this->repoid) && empty($this->repoid)) { $this->getRepoID(); } @@ -219,7 +233,8 @@ public function getRepoGuiUrl(): string { * Get the repo identifier * @return string */ - public function getRepoID(): string { + public function getRepoID(): string + { if (isset($this->properties["acdh:hasIdentifier"])) { foreach ($this->properties["acdh:hasIdentifier"] as $v) { if (isset($v->id) && !empty($v->id)) { @@ -241,13 +256,14 @@ public function getRepoID(): string { * * @return array */ - public function getAccessRestriction(): array { + public function getAccessRestriction(): array + { $result = array(); if (isset($this->properties["acdh:hasAccessRestriction"])) { foreach ($this->properties["acdh:hasAccessRestriction"] as $v) { if (isset($v->title) && !empty($v->title)) { $result['title'] = $v->title; - } else if (isset($v->value) && !empty($v->value)) { + } elseif (isset($v->value) && !empty($v->value)) { $result['title'] = $v->value; } @@ -267,7 +283,8 @@ public function getAccessRestriction(): array { * * @return string */ - public function getTitleImage(string $width = '200px'): string { + public function getTitleImage(string $width = '200px'): string + { $img = ''; $imgBinary = ''; $width = str_replace('px', '', $width); @@ -291,7 +308,8 @@ public function getTitleImage(string $width = '200px'): string { * @param string $width * @return string */ - public function getTitleImageUrl(string $width = '200px'): string { + public function getTitleImageUrl(string $width = '200px'): string + { $img = ''; $imgBinary = ''; $width = str_replace('px', '', $width); @@ -313,7 +331,8 @@ public function getTitleImageUrl(string $width = '200px'): string { * Check if we have a titleimage id or not * @return bool */ - public function isTitleImage(): bool { + public function isTitleImage(): bool + { if (!empty($this->getAcdhID())) { return true; } @@ -325,12 +344,13 @@ public function isTitleImage(): bool { * * @return string */ - public function getAcdhType(): string { + public function getAcdhType(): string + { if (isset($this->properties["rdf:type"])) { foreach ($this->properties["rdf:type"] as $v) { if (isset($v->title) && !empty($v->title) && (strpos($v->title, 'https://vocabs.acdh.oeaw.ac.at/schema#') !== false)) { return str_replace('https://vocabs.acdh.oeaw.ac.at/schema#', '', $v->title); - } else if (isset($v->value) && !empty($v->value) && (strpos($v->value, 'https://vocabs.acdh.oeaw.ac.at/schema#') !== false)) { + } elseif (isset($v->value) && !empty($v->value) && (strpos($v->value, 'https://vocabs.acdh.oeaw.ac.at/schema#') !== false)) { return str_replace('https://vocabs.acdh.oeaw.ac.at/schema#', '', $v->value); } } @@ -342,13 +362,14 @@ public function getAcdhType(): string { * Display all RDF:Type Values * @return array */ - public function getRdfTypes(): array { + public function getRdfTypes(): array + { $result = array(); if (isset($this->properties["rdf:type"])) { foreach ($this->properties["rdf:type"] as $v) { if (isset($v->title) && !empty($v->title) && (strpos($v->title, 'https://vocabs.acdh.oeaw.ac.at/schema#') !== false)) { $result[] = Helper::createShortcut($v->title); - } else if (isset($v->value) && !empty($v->value) && (strpos($v->value, 'https://vocabs.acdh.oeaw.ac.at/schema#') !== false)) { + } elseif (isset($v->value) && !empty($v->value) && (strpos($v->value, 'https://vocabs.acdh.oeaw.ac.at/schema#') !== false)) { $result[] = Helper::createShortcut($v->value); } } @@ -361,12 +382,13 @@ public function getRdfTypes(): array { * * @return string */ - public function getSkosType(): string { + public function getSkosType(): string + { if (isset($this->properties["rdf:type"])) { foreach ($this->properties["rdf:type"] as $v) { if (isset($v->title) && !empty($v->title) && (strpos($v->title, 'http://www.w3.org/2004/02/skos/core#') !== false)) { return str_replace('http://www.w3.org/2004/02/skos/core#', '', $v->title); - } else if (isset($v->title) && !empty($v->value) && (strpos($v->value, 'http://www.w3.org/2004/02/skos/core#') !== false)) { + } elseif (isset($v->title) && !empty($v->value) && (strpos($v->value, 'http://www.w3.org/2004/02/skos/core#') !== false)) { return str_replace('http://www.w3.org/2004/02/skos/core#', '', $v->value); } } @@ -379,7 +401,8 @@ public function getSkosType(): string { * * @return array */ - public function getExpertTableData(): array { + public function getExpertTableData(): array + { return $this->properties; } @@ -390,7 +413,8 @@ public function getExpertTableData(): array { * @param string $dateFormat * @return string */ - public function getFormattedDateByProperty(string $property, string $dateFormat = 'Y'): string { + public function getFormattedDateByProperty(string $property, string $dateFormat = 'Y'): string + { if (isset($this->properties[$property])) { if (isset($this->properties[$property][0]->value)) { $val = strtotime($this->properties[$property][0]->value); @@ -404,7 +428,8 @@ public function getFormattedDateByProperty(string $property, string $dateFormat * Select the identifier for the Copy resource link * @return string */ - public function getCopyResourceLink(): string { + public function getCopyResourceLink(): string + { //check the pid if (!empty($this->getPid())) { return $this->getPid(); @@ -431,16 +456,17 @@ public function getCopyResourceLink(): string { * Create the JS string for the leaflet map MultiPolyLang * @return string */ - public function getMultiPolygonForLeaflet(): string { + public function getMultiPolygonForLeaflet(): string + { $str = ""; if (isset($this->properties["acdh:hasWKT"][0]->title) && !empty($this->properties["acdh:hasWKT"][0]->title)) { $data = explode(" ", $this->properties["acdh:hasWKT"][0]->title); foreach ($data as $d) { if (strpos($d, 'MULTIPOLYGON') !== false) { $d = str_replace('MULTIPOLYGON', '', $d); - } else if (strpos($d, '(') !== false) { + } elseif (strpos($d, '(') !== false) { $d = str_replace('(', '', $d); - } else if (strpos($d, ')))') !== false) { + } elseif (strpos($d, ')))') !== false) { $d = str_replace(')))', ',', $d); } if (!empty($d)) { @@ -460,12 +486,12 @@ public function getMultiPolygonForLeaflet(): string { * Get the first coordinate for the multipolygon leaflet map * @return string */ - public function getMultiPolygonFirstCoordinate(): string { + public function getMultiPolygonFirstCoordinate(): string + { $multi = $this->getMultiPolygonForLeaflet(); if (!empty($multi)) { return explode("],", $multi)[0] . "]"; } return ""; } - }