diff --git a/src/Helper/ArcheApiHelper.php b/src/Helper/ArcheApiHelper.php index e4b27ec..e39e779 100644 --- a/src/Helper/ArcheApiHelper.php +++ b/src/Helper/ArcheApiHelper.php @@ -13,8 +13,8 @@ * * @author norbertczirjak */ -class ArcheApiHelper { - +class ArcheApiHelper +{ use \Drupal\acdh_repo_gui\Traits\ArcheUtilTrait; private $data = array(); @@ -23,7 +23,8 @@ class ArcheApiHelper { private $properties; private $requiredClasses = array(); - public function createView(array $data = array(), string $apiType = '', string $lng = 'en'): array { + public function createView(array $data = array(), string $apiType = '', string $lng = 'en'): array + { (!empty($lng)) ? $this->siteLang = strtolower($lng) : $this->siteLang = "en"; if (count($data) == 0 && !empty($apiType)) { return array(); @@ -78,7 +79,8 @@ public function createView(array $data = array(), string $apiType = '', string $ /** * Create the inverse result for the datatable */ - private function formatInverseData() { + private function formatInverseData() + { $this->result = array(); foreach ($this->data as $id => $obj) { foreach ($obj as $o) { @@ -94,7 +96,8 @@ private function formatInverseData() { /** * Format the sql result to the getMembers api endpoint */ - private function formatMembersData() { + private function formatMembersData() + { $this->result = array(); foreach ($this->data as $obj) { $this->result[] = array("$obj->title"); @@ -104,7 +107,8 @@ private function formatMembersData() { /** * Format the sql result to the Related Publications and Resources api endpoint */ - private function formatRPRData() { + private function formatRPRData() + { $this->result = array(); foreach ($this->data as $obj) { $this->result[] = array( @@ -119,7 +123,8 @@ private function formatRPRData() { * Create the reponse header * @param array $data */ - private function setupMetadataType(array $data = array()) { + private function setupMetadataType(array $data = array()) + { $this->creatMetadataObj($data); if (count($data['properties']) > 0) { $this->data = $data['properties']; @@ -135,7 +140,8 @@ private function setupMetadataType(array $data = array()) { /** * format the collections and binaries count response */ - private function formatCollsBinsCount() { + private function formatCollsBinsCount() + { $this->result['$schema'] = "http://json-schema.org/draft-07/schema#"; $collections = "0"; $files = "0"; @@ -158,7 +164,8 @@ private function formatCollsBinsCount() { /** * Format the data for the metadata api request */ - private function formatMetadataView() { + private function formatMetadataView() + { foreach ($this->data as $v) { $prop = str_replace('https://vocabs.acdh.oeaw.ac.at/schema#', '', $v->property); @@ -205,7 +212,8 @@ private function formatMetadataView() { * @param array $data * @return string */ - private function checkCardinality(string $prop, object $obj) { + private function checkCardinality(string $prop, object $obj) + { if (isset($obj->min)) { $this->result['properties'][$prop]['minItems'] = (int) $obj->min; if ($obj->min >= 1) { @@ -239,7 +247,8 @@ private function checkCardinality(string $prop, object $obj) { * Create properties obj with values from the metadata api request * @param array $data */ - private function creatMetadataObj(array $data) { + private function creatMetadataObj(array $data) + { $this->properties = new \stdClass(); if (isset($data['class'])) { @@ -256,7 +265,8 @@ private function creatMetadataObj(array $data) { /** * Format the basic APi views */ - private function formatView() { + private function formatView() + { $this->result = array(); foreach ($this->data as $k => $val) { foreach ($val as $v) { @@ -280,7 +290,8 @@ private function formatView() { /** * Format the checkIdentifier api call result */ - private function formatCheckIdentifierData() { + private function formatCheckIdentifierData() + { $this->result = array(); foreach ($this->data as $val) { if ($val->property == 'https://vocabs.acdh.oeaw.ac.at/schema#hasAvailableDate') { @@ -298,7 +309,8 @@ private function formatCheckIdentifierData() { /** * create the GNDfile for the GND API */ - private function createGNDFile() { + private function createGNDFile() + { $host = str_replace('http://', 'https://', \Drupal::request()->getSchemeAndHttpHost() . '/browser/oeaw_detail/'); $fileLocation = \Drupal::request()->getSchemeAndHttpHost() . '/browser/sites/default/files/beacon.txt';