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\Repository; |
13
|
|
|
|
14
|
|
|
use PhraseanetSDK\AbstractRepository; |
15
|
|
|
use PhraseanetSDK\Entity\Query; |
16
|
|
|
use PhraseanetSDK\Exception\RuntimeException; |
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
18
|
|
|
|
19
|
|
|
class Record extends AbstractRepository |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Find the record by its id that belongs to the provided databox |
23
|
|
|
* |
24
|
|
|
* @param integer $databoxId The record databox id |
25
|
|
|
* @param integer $recordId The record id |
26
|
|
|
* @return \PhraseanetSDK\Entity\Record |
27
|
|
|
* @throws RuntimeException |
28
|
|
|
*/ |
29
|
2 |
|
public function findById($databoxId, $recordId, $disableCache = false) |
30
|
|
|
{ |
31
|
2 |
|
$path = sprintf('v1/records/%s/%s/', $databoxId, $recordId); |
32
|
2 |
|
$query = []; |
33
|
|
|
|
34
|
2 |
|
if ($disableCache) { |
35
|
|
|
$query['t'] = time(); |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
$response = $this->query('GET', $path, $query); |
39
|
|
|
|
40
|
2 |
|
if (true !== $response->hasProperty('record')) { |
41
|
1 |
|
throw new RuntimeException('Missing "record" property in response content'); |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
return \PhraseanetSDK\Entity\Record::fromValue($response->getProperty('record')); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Find records |
49
|
|
|
* |
50
|
|
|
* @param integer $offsetStart The offset |
51
|
|
|
* @param integer $perPage The number of item per page |
52
|
|
|
* @return ArrayCollection |
53
|
|
|
* @throws RuntimeException |
54
|
|
|
*/ |
55
|
2 |
|
public function find($offsetStart, $perPage) |
56
|
|
|
{ |
57
|
2 |
|
$response = $this->query('POST', 'v1/records/search/', array(), array( |
58
|
2 |
|
'query' => 'all', |
59
|
2 |
|
'offset_start' => (int) $offsetStart, |
60
|
2 |
|
'per_page' => (int) $perPage, |
61
|
2 |
|
)); |
62
|
|
|
|
63
|
2 |
|
if (true !== $response->hasProperty('results')) { |
64
|
1 |
|
throw new RuntimeException('Missing "results" property in response content'); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
return new ArrayCollection(\PhraseanetSDK\Entity\Record::fromList( |
68
|
1 |
|
$response->getProperty('results') |
|
|
|
|
69
|
1 |
|
)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Search for records |
74
|
|
|
* |
75
|
|
|
* @param array $parameters Query parameters |
76
|
|
|
* @return \PhraseanetSDK\Entity\Query object |
77
|
|
|
* @throws RuntimeException |
78
|
|
|
*/ |
79
|
2 |
|
public function search(array $parameters = array()) |
80
|
|
|
{ |
81
|
2 |
|
$response = $this->query('POST', 'v1/search/', array(), array_merge( |
82
|
2 |
|
array('search_type' => 0), |
83
|
|
|
$parameters |
84
|
2 |
|
)); |
85
|
|
|
|
86
|
2 |
|
if ($response->isEmpty()) { |
87
|
1 |
|
throw new RuntimeException('Response content is empty'); |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
return Query::fromValue($this->em, $response->getResult()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.