1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
5
|
|
|
|
6
|
|
|
class Box extends Base |
7
|
|
|
{ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Private constructor so only the client can create this |
11
|
|
|
* @param Client $client |
12
|
|
|
*/ |
13
|
20 |
|
public function __construct(Client $client) |
14
|
|
|
{ |
15
|
20 |
|
parent::__construct($client); |
16
|
20 |
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/box"); |
17
|
20 |
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Get one or multiple boxes |
22
|
|
|
* @param string box id, leave null for list of boxes |
23
|
|
|
* @param object Containing query arguments |
24
|
|
|
* @return object Result of the request |
25
|
|
|
*/ |
26
|
|
|
public function Get($boxId = null, $args = array("limit" => 50)) |
27
|
|
|
{ |
28
|
|
|
if (is_null($boxId)) { |
29
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
30
|
|
|
} |
31
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$boxId, $args); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Get all box codes |
36
|
|
|
* @param string box id |
37
|
|
|
* @param object Containing query arguments |
38
|
|
|
* @return object Result of the request |
39
|
|
|
*/ |
40
|
|
|
public function GetCode($boxId, $args = array("limit" => 50)) |
41
|
|
|
{ |
42
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$boxId."/code", $args); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get one or multiple versions of a box |
47
|
|
|
* @param string box id |
48
|
|
|
* @param string version id, leave null for list of versions |
49
|
|
|
* @param object Containing query arguments |
50
|
|
|
* @return object Result of the request |
51
|
|
|
*/ |
52
|
|
|
public function GetVersion($boxId, $versionId = null, $args = array("limit" => 50)) |
53
|
|
|
{ |
54
|
|
|
if (is_null($versionId)) { |
55
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$boxId."/version/", $args); |
56
|
|
|
} |
57
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$boxId."/version/".$versionId, $args); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Create new box |
62
|
|
|
* @param object Containing all the information of a box |
63
|
|
|
* @return object Result of the request |
64
|
|
|
*/ |
65
|
|
|
public function Create($box) |
66
|
|
|
{ |
67
|
|
|
return $this->GetClient()->Post($this->GetUrl(), $box); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Create new box |
72
|
|
|
* @param object Containing all the information of a box |
73
|
|
|
* @return object Result of the request |
74
|
|
|
*/ |
75
|
|
|
public function CreateVersion($boxId, $version) |
76
|
|
|
{ |
77
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/".$boxId."/version", $version); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Delete a box version by version id |
82
|
|
|
* @param string Id of the box |
83
|
|
|
* @param string Id of the version to be deleted |
84
|
|
|
* @return object Result of the request |
85
|
|
|
*/ |
86
|
|
|
public function Delete($boxId) |
87
|
|
|
{ |
88
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$boxId); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Delete a box version by version id |
93
|
|
|
* @param string Id of the box |
94
|
|
|
* @param string Id of the version to be deleted |
95
|
|
|
* @return object Result of the request |
96
|
|
|
*/ |
97
|
|
|
public function DeleteVersion($boxId, $versionId) |
98
|
|
|
{ |
99
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$boxId."/version/".$versionId); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Update a box |
104
|
|
|
* @param object Box containing the boxid and fields that need to be updated |
105
|
|
|
* @throws \Exception When boxid is not present |
106
|
|
|
* @return object Result of the request |
107
|
|
|
*/ |
108
|
|
|
public function Update($box) |
109
|
|
|
{ |
110
|
|
|
if (!isset($box['boxid'])) { |
111
|
|
|
throw new \Exception("box must contain a boxid"); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this->GetClient()->Put($this->GetUrl()."/".$box['boxid'], $box); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Update a box |
119
|
|
|
* @param string Id of the box |
120
|
|
|
* @param object Version containing the version and fields that need to be updated |
121
|
|
|
* @throws \Exception When versionid is not present |
122
|
|
|
* @return object Result of the request |
123
|
|
|
*/ |
124
|
|
|
public function UpdateVersion($boxid, $version) |
125
|
|
|
{ |
126
|
|
|
if (!isset($version['versionid'])) { |
127
|
|
|
throw new \Exception("version must contain a versionid"); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $this->GetClient()->Put($this->GetUrl()."/".$boxid."/version/".$version['versionid'], $version); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|