15 |
15 |
16 /** |
16 /** |
17 * Model class for Document. Inherit from EasyRd\Resource |
17 * Model class for Document. Inherit from EasyRd\Resource |
18 * SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}} |
18 * SELECT DISTINCT ?g WHERE {GRAPH ?g {?s ?p ?o}} |
19 */ |
19 */ |
20 class Document extends DocumentResult { |
20 class Document extends DocumentBase { |
21 |
21 |
22 public function __construct($uri, $graph = null) { |
22 public function __construct($uri, $graph = null) { |
23 // print($graph->dump('html')); |
23 // print($graph->dump('html')); |
24 parent::__construct($uri, $graph); |
24 parent::__construct($uri, $graph); |
25 } |
25 } |
40 $this->transcript = false; |
40 $this->transcript = false; |
41 $this->geoInfo = false; |
41 $this->geoInfo = false; |
42 } |
42 } |
43 |
43 |
44 |
44 |
45 public function getPublishers() { |
|
46 if(is_null($this->publishers)) { |
|
47 try { |
|
48 $this->publishers = $this->getProvidedCHO()->all('dc11:publisher'); |
|
49 } catch(\Exception $e) { |
|
50 $this->publishers = []; |
|
51 } |
|
52 } |
|
53 return $this->publishers; |
|
54 } |
|
55 |
|
56 private function parseWebResources() { |
45 private function parseWebResources() { |
57 |
46 |
58 $this->mediaArray = []; |
47 $this->mediaArray = []; |
59 $this->transcript = null; |
48 $this->transcript = null; |
60 |
49 |
61 $master = $this->get('<http://www.europeana.eu/schemas/edm/isShownBy>'); |
50 $master = $this->get('<http://www.europeana.eu/schemas/edm/isShownBy>'); |
62 $masterUrl = is_null($master)?null:$master->getUri(); |
51 $masterUrl = is_null($master)?null:$master->getUri(); |
63 |
52 |
64 foreach($this->graph->allOfType("<http://www.europeana.eu/schemas/edm/WebResource>") as $webResource) { |
53 foreach($this->graph->allOfType("<http://www.europeana.eu/schemas/edm/WebResource>") as $webResource) { |
65 $formatLit = $webResource->getLiteral("dc11:format"); |
54 $formatLit = $webResource->getLiteral("dc11:format"); |
66 $format = is_null($formatLit)?null:$formatLit->getValue(); |
55 $format = is_null($formatLit)?null:$formatLit->getValue(); |
67 if(is_null($format)) { |
56 if(is_null($format)) { |
68 throw new ModelsException("parseWebResources: No dc:11 format on web resource"); |
57 throw new ModelsException("parseWebResources: No dc:11 format on web resource"); |
69 } |
58 } |
70 |
59 |
71 if(0 === strpos($format, 'audio/') || |
60 if(0 === strpos($format, 'audio/') || |
72 0 === strpos($format, 'video/') || |
61 0 === strpos($format, 'video/') || |
73 0 === strpos($format, 'Sampling:') ) { |
62 0 === strpos($format, 'Sampling:') ) { |
74 array_push( |
63 array_push( |
75 $this->mediaArray, |
64 $this->mediaArray, |
76 new MediaResource( |
65 new MediaResource( |
77 $webResource->getUri(), |
66 $webResource->getUri(), |
78 $this->graph, |
67 $this->graph, |
79 (($webResource->getUri() === $masterUrl)?true:false)) |
68 (($webResource->getUri() === $masterUrl)?true:false)) |
80 ); |
69 ); |
81 } else if( |
70 } else if( |
82 0 === strpos($format, 'application/xml') || |
71 0 === strpos($format, 'application/xml') || |
83 0 === strpos($format, 'application/pdf') ) { |
72 0 === strpos($format, 'application/pdf') ) { |
84 $this->transcript = new TranscriptResource($webResource->getUri(), $this->graph); |
73 $this->transcript = new TranscriptResource($webResource->getUri(), $this->graph); |
85 } |
74 } |
86 else { |
75 else { |
87 throw new ModelsException("parseWebResources: unknown format"); |
76 throw new ModelsException("parseWebResources: unknown format"); |
88 } |
77 } |
89 } |
78 } |
90 |
79 |
91 } |
80 } |
92 |
81 |
93 public function getMediaArray() { |
82 public function getMediaArray() { |
261 |
250 |
262 $this->subjects = null; |
251 $this->subjects = null; |
263 |
252 |
264 } |
253 } |
265 |
254 |
|
255 public function getPublishers() { |
|
256 if(is_null($this->publishers)) { |
|
257 try { |
|
258 $this->publishers = $this->getProvidedCHO()->all('dc11:publisher'); |
|
259 } catch(\Exception $e) { |
|
260 $this->publishers = []; |
|
261 } |
|
262 } |
|
263 return $this->publishers; |
|
264 } |
|
265 |
|
266 public function getPublishersValues() { |
|
267 $publishers = $this->getPublishers(); |
|
268 return array_map( |
|
269 function($v) { return Utils::processLiteralResourceOrString($v); }, |
|
270 $this->getPublishers() |
|
271 ); |
|
272 } |
|
273 |
|
274 |
|
275 |
266 public function isIsomorphic($doc) { |
276 public function isIsomorphic($doc) { |
267 return Isomorphic::isomorphic($this->graph, $doc->graph); |
277 return Isomorphic::isomorphic($this->graph, $doc->graph); |
268 } |
278 } |
269 |
279 |
270 /* |
280 /* |
294 ); |
304 ); |
295 |
305 |
296 $transcript = is_null($this->getTranscript())?null:$this->getTranscript()->jsonSerialize(); |
306 $transcript = is_null($this->getTranscript())?null:$this->getTranscript()->jsonSerialize(); |
297 $geoInfo = is_null($this->getGeoInfo())?null:$this->getGeoInfo()->jsonSerialize(); |
307 $geoInfo = is_null($this->getGeoInfo())?null:$this->getGeoInfo()->jsonSerialize(); |
298 |
308 |
299 $publishers = array_map( |
309 $publishers = $this->getPublishersValues(); |
300 function($v) { return Utils::processLiteralResourceOrString($v); }, |
|
301 $this->getPublishers() |
|
302 ); |
|
303 |
310 |
304 $contributors = array_map( |
311 $contributors = array_map( |
305 function($c) { unset($c['nameLiteral']); return $c; }, |
312 function($c) { unset($c['nameLiteral']); return $c; }, |
306 $this->getContributors() |
313 $this->getContributors() |
307 ); |
314 ); |