Skip to content

Commit

Permalink
PHP code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Github Actions Workflow committed May 19, 2021
1 parent cf6138c commit a89d3ea
Showing 1 changed file with 63 additions and 37 deletions.
100 changes: 63 additions & 37 deletions src/Object/ResourceObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Drupal\acdh_repo_gui\Helper\ArcheHelper as Helper;

class ResourceObject {

class ResourceObject
{
private $config;
private $properties;
private $acdhid;
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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();
}

Expand All @@ -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
) {
Expand All @@ -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;
}
Expand All @@ -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();
}

Expand All @@ -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) {
Expand All @@ -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 : "";
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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)) {
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -379,7 +401,8 @@ public function getSkosType(): string {
*
* @return array
*/
public function getExpertTableData(): array {
public function getExpertTableData(): array
{
return $this->properties;
}

Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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)) {
Expand All @@ -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 "";
}

}

0 comments on commit a89d3ea

Please sign in to comment.