Skip to content

Commit

Permalink
[#12] Add links.primo to PrimoRecordGroup
Browse files Browse the repository at this point in the history
The current link format yields strange results though, see #12 for more info.
  • Loading branch information
danmichaelo committed Oct 31, 2016
1 parent b36bb99 commit 40ae161
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
44 changes: 8 additions & 36 deletions app/PrimoRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BCLib\PrimoServices\QueryTerm;
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement;

class PrimoRecord implements \JsonSerializable
class PrimoRecord extends PrimoResult implements \JsonSerializable
{
public $orderedMaterialList = ['e-books', 'print-books'];
protected $brief;
Expand Down Expand Up @@ -192,25 +192,16 @@ function extractGetIts($getits)
return $out;
}

public function primoLink()
public function link()
{
if ($this->multiple_editions) {

$queryTerm = new QueryTerm();
$queryTerm->set('facet_frbrgroupid', QueryTerm::EXACT, $this->id);

return 'http://' . $this->deeplinkProvider->view('UBO')
->search($queryTerm, null, 'library_catalogue');

} else {
return 'http://' . $this->deeplinkProvider->view('UBO')
->link($this->id);
}
return url('primo/records/' .$this->id);
}

public function link()
public function primoLink()
{
return url('primo/records/' .$this->id);
return 'http://' . $this->deeplinkProvider
->view('UBO')
->link($this->id);
}

public function groupLink()
Expand All @@ -228,25 +219,6 @@ public function jsonSerialize()
return toArray('full');
}

public function toArray($fullRepr=false)
{
$data = $this->brief;
$data['links'] = [
'self' => $this->link(),
];
if ($fullRepr) {
$data['links']['primo'] = $this->primoLink();
$data['links']['group'] = $this->groupLink();
$data['links']['cover'] = $this->coverLink();
// $this->addLocations();
}

if ($fullRepr) {
$data = array_merge($data, $this->full);
}
return $data;
}

public function & getComponent(&$components, $id)
{
if (count($components) == 1) {
Expand Down Expand Up @@ -413,4 +385,4 @@ private function extractArray(QuiteSimpleXMLElement $group, $xpath)
}, $group->all($xpath));
}

}
}
21 changes: 12 additions & 9 deletions app/PrimoRecordGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use BCLib\PrimoServices\QueryTerm;
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement;

class PrimoRecordGroup implements \JsonSerializable
class PrimoRecordGroup extends PrimoResult implements \JsonSerializable
{
protected $brief;
protected $full;
Expand Down Expand Up @@ -40,6 +40,16 @@ public function link()
return url('primo/groups/' .$this->id);
}

public function primoLink()
{
$queryTerm = new QueryTerm();
$queryTerm->set('facet_frbrgroupid', QueryTerm::EXACT, $this->id);

return 'http://' . $this->deeplinkProvider
->view('UBO')
->search($queryTerm, 'bibsys_ils', 'library_catalogue');
}

public function process()
{
$record = $this->doc->first('./p:PrimoNMBib/p:record');
Expand All @@ -54,13 +64,6 @@ public function process()
return $this;
}

public function toArray($expanded=false)
{
$data = $this->brief;
$data['links']['self'] = $this->link();
return $data;
}

public function jsonSerialize()
{
return $this->toArray();
Expand All @@ -73,4 +76,4 @@ private function extractArray(QuiteSimpleXMLElement $group, $xpath)
}, $group->all($xpath));
}

}
}
33 changes: 33 additions & 0 deletions app/PrimoResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App;

use BCLib\PrimoServices\DeepLink;
use BCLib\PrimoServices\QueryTerm;
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement;

class PrimoResult
{

public function toArray($fullRepr=false)
{
$data = $this->brief;
$data['links'] = [
'self' => $this->link(),
];
if ($fullRepr) {
$data['links']['primo'] = $this->primoLink();
if ($this instanceof PrimoRecord) {
$data['links']['group'] = $this->groupLink();
$data['links']['cover'] = $this->coverLink();
}
// $this->addLocations();
}

if ($fullRepr) {
$data = array_merge($data, $this->full);
}
return $data;
}

}

0 comments on commit 40ae161

Please sign in to comment.