Commit 93e5ab4c authored by root's avatar root
Browse files

Bugfixing and added catalog.gz

parent e0f1a3a4
......@@ -8,6 +8,8 @@ use \Psr\Http\Message\ResponseInterface as Response;
require __DIR__.'/../vendor/autoload.php';
ini_set('memory_limit' , '3g');
# Slim
$configuration = [
'settings' => [
......
......@@ -24,7 +24,8 @@ class BarcodeUtil {
}
function getSpecimen($barcode){
return ($this->isValid($barcode)) ? $this->db->query($this->querytemplate_one, [$barcode]) : null;
$specimens = ($this->isValid($barcode)) ? $this->db->query($this->querytemplate_one, [$barcode]) : null;
return (isset($specimens)) ? $specimens[0] : null;
}
function getAllSpecimen(){
......@@ -33,6 +34,8 @@ class BarcodeUtil {
function getAllSpecimenEscaped(){
$specimens = $this->getAllSpecimen();
return $specimens;
return (isset($specimens)) ? array_map(function ($s) { return $this->escape($s); }, $specimens) : null;
}
......
......@@ -37,10 +37,9 @@ class Database {
function query($stmt, $params=[]){
$query = \sqlsrv_query($this->connection, $stmt, $params);
$result = \sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC);
if(count($result) == 0) return NULL;
while($row = \sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC)){
$result[] = $row;
}
return $result;
}
}
......
File added
......@@ -13,18 +13,27 @@ $app->get('/object[/[{barcode}]]', function ($request, $response, $args) {
$params = $request->getParams();
$barcode = (isset($args['barcode'])) ? $args['barcode'] : ((isset($params['barcode'])) ? $params['barcode'] : null);
## Preferred content type of client
$negotiation = new Negotiation();
$bestContentType = $negotiation->mimeBest(implode($request->getHeaders()['HTTP_ACCEPT']), Config::get('contenttypes')['prefs']);
## If no barcode is given, redirect to catalog
if(!isset($barcode))
if(!isset($barcode)){
## rdf
if($bestContentType === Config::get('contenttypes')['rdf']){
$specimens = $barcodeUtil->getAllSpecimenEscaped();
return $this->view->render($response, 'sitemap.rdf.template.twig', [
'specimens' => $specimens,
'config' => Config::get('sitemap')
])->withHeader('Content-type', 'application/xml');
}
return $response->withRedirect(Config::get('urls')['catalog_url']);
}
## If barcode was not found in DB, return 404
if(!$barcodeUtil->isInDB($barcode))
return $this->view->render($response, '404.template.twig')->withStatus(404);
## Preferred content type of client
$negotiation = new Negotiation();
$bestContentType = $negotiation->mimeBest(implode($request->getHeaders()['HTTP_ACCEPT']), Config::get('contenttypes')['prefs']);
## html
if($bestContentType === Config::get('contenttypes')['html'])
return $response->withRedirect($this->get('router')->pathFor('page', [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment