1 | <?php |
||
2 | |||
3 | namespace codingFive0\octadesk; |
||
4 | |||
5 | class Person extends Octadesk |
||
6 | { |
||
7 | |||
8 | public function __construct($accToken) |
||
9 | { |
||
10 | $this->setAccesToken($accToken); |
||
11 | parent::__construct(); |
||
12 | } |
||
13 | |||
14 | public function findById($id) |
||
15 | { |
||
16 | $this->request( |
||
17 | "GET", |
||
18 | "persons/{$id}" |
||
19 | ); |
||
20 | |||
21 | return $this; |
||
22 | } |
||
23 | |||
24 | public function findByEmail($email) |
||
25 | { |
||
26 | if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
||
27 | $this->error = "Informe um e-mail em formato vĂ¡lido para prosseguir."; |
||
28 | return null; |
||
29 | } |
||
30 | |||
31 | $this->request( |
||
32 | "GET", |
||
33 | "persons", |
||
34 | [ |
||
35 | "email" => $email |
||
36 | ] |
||
37 | ); |
||
38 | |||
39 | return $this; |
||
40 | } |
||
41 | |||
42 | public function findRequesters($keywords = null, $page = null, $detailed = false) |
||
43 | { |
||
44 | if ($keywords) { |
||
45 | $params["keyword"] = $keywords; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
46 | } |
||
47 | |||
48 | if ($page) { |
||
49 | $params["page"] = $page; |
||
50 | } |
||
51 | |||
52 | if ($detailed) { |
||
53 | $params["detailed"] = $detailed; |
||
54 | } |
||
55 | |||
56 | $this->request( |
||
57 | "GET", |
||
58 | "persons/requesters", |
||
59 | $params |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
60 | ); |
||
61 | |||
62 | return $this; |
||
63 | } |
||
64 | |||
65 | public function findAgents($keywords = null, $page = null, $detailed = false) |
||
66 | { |
||
67 | if ($keywords) { |
||
68 | $params["keyword"] = $keywords; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
69 | } |
||
70 | |||
71 | if ($page) { |
||
72 | $params["page"] = $page; |
||
73 | } |
||
74 | |||
75 | if ($detailed) { |
||
76 | $params["detailed"] = $detailed; |
||
77 | } |
||
78 | |||
79 | $this->request( |
||
80 | "GET", |
||
81 | "persons/agents", |
||
82 | $params |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
83 | ); |
||
84 | |||
85 | return $this; |
||
86 | } |
||
87 | |||
88 | public function createClient($name, $email, $clientId, $thumbUrl = null, $organizationName = null, $organizationDesc = null, $organizationDomain = null) |
||
89 | { |
||
90 | $fields = [ |
||
91 | "email" => $email, |
||
92 | "name" => $name, |
||
93 | "thumbUrl" => $thumbUrl, |
||
94 | "customerCode" => $clientId, |
||
95 | "isLocked" => true, |
||
96 | "type" => 2, |
||
97 | "participantPermission" => 0, |
||
98 | "roleType" => 5, |
||
99 | "permissionType" => 0 |
||
100 | ]; |
||
101 | |||
102 | if (!empty($organizationName) || !empty($organizationDesc) || !empty($organizationDomain)) { |
||
103 | $fields = array_merge($fields, [ |
||
104 | "default" => true, |
||
105 | "name" => $organizationName, |
||
106 | "description" => $organizationDesc, |
||
107 | "domain" => $organizationDomain |
||
108 | ]); |
||
109 | } |
||
110 | |||
111 | $this->request( |
||
112 | "POST", |
||
113 | "persons", |
||
114 | $fields |
||
115 | ); |
||
116 | |||
117 | return $this; |
||
118 | } |
||
119 | } |