author | ymh <ymh.work@gmail.com> |
Tue, 06 Sep 2016 16:50:41 +0200 | |
changeset 275 | a4d8618c2f1b |
parent 260 | 64caee7ce38d |
child 319 | 78990a8a069b |
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; |
275
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
26 |
private $transcriptUrl = 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
|
27 |
|
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
|
28 |
protected function clearMemoizationCache() { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
29 |
parent::clearMemoizationCache(); |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
30 |
$this->publishers = false; |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
31 |
$this->duration = false; |
275
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
32 |
$this->durationMs = -1; |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
33 |
$this->transcriptUrl = 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
|
34 |
|
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
|
35 |
} |
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
|
36 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
37 |
public function getPublishers() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
38 |
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
|
39 |
try { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
40 |
$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
|
41 |
} catch(\Exception $e) { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
42 |
$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
|
43 |
} |
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 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
45 |
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
|
46 |
} |
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
|
47 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
48 |
public function getPublishersValue() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
49 |
$publishers = $this->getPublishers(); |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
50 |
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
|
51 |
} |
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
|
52 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
53 |
public function getDuration() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
54 |
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
|
55 |
try { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
56 |
$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
|
57 |
} catch(\Exception $e) { |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
58 |
$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
|
59 |
} |
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 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
61 |
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
|
62 |
} |
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
|
63 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
64 |
public function getDurationValue() { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
65 |
if($this->durationMs === -1) { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
66 |
$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
|
67 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
68 |
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
|
69 |
} |
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 |
|
275
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
71 |
public function getTranscriptUrl() { |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
72 |
if($this->transcriptUrl === false) { |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
73 |
try { |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
74 |
$this->transcriptUrl = $this->getProvidedCHO()->getLiteral("<".config('corpusparole.corpus_ontology_url').'transcript'.">"); |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
75 |
} catch(\Exception $e) { |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
76 |
$this->transcriptUrl = null; |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
77 |
} |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
78 |
} |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
79 |
return is_null($this->transcriptUrl)?null:$this->transcriptUrl->getValue(); |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
80 |
} |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
81 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
82 |
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
|
83 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
84 |
$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
|
85 |
|
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
86 |
if($this->graph) { |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
87 |
$res = array_merge($res, [ |
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
88 |
'publishers' => $this->getPublishersValue(), |
275
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
89 |
'duration' => $this->getDurationValue(), |
a4d8618c2f1b
add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents:
260
diff
changeset
|
90 |
'transcript_url' => $this->getTranscriptUrl() |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
91 |
]); |
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
|
92 |
} |
260
64caee7ce38d
Split document model in document and document results
ymh <ymh.work@gmail.com>
parents:
168
diff
changeset
|
93 |
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
|
94 |
} |
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
|
95 |
} |