Skip to content

Commit 631af94

Browse files
committed
Add portfolios and representations
1 parent 804c7f5 commit 631af94

29 files changed

+2089
-66
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Add portfolios and representations to Bib objects.
12+
913
### Fixed
1014

1115
- Set MMS id on Bib object when initiated from SRU response.

README.md

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ If the package doesn't fit your needs, you might take a look at the alternative
1414

1515
## Table of Contents
1616

17-
* [Table of Contents](#table-of-contents)
1817
* [Install using Composer](#install-using-composer)
1918
* [Initializing a client](#initializing-a-client)
2019
* [Quick intro](#quick-intro)
2120
* [Note about lazy-loading and existence-checking](#note-about-lazy-loading-and-existence-checking)
22-
* [Bibs: Bibliographic records, Holdings, Items](#bibs-bibliographic-records-holdings-items)
21+
* [Bibs: Bibliographic records, Holdings, Representations, Portfolios](#bibs-bibliographic-records-holdings-representations-portfolios)
2322
* [Getting a single record](#getting-a-single-record)
2423
* [The MARC21 record](#the-marc21-record)
2524
* [Searching for records](#searching-for-records)
2625
* [Getting linked record from network zone](#getting-linked-record-from-network-zone)
2726
* [Editing records](#editing-records)
2827
* [Holdings and items](#holdings-and-items)
29-
* [Items](#items)
28+
* [Item by barcode](#items-by-barcode)
29+
* [Electronic portfolios and collections](#electronic-portfolios-and-collections)
30+
* [Digital representation and files](#digital-representation-and-files)
3031
* [Users, loans, fees and requests](#users-loans-fees-and-requests)
3132
* [Search](#search)
3233
* [Loans](#loans)
@@ -35,6 +36,9 @@ If the package doesn't fit your needs, you might take a look at the alternative
3536
* [Analytics reports](#analytics-reports)
3637
* [Column names](#column-names)
3738
* [Filters](#filters)
39+
* [Task lists](#task-lists)
40+
* [Lending requests](#lending-requests)
41+
* [Requested resources (pick from shelf)](#requested-resources-pick-from-shelf)
3842
* [Laravel 5 integration](#laravel-5-integration)
3943
* [Future plans](#future-plans)
4044

@@ -155,7 +159,7 @@ if (!$bib->exists()) {
155159
}
156160
```
157161

158-
## Bibs: Bibliographic records, Holdings, Items
162+
## Bibs: Bibliographic records, Holdings, Representations, Portfolios
159163

160164
### Getting a single record
161165

@@ -279,14 +283,45 @@ foreach ($bib->holdings as $holding) {
279283
In this case, the client makes one request to fetch the list of holdings, and
280284
then one request per holding to fetch items.
281285

282-
## Items
286+
### Item by barcode
283287

284288
There is a special entrypoint to retrieve an item by barcode:
285289

286290
```php
287291
$item = $alma->items->fromBarcode('92nf02526');
288292
```
289293

294+
### Electronic portfolios and collections
295+
296+
Electronic portfolios and collections are available on the `Bib` object in the same way as holdings.
297+
298+
```php
299+
$bib = $alma->bibs->get('990310361044702204');
300+
foreach ($bib->portfolios as $portfolio) {
301+
echo "{$portfolio->portfolio_id} {$portfolio->electronic_collection->service->link} ";
302+
echo "{$portfolio->electronic_collection->public_name}\n";
303+
}
304+
```
305+
306+
```php
307+
$bib = $alma->bibs->get('990310361044702204');
308+
foreach ($bib->electronic_collections as $collection) {
309+
echo "{$collection->public_name}";
310+
}
311+
```
312+
313+
### Digital representation and files
314+
315+
```php
316+
$bib = $alma->bibs->get('990310361044702204');
317+
foreach ($bib->representations as $rep) {
318+
echo "{$rep->representation_id} {$rep->label}\n";
319+
foreach ($rep->files as $rep_file) {
320+
echo "{$rep_file->label} {$rep_file->thumbnail_url}\n";
321+
}
322+
}
323+
```
324+
290325
## Users, loans, fees and requests
291326

292327
**Note**: Editing is not yet implemented.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Bibs;
4+
5+
use Scriptotek\Alma\Bibs\Bib;
6+
use Scriptotek\Alma\Bibs\ElectronicCollections;
7+
use Scriptotek\Alma\Client as AlmaClient;
8+
use PhpSpec\ObjectBehavior;
9+
use Prophecy\Argument;
10+
use Scriptotek\Alma\Electronic\Collection;
11+
use spec\Scriptotek\Alma\SpecHelper;
12+
13+
class ElectronicCollectionsSpec extends ObjectBehavior
14+
{
15+
public function let(AlmaClient $client, Bib $bib)
16+
{
17+
$bib->mms_id = 'abc';
18+
$this->beConstructedWith($client, $bib);
19+
}
20+
21+
function it_is_initializable()
22+
{
23+
$this->shouldHaveType(ElectronicCollections::class);
24+
}
25+
26+
protected function expectRequest($client)
27+
{
28+
$client->getJSON('/bibs/abc/e-collections')
29+
->shouldBeCalled()
30+
->willReturn(SpecHelper::getDummyData('e-collections_response.json'));
31+
}
32+
33+
public function it_is_countable(AlmaClient $client)
34+
{
35+
$this->expectRequest($client);
36+
37+
$this->shouldHaveCount(1);
38+
}
39+
40+
public function it_provides_basic_data_without_loading_the_full_record(AlmaClient $client)
41+
{
42+
$this->expectRequest($client);
43+
44+
$c = $this->all()[0];
45+
46+
$c->shouldHaveType(Collection::class);
47+
$c->public_name->shouldBe('SpringerLink Books Complete');
48+
}
49+
}

spec/Bibs/FileSpec.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Bibs;
4+
5+
use Scriptotek\Alma\Bibs\Bib;
6+
use Scriptotek\Alma\Bibs\Representation;
7+
use Scriptotek\Alma\Bibs\File;
8+
use Scriptotek\Alma\Client as AlmaClient;
9+
use PhpSpec\ObjectBehavior;
10+
use Prophecy\Argument;
11+
12+
class FileSpec extends ObjectBehavior
13+
{
14+
public function let(AlmaClient $client, Bib $bib, Representation $representation)
15+
{
16+
$bib->mms_id = '990006312214702204';
17+
$representation->representation_id = '22163771200002204';
18+
$file_id = '23163771190002204';
19+
20+
$this->beConstructedWith($client, $bib, $representation, $file_id);
21+
}
22+
23+
public function it_is_initializable()
24+
{
25+
$this->shouldHaveType(File::class);
26+
}
27+
28+
}

spec/Bibs/FilesSpec.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Bibs;
4+
5+
use Scriptotek\Alma\Bibs\Bib;
6+
use Scriptotek\Alma\Bibs\Representation;
7+
use Scriptotek\Alma\Bibs\Files;
8+
use Scriptotek\Alma\Client as AlmaClient;
9+
use PhpSpec\ObjectBehavior;
10+
use Prophecy\Argument;
11+
use spec\Scriptotek\Alma\SpecHelper;
12+
13+
class FilesSpec extends ObjectBehavior
14+
{
15+
public function let(AlmaClient $client, Bib $bib, Representation $representation)
16+
{
17+
$bib->mms_id = 'abc';
18+
$representation->representation_id = '123';
19+
$this->beConstructedWith($client, $bib, $representation);
20+
}
21+
22+
public function it_is_initializable()
23+
{
24+
$this->shouldHaveType(Files::class);
25+
}
26+
27+
protected function expectRequest($client)
28+
{
29+
$client->getJSON('/bibs/abc/representations/123/files')
30+
->shouldBeCalled()
31+
->willReturn(SpecHelper::getDummyData('files_response.json'));
32+
}
33+
34+
public function it_is_countable(AlmaClient $client)
35+
{
36+
$this->expectRequest($client);
37+
38+
$this->shouldHaveCount(96);
39+
}
40+
}

spec/Bibs/HoldingsSpec.php

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,24 @@
1111

1212
class HoldingsSpec extends ObjectBehavior
1313
{
14-
public $sample = '{
15-
"holding": [
16-
{
17-
"library": {
18-
"value": "65144020000121",
19-
"desc": "BURNS"
20-
},
21-
"location": {
22-
"value": "UNASSIGNED",
23-
"desc": "UNASSIGNED location"
24-
},
25-
"link": "/almaws/v1/bibs/99100383900121/holdings/2221159990000121",
26-
"holding_id": "2221159990000121"
27-
},
28-
{
29-
"library": {
30-
"value": "5867020000121",
31-
"desc": "Main Library"
32-
},
33-
"location": {
34-
"value": "MICR",
35-
"desc": "Microforms"
36-
},
37-
"link": "/almaws/v1/bibs/99100383900121/holdings/2221410000000121",
38-
"holding_id": "2221410000000121"
39-
}
40-
],
41-
"bib_data": {
42-
"title": "Data base",
43-
"issn": "0095-0033",
44-
"publisher": "Association for Computing Machinery",
45-
"link": "/almaws/v1/bibs/99100383900121",
46-
"mms_id": 99100383900121,
47-
"place_of_publication": "New York :",
48-
"network_number": [
49-
"(CONSER) 2011250895",
50-
"(CKB)954926959913",
51-
"(OCoLC)604911177"
52-
]
53-
},
54-
"total_record_count": 2
55-
}';
56-
5714
public function let(AlmaClient $client, Bib $bib)
5815
{
5916
$bib->mms_id = 'abc';
6017
$this->beConstructedWith($client, $bib);
6118
}
6219

20+
public function it_is_initializable()
21+
{
22+
$this->shouldHaveType(Holdings::class);
23+
}
24+
25+
protected function expectRequest($client)
26+
{
27+
$client->getJSON('/bibs/abc/holdings')
28+
->shouldBeCalled()
29+
->willReturn(SpecHelper::getDummyData('holdings_response.json'));
30+
}
31+
6332
public function it_provides_a_lazy_interface_to_holding_objects(AlmaClient $client, Bib $bib)
6433
{
6534
SpecHelper::expectNoRequests($client);
@@ -86,18 +55,14 @@ public function it_provides_a_lazy_array_interface_to_holding_objects(AlmaClient
8655

8756
public function it_is_countable(AlmaClient $client)
8857
{
89-
$client->getJSON('/bibs/abc/holdings')
90-
->shouldBeCalled()
91-
->willReturn(json_decode($this->sample));
58+
$this->expectRequest($client);
9259

9360
$this->shouldHaveCount(2);
9461
}
9562

9663
public function it_provides_an_iterator_interface_to_holding_objects(AlmaClient $client)
9764
{
98-
$client->getJSON('/bibs/abc/holdings')
99-
->shouldBeCalled()
100-
->willReturn(json_decode($this->sample));
65+
$this->expectRequest($client);
10166

10267
$this->shouldImplement('Iterator');
10368

@@ -106,9 +71,7 @@ public function it_provides_an_iterator_interface_to_holding_objects(AlmaClient
10671

10772
public function it_provides_basic_data_without_loading_the_full_record(AlmaClient $client)
10873
{
109-
$client->getJSON('/bibs/abc/holdings')
110-
->shouldBeCalledTimes(1)
111-
->willReturn(json_decode($this->sample));
74+
$this->expectRequest($client);
11275

11376
$this->shouldHaveCount(2);
11477
$this->all()[0]->shouldHaveType(Holding::class);

spec/Bibs/PortfolioSpec.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Bibs;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use Scriptotek\Alma\Bibs\Bib;
8+
use Scriptotek\Alma\Bibs\Portfolio;
9+
use Scriptotek\Alma\Bibs\Portfolios;
10+
use Scriptotek\Alma\Client as AlmaClient;
11+
use Scriptotek\Alma\Electronic\Collection;
12+
use spec\Scriptotek\Alma\SpecHelper;
13+
14+
class PortfolioSpec extends ObjectBehavior
15+
{
16+
public function let(AlmaClient $client, Bib $bib)
17+
{
18+
$bib->mms_id = 'abc';
19+
$portfolio_id = '123';
20+
$this->beConstructedWith($client, $bib, $portfolio_id);
21+
}
22+
23+
function it_is_initializable()
24+
{
25+
$this->shouldHaveType(Portfolio::class);
26+
}
27+
28+
protected function expectRequest($client)
29+
{
30+
$client->getJSON('/bibs/abc/portfolios/123')
31+
->shouldBeCalled()
32+
->willReturn(SpecHelper::getDummyData('portfolio_response.json'));
33+
}
34+
35+
public function it_fetches_data_when_needed(AlmaClient $client)
36+
{
37+
$this->expectRequest($client);
38+
39+
$this->availability->desc->shouldBe('Available');
40+
}
41+
42+
public function it_belongs_to_collection(AlmaClient $client)
43+
{
44+
$this->expectRequest($client);
45+
46+
$this->getElectronicCollection()->shouldHaveType(Collection::class);
47+
$this->electronic_collection->shouldHaveType(Collection::class);
48+
}}

0 commit comments

Comments
 (0)