1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Phraseanet SDK. |
5
|
|
|
* |
6
|
|
|
* (c) Alchemy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PhraseanetSDK\Entity; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use PhraseanetSDK\Annotation\ApiField as ApiField; |
16
|
|
|
use PhraseanetSDK\Annotation\ApiRelation as ApiRelation; |
17
|
|
|
use PhraseanetSDK\EntityManager; |
18
|
|
|
|
19
|
|
|
class Query |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param EntityManager $entityManager |
24
|
|
|
* @param \stdClass $value |
25
|
|
|
* @return Query |
26
|
|
|
*/ |
27
|
3 |
|
public static function fromValue(EntityManager $entityManager, \stdClass $value) |
28
|
|
|
{ |
29
|
3 |
|
return new self($entityManager, $value); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var EntityManager |
34
|
|
|
*/ |
35
|
|
|
protected $entityManager; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \stdClass |
39
|
|
|
*/ |
40
|
|
|
protected $source; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var QueryFacet[]|ArrayCollection |
44
|
|
|
*/ |
45
|
|
|
protected $facets; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var QuerySuggestion[]|ArrayCollection |
49
|
|
|
*/ |
50
|
|
|
protected $suggestions; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var Result|null |
54
|
|
|
*/ |
55
|
|
|
protected $results; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param EntityManager $entityManager |
59
|
|
|
* @param \stdClass $source |
60
|
|
|
*/ |
61
|
3 |
|
public function __construct(EntityManager $entityManager, \stdClass $source) |
62
|
|
|
{ |
63
|
3 |
|
$this->entityManager = $entityManager; |
64
|
3 |
|
$this->source = $source; |
65
|
3 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return \stdClass |
69
|
|
|
*/ |
70
|
|
|
public function getRawData() |
71
|
|
|
{ |
72
|
|
|
return $this->source; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* The offset start |
77
|
|
|
* |
78
|
|
|
* @return integer |
79
|
|
|
*/ |
80
|
1 |
|
public function getOffsetStart() |
81
|
|
|
{ |
82
|
1 |
|
return $this->source->offset_start; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* The number item to retrieve |
87
|
|
|
* |
88
|
|
|
* @return integer |
89
|
|
|
*/ |
90
|
1 |
|
public function getPerPage() |
91
|
|
|
{ |
92
|
1 |
|
return $this->source->per_page; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get the total result |
97
|
|
|
* |
98
|
|
|
* @return integer |
99
|
|
|
*/ |
100
|
1 |
|
public function getTotalResults() |
101
|
|
|
{ |
102
|
1 |
|
return $this->source->total_results; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get errors as string |
107
|
|
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
1 |
|
public function getError() |
111
|
|
|
{ |
112
|
1 |
|
return $this->source->error; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get warnings as string |
117
|
|
|
* |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
1 |
|
public function getWarning() |
121
|
|
|
{ |
122
|
1 |
|
return $this->source->warning; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get the query time |
127
|
|
|
* |
128
|
|
|
* @return float |
129
|
|
|
*/ |
130
|
1 |
|
public function getQueryTime() |
131
|
|
|
{ |
132
|
1 |
|
return $this->source->query_time; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get search indexes |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
1 |
|
public function getSearchIndexes() |
141
|
|
|
{ |
142
|
1 |
|
return $this->source->search_indexes; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Get the query string |
147
|
|
|
* |
148
|
|
|
* @return string |
149
|
|
|
*/ |
150
|
1 |
|
public function getQuery() |
151
|
|
|
{ |
152
|
1 |
|
return $this->source->query; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get query suggestions as a collection of QuerySuggestion |
157
|
|
|
* objects |
158
|
|
|
* |
159
|
|
|
* @return ArrayCollection |
160
|
|
|
*/ |
161
|
1 |
|
public function getSuggestions() |
162
|
|
|
{ |
163
|
1 |
|
if (! isset($this->source->suggestions)) { |
164
|
|
|
$this->suggestions = new ArrayCollection(); |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
return $this->suggestions ?: $this->suggestions = new ArrayCollection(QuerySuggestion::fromList( |
|
|
|
|
168
|
1 |
|
$this->source->suggestions |
169
|
1 |
|
)); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return ArrayCollection|QueryFacet[] |
174
|
|
|
*/ |
175
|
|
|
public function getFacets() |
176
|
|
|
{ |
177
|
|
|
if (! isset($this->source->facets)) { |
178
|
|
|
$this->facets = new ArrayCollection(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $this->facets ?: $this->facets = new ArrayCollection(QueryFacet::fromList($this->source->facets)); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* |
186
|
|
|
* @return Result |
187
|
|
|
*/ |
188
|
3 |
|
public function getResults() |
189
|
|
|
{ |
190
|
3 |
|
return $this->results ?: $this->results = Result::fromValue($this->entityManager, $this->source->results); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Set or override value in protected object 'source' (\stdClass type) |
195
|
|
|
* |
196
|
|
|
* @param $pKey string |
197
|
|
|
* @param $pValue mixed |
198
|
|
|
*/ |
199
|
|
|
public function setSourceEntry($pKey, $pValue) |
200
|
|
|
{ |
201
|
|
|
$this->source->$pKey = $pValue; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|