1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
5
|
|
|
|
6
|
|
|
class Project extends Base |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Private constructor so only the client can create this |
10
|
|
|
* @param Client $client |
11
|
|
|
*/ |
12
|
20 |
|
public function __construct(Client $client) |
13
|
|
|
{ |
14
|
20 |
|
parent::__construct($client); |
15
|
20 |
|
$this->SetUrl("/project"); |
16
|
20 |
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get one or multiple projects |
20
|
|
|
* @param string project id, leave null for list of boxes |
21
|
|
|
* @param object Containing query arguments |
22
|
|
|
* @return object Result of the request |
23
|
|
|
*/ |
24
|
|
|
public function Get($projectId = null, $args = array("limit" => 50)) |
25
|
|
|
{ |
26
|
|
|
if (is_null($projectId)) { |
27
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
28
|
|
|
} |
29
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$projectId, $args); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create new project |
34
|
|
|
* @param object Containing all the information of a project |
35
|
|
|
* @return object Result of the request |
36
|
|
|
*/ |
37
|
|
|
public function Create($project) |
38
|
|
|
{ |
39
|
|
|
return $this->GetClient()->Post($this->GetUrl(), $project); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Update a project |
44
|
|
|
* @param id of the project |
45
|
|
|
* @param object Containing all the information of a project |
46
|
|
|
* @throws \Exception when projectid is missing |
47
|
|
|
* @return object Result of the request |
48
|
|
|
*/ |
49
|
|
|
public function Update($project) |
50
|
|
|
{ |
51
|
|
|
if (!isset($project['projectid'])) { |
52
|
|
|
throw new \Exception("project must contain a projectid"); |
53
|
|
|
} |
54
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/".$project['projectid'], $project); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Delete a project object by project id |
59
|
|
|
* @param string Id of the project |
60
|
|
|
* @return object Result of the request |
61
|
|
|
*/ |
62
|
|
|
public function Delete($projectId) |
63
|
|
|
{ |
64
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$projectId); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Retrieve fields of a project object by project id |
69
|
|
|
* @param string Id of the project |
70
|
|
|
* @return object Result of the request |
71
|
|
|
*/ |
72
|
|
|
public function Fields($projectId) |
73
|
|
|
{ |
74
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$projectId."/fields"); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Retrieve logs of a project object by project id |
79
|
|
|
* @param string Id of the project |
80
|
|
|
* @return object Result of the request |
81
|
|
|
*/ |
82
|
|
|
public function Logs($projectId) |
83
|
|
|
{ |
84
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$projectId."/logs"); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|