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 Jul 15, 2021
1 parent d962b1e commit 0b55032
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/Helper/ArcheApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*
* @author norbertczirjak
*/
class ArcheApiHelper {

class ArcheApiHelper
{
use \Drupal\acdh_repo_gui\Traits\ArcheUtilTrait;

private $data = array();
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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("<a id='archeHref' href='/browser/oeaw_detail/$obj->id'>$obj->title</a>");
Expand All @@ -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(
Expand All @@ -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'];
Expand All @@ -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";
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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'])) {
Expand All @@ -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) {
Expand All @@ -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') {
Expand All @@ -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';

Expand Down

0 comments on commit 0b55032

Please sign in to comment.