|
1
|
|
|
<?php |
|
2
|
|
|
namespace Datatrics\API\Modules; |
|
3
|
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
|
5
|
|
|
|
|
6
|
|
|
class Profile extends Base |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Private constructor so only the client can create this |
|
10
|
|
|
* @param Client $client |
|
11
|
|
|
*/ |
|
12
|
16 |
|
public function __construct(Client $client) |
|
13
|
|
|
{ |
|
14
|
16 |
|
parent::__construct($client); |
|
15
|
16 |
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/profile"); |
|
16
|
16 |
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Get one or multiple profiles |
|
20
|
|
|
* @param string profile id, leave null for list of profiles |
|
21
|
|
|
* @param object Containing query arguments |
|
22
|
|
|
* @return object Result of the request |
|
23
|
|
|
*/ |
|
24
|
|
|
public function Get($profileId = null, $args = array("limit" => 50)) |
|
25
|
|
|
{ |
|
26
|
|
|
if (is_null($profileId)) { |
|
27
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
|
28
|
|
|
} |
|
29
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$profileId, $args); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Create new profile |
|
34
|
|
|
* @param object Containing all the information of a profile |
|
35
|
|
|
* @return object Result of the request |
|
36
|
|
|
*/ |
|
37
|
|
|
public function Create($profile) |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->GetClient()->Post($this->GetUrl(), $profile); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Delete a profile by profileid |
|
44
|
|
|
* @param string Id of the profile to be deleted |
|
45
|
|
|
* @return object Result of the request |
|
46
|
|
|
*/ |
|
47
|
|
|
public function Delete($profileId) |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$profileId); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Update a profile |
|
54
|
|
|
* @param object Profile containing the profileid and fields that need to be updated |
|
55
|
|
|
* @throws \Exception When profileid is not present |
|
56
|
|
|
* @return object Result of the request |
|
57
|
|
|
*/ |
|
58
|
|
|
public function Update($profile) |
|
59
|
|
|
{ |
|
60
|
|
|
if (!isset($profile['profileid'])) { |
|
61
|
|
|
throw new \Exception("profile must contain a profileid"); |
|
62
|
|
|
} |
|
63
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/".$profile['profileid'], $profile); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Updates a maximum of 50 profiles at a time. |
|
68
|
|
|
* @param array Containing profiles with a maximum of 50 |
|
69
|
|
|
* @throws \Exception When more that 50 profiles are provided |
|
70
|
|
|
* @return object Result of the request |
|
71
|
|
|
*/ |
|
72
|
|
|
public function Bulk($profiles) |
|
73
|
|
|
{ |
|
74
|
|
|
if (count($profiles) > 50) { |
|
75
|
|
|
throw new \Exception("Maximum of 50 profiles allowed at a time"); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/bulk", ['items' => $profiles]); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|