| @@ 8-59 (lines=52) @@ | ||
| 5 | use Scriptotek\Alma\Client; |
|
| 6 | use Scriptotek\Alma\Model\LazyResource; |
|
| 7 | ||
| 8 | class File extends LazyResource |
|
| 9 | { |
|
| 10 | /** @var Bib */ |
|
| 11 | public $bib; |
|
| 12 | ||
| 13 | /** @var Representation */ |
|
| 14 | public $representation; |
|
| 15 | ||
| 16 | /** @var Requests */ |
|
| 17 | public $requests; |
|
| 18 | ||
| 19 | /** @var string */ |
|
| 20 | public $file_id; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * File constructor. |
|
| 24 | * |
|
| 25 | * @param Client $client |
|
| 26 | * @param Bib $bib |
|
| 27 | * @param Representation $representation |
|
| 28 | * @param $file_id |
|
| 29 | */ |
|
| 30 | public function __construct(Client $client, Bib $bib, Representation $representation, $file_id) |
|
| 31 | { |
|
| 32 | parent::__construct($client); |
|
| 33 | $this->bib = $bib; |
|
| 34 | $this->representation = $representation; |
|
| 35 | $this->file_id = $file_id; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * Generate the base URL for this resource. |
|
| 40 | * |
|
| 41 | * @return string |
|
| 42 | */ |
|
| 43 | protected function urlBase() |
|
| 44 | { |
|
| 45 | return "/bibs/{$this->bib->mms_id}/representations/{$this->representation->representation_id}/files/{$this->file_id}"; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Check if we have the full representation of our data object. |
|
| 50 | * |
|
| 51 | * @param \stdClass $data |
|
| 52 | * |
|
| 53 | * @return bool |
|
| 54 | */ |
|
| 55 | protected function isInitialized($data) |
|
| 56 | { |
|
| 57 | return isset($data->path); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||
| @@ 11-59 (lines=49) @@ | ||
| 8 | /** |
|
| 9 | * A single Representation resource. |
|
| 10 | */ |
|
| 11 | class Representation extends LazyResource |
|
| 12 | { |
|
| 13 | /* @var string */ |
|
| 14 | public $representation_id; |
|
| 15 | ||
| 16 | /* @var Bib */ |
|
| 17 | public $bib; |
|
| 18 | ||
| 19 | /* @var Files */ |
|
| 20 | public $files; |
|
| 21 | ||
| 22 | public function __construct(Client $client, Bib $bib, $representation_id) |
|
| 23 | { |
|
| 24 | parent::__construct($client); |
|
| 25 | $this->bib = $bib; |
|
| 26 | $this->representation_id = $representation_id; |
|
| 27 | $this->files = Files::make($this->client, $bib, $this); |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * Generate the base URL for this resource. |
|
| 32 | * |
|
| 33 | * @return string |
|
| 34 | */ |
|
| 35 | protected function urlBase() |
|
| 36 | { |
|
| 37 | return "/bibs/{$this->bib->mms_id}/representations/{$this->representation_id}"; |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Get the files for this representation. |
|
| 42 | */ |
|
| 43 | public function getFiles() |
|
| 44 | { |
|
| 45 | return $this->files; |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Check if we have the full representation of our data object. |
|
| 50 | * |
|
| 51 | * @param \stdClass $data |
|
| 52 | * |
|
| 53 | * @return bool |
|
| 54 | */ |
|
| 55 | protected function isInitialized($data) |
|
| 56 | { |
|
| 57 | return isset($data->delivery_url); |
|
| 58 | } |
|
| 59 | } |
|
| 60 | ||