author | Chloe Laisne <chloe.laisne@gmail.com> |
Wed, 24 Aug 2016 17:48:50 +0200 | |
changeset 266 | 0e1880fa7bd3 |
parent 260 | 64caee7ce38d |
child 275 | a4d8618c2f1b |
permissions | -rw-r--r-- |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
namespace CorpusParole\Models; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
|
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
use Config; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
use CorpusParole\Libraries\Utils; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
use CorpusParole\Libraries\CocoonUtils; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
use CorpusParole\Libraries\RdfModel\RdfModelResource; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
use JsonSerializable; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
use Log; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
use EasyRdf\Literal; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
use EasyRdf\Resource; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
use EasyRdf\Graph; |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
|
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
|
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
/** |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
*/ |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
17 |
class DocumentResult extends DocumentBase { |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
|
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
public function __construct($uri, $graph = null) { |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
parent::__construct($uri, $graph); |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
23 |
private $publishers = false; |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
24 |
private $duration = false; |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
25 |
private $durationMs = -1; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
|
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
protected function clearMemoizationCache() { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
28 |
parent::clearMemoizationCache(); |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
29 |
$this->publishers = false; |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
30 |
$this->duration = false; |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
31 |
$this->$durationMs = -1; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
|
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
35 |
public function getPublishers() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
36 |
if($this->publishers === false) { |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
try { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
38 |
$this->publishers = $this->getProvidedCHO()->getLiteral('dc11:publisher'); |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
} catch(\Exception $e) { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
40 |
$this->publishers = null; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
43 |
return $this->publishers; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
46 |
public function getPublishersValue() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
47 |
$publishers = $this->getPublishers(); |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
48 |
return is_null($publishers)?null:$publishers->getValue(); |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
51 |
public function getDuration() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
52 |
if($this->duration === false) { |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
try { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
54 |
$this->duration = $this->getProvidedCHO()->getLiteral('<http://purl.org/dc/terms/extent>'); |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
} catch(\Exception $e) { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
56 |
$this->duration = null; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
59 |
return $this->duration; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
62 |
public function getDurationValue() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
63 |
if($this->durationMs === -1) { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
64 |
$this->durationMs = Utils::iso8601IntervalToMillis($this->getDuration()); |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
66 |
return $this->durationMs; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
69 |
public function jsonSerialize() { |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
71 |
$res = parent::jsonSerialize(); |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
73 |
if($this->graph) { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
74 |
$res = array_merge($res, [ |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
75 |
'publishers' => $this->getPublishersValue(), |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
76 |
'duration' => $this->getDurationValue() |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
77 |
]); |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
79 |
return $res; |
168
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
} |
17f10b56c079
improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
} |