Skip to content

Commit

Permalink
Init IIIF collection assemble.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mat Jordan committed May 3, 2021
1 parent 307f5b9 commit c4d11e6
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 12 deletions.
4 changes: 4 additions & 0 deletions collection/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ index.php?url=/$1 [QSA,L]
</IfModule>
38 changes: 38 additions & 0 deletions collection/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

require "../run.php";

use Src\Collection;

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uri = explode( '/', $uri );

// the namespace must be an string
if (isset($uri[3])) {
$namespace = $uri[3];
}

// the persistentIdentifier PID must be an int
if (isset($uri[4])) {
$id = $uri[4];
}

if (isset($namespace) && isset($id)) {

$requestMethod = $_SERVER["REQUEST_METHOD"];

$controller = new Collection($requestMethod, array($namespace, $id));
$controller->processRequest();

} else {

header("HTTP/1.1 404 Not Found");
exit();

}
72 changes: 72 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Src;

error_reporting(E_ALL);

class Collection
{

private $requestMethod;
private $persistentIdentifier;

public function __construct($requestMethod, $persistentIdentifier)
{

$this->requestMethod = $requestMethod;
$this->persistentIdentifier = $persistentIdentifier;

}

public function processRequest()
{

switch ($this->requestMethod) {
case 'GET':
$response = self::theCollection();
break;
default:
$response = self::noFoundResponse();
break;
}

print $response;

}

private function theCollection()
{

$persistentIdentifier = implode('%3A', $this->persistentIdentifier);
$object = Request::getObjects($persistentIdentifier);

if ($object['status'] === 200) :
$model = simplexml_load_string($object['body'])->objModels->model;
if (self::isCollection($model)) :
$object = Request::getObjects($persistentIdentifier, 'XML', true);
return json_encode($object);
else :
$object['body'] = 'Object ' . str_replace('%3A', ':', $persistentIdentifier) . ' is not of object model islandora:collectionCModel.';
return json_encode($object);
endif;
else :
return json_encode($object);
endif;

}

private static function isCollection ($islandoraModel) {

$model = Utility::xmlToArray($islandoraModel);

if (in_array('info:fedora/islandora:collectionCModel', $model)) :
return true;
else:
return false;
endif;

}

}

?>
7 changes: 0 additions & 7 deletions src/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ private function cacheManifest ($manifest)

}

private function removeExpired ($id)
{

return true;

}

private function noFoundResponse()
{

Expand Down
13 changes: 8 additions & 5 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ public static function responseBody($uri) {

}

public static function getObjects($pid, $format = 'XML') {

$request = $_ENV['FEDORA_URL'] . '/objects/' . $pid;

if ($format) :
public static function getObjects($pid, $format = 'XML', $isMemberOf = false) {

if ($isMemberOf) :
$request = $_ENV['FEDORA_URL'] . '/objects';
$request .= '?query=pid%7E' . explode('%3A', $pid)[1] . '*&pid=true';
$request .= '&resultFormat=' . $format;
else :
$request = $_ENV['FEDORA_URL'] . '/objects/' . $pid;
$request .= '?format=' . $format;
endif;

Expand Down

0 comments on commit c4d11e6

Please sign in to comment.