@@ 10-66 (lines=57) @@ | ||
7 | use Scriptotek\Alma\CountableGhostModelList; |
|
8 | use Scriptotek\Alma\IterableResource; |
|
9 | ||
10 | class Holdings extends CountableGhostModelList implements \Countable, \Iterator, \ArrayAccess |
|
11 | { |
|
12 | use ArrayAccessResource; |
|
13 | use IterableResource; |
|
14 | ||
15 | /* @var Bib */ |
|
16 | public $bib; |
|
17 | ||
18 | public function __construct(Client $client, Bib $bib) |
|
19 | { |
|
20 | parent::__construct($client); |
|
21 | $this->bib = $bib; |
|
22 | } |
|
23 | ||
24 | /** |
|
25 | * Get resource. |
|
26 | * |
|
27 | * @param string $holding_id |
|
28 | * @return Holding |
|
29 | */ |
|
30 | public function get($holding_id) |
|
31 | { |
|
32 | return Holding::make($this->client, $this->bib, $holding_id); |
|
33 | } |
|
34 | ||
35 | public function setData(\stdClass $data) |
|
36 | { |
|
37 | $this->resources = array_map( |
|
38 | function (\stdClass $holding) { |
|
39 | return Holding::make($this->client, $this->bib, $holding->holding_id) |
|
40 | ->init($holding); |
|
41 | }, |
|
42 | $data->holding |
|
43 | ); |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * Check if we have the full representation of our data object. |
|
48 | * |
|
49 | * @param \stdClass $data |
|
50 | * @return boolean |
|
51 | */ |
|
52 | protected function isInitialized($data) |
|
53 | { |
|
54 | return $data->total_record_count; |
|
55 | } |
|
56 | ||
57 | /** |
|
58 | * Generate the base URL for this resource. |
|
59 | * |
|
60 | * @return string |
|
61 | */ |
|
62 | protected function urlBase() |
|
63 | { |
|
64 | return "/bibs/{$this->bib->mms_id}/holdings"; |
|
65 | } |
|
66 | } |
|
67 |
@@ 10-72 (lines=63) @@ | ||
7 | use Scriptotek\Alma\CountableGhostModelList; |
|
8 | use Scriptotek\Alma\IterableResource; |
|
9 | ||
10 | class Locations extends CountableGhostModelList implements \ArrayAccess, \Countable, \Iterator |
|
11 | { |
|
12 | use ArrayAccessResource; |
|
13 | use IterableResource; |
|
14 | ||
15 | /** @var Library */ |
|
16 | protected $library; |
|
17 | ||
18 | /** |
|
19 | * Locations constructor. |
|
20 | * |
|
21 | * @param Client $client |
|
22 | * @param Library $library |
|
23 | */ |
|
24 | public function __construct(Client $client, Library $library) |
|
25 | { |
|
26 | parent::__construct($client); |
|
27 | $this->library = $library; |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * Get resource. |
|
32 | * |
|
33 | * @param string $code |
|
34 | * @return Location |
|
35 | */ |
|
36 | public function get($code) |
|
37 | { |
|
38 | return Location::make($this->client, $this->library, $code); |
|
39 | } |
|
40 | ||
41 | protected function setData(\stdClass $data) |
|
42 | { |
|
43 | $this->resources = array_map( |
|
44 | function (\stdClass $location) { |
|
45 | return Location::make($this->client, $this->library, $location->code) |
|
46 | ->init($location); |
|
47 | }, |
|
48 | $data->location |
|
49 | ); |
|
50 | } |
|
51 | ||
52 | /** |
|
53 | * Check if we have the full representation of our data object. |
|
54 | * |
|
55 | * @param \stdClass $data |
|
56 | * @return boolean |
|
57 | */ |
|
58 | protected function isInitialized($data) |
|
59 | { |
|
60 | return isset($data->location); |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * Generate the base URL for this resource. |
|
65 | * |
|
66 | * @return string |
|
67 | */ |
|
68 | protected function urlBase() |
|
69 | { |
|
70 | return "/conf/libraries/{$this->library->code}/locations"; |
|
71 | } |
|
72 | } |
|
73 |