1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace linkprofit\AmoCRM\services; |
4
|
|
|
|
5
|
|
|
use linkprofit\AmoCRM\entities\Account; |
6
|
|
|
use linkprofit\AmoCRM\entities\TaskType; |
7
|
|
|
use linkprofit\AmoCRM\RequestHandler; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class AccountService |
11
|
|
|
* @package linkprofit\AmoCRM\services |
12
|
|
|
*/ |
13
|
|
|
class AccountService implements AccountServiceInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var \linkprofit\AmoCRM\RequestHandler |
17
|
|
|
*/ |
18
|
|
|
protected $request; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* ServiceInterface constructor. |
22
|
|
|
* |
23
|
|
|
* @param RequestHandler $requestHandler |
24
|
|
|
*/ |
25
|
3 |
|
public function __construct(RequestHandler $requestHandler) |
26
|
|
|
{ |
27
|
3 |
|
$this->request = $requestHandler; |
28
|
3 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return bool|array |
32
|
|
|
*/ |
33
|
1 |
|
public function getAllArray() |
34
|
|
|
{ |
35
|
1 |
|
$this->send(); |
36
|
|
|
|
37
|
1 |
|
return $this->request->getResponse(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array|bool|\linkprofit\AmoCRM\entities\Account |
42
|
|
|
*/ |
43
|
1 |
|
public function getAccount() |
44
|
|
|
{ |
45
|
1 |
|
$this->send([]); |
46
|
|
|
|
47
|
1 |
|
return $this->parseArrayToAccountEntity($this->request->getResponse()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \linkprofit\AmoCRM\entities\CustomField[] |
52
|
|
|
*/ |
53
|
|
|
public function getCustomFields() |
54
|
|
|
{ |
55
|
|
|
// TODO |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return \linkprofit\AmoCRM\entities\User[] |
60
|
|
|
*/ |
61
|
|
|
public function getUsers() |
62
|
|
|
{ |
63
|
|
|
// TODO |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \linkprofit\AmoCRM\entities\Pipeline[] |
68
|
|
|
*/ |
69
|
|
|
public function getPipelines() |
70
|
|
|
{ |
71
|
|
|
// TODO |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return \linkprofit\AmoCRM\entities\Group[] |
76
|
|
|
*/ |
77
|
|
|
public function getGroups() |
78
|
|
|
{ |
79
|
|
|
// TODO |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return \linkprofit\AmoCRM\entities\NoteTypes[] |
84
|
|
|
*/ |
85
|
|
|
public function getNoteTypes() |
86
|
|
|
{ |
87
|
|
|
// TODO |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return \linkprofit\AmoCRM\entities\TaskType[] |
92
|
|
|
*/ |
93
|
1 |
|
public function getTaskTypes() |
94
|
|
|
{ |
95
|
1 |
|
$this->send(['with' => 'task_types']); |
96
|
|
|
|
97
|
1 |
|
return $this->parseArrayToTaskTypeEntities($this->request->getResponse()['_embedded']['task_types']); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
3 |
|
protected function getLink() |
104
|
|
|
{ |
105
|
3 |
|
return 'https://' . $this->request->getSubdomain() . '.amocrm.ru/api/v2/account'; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param array $with |
110
|
|
|
*/ |
111
|
3 |
|
private function send($with = ['with' => 'custom_fields,users,pipelines,groups,note_types,task_types']) |
112
|
|
|
{ |
113
|
3 |
|
$link = $this->getLink().'?'.http_build_query($with); |
114
|
3 |
|
$this->request->performRequest($link, [], 'application/json', 'GET'); |
115
|
3 |
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param $array |
119
|
|
|
* @return Account |
120
|
|
|
*/ |
121
|
1 |
|
private function parseArrayToAccountEntity($array) |
122
|
|
|
{ |
123
|
1 |
|
$account = new Account(); |
124
|
1 |
|
$account->set($array); |
125
|
|
|
|
126
|
1 |
|
return $account; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param array $array |
131
|
|
|
* |
132
|
|
|
* @return array |
133
|
|
|
*/ |
134
|
1 |
|
public function parseArrayToTaskTypeEntities(array $array) |
135
|
|
|
{ |
136
|
1 |
|
$entities = []; |
137
|
|
|
|
138
|
1 |
|
foreach ($array as $item) { |
139
|
1 |
|
$entity = new TaskType(); |
140
|
1 |
|
$entity->set($item); |
141
|
1 |
|
$entities[] = $entity; |
142
|
|
|
} |
143
|
|
|
|
144
|
1 |
|
return $entities; |
145
|
|
|
} |
146
|
|
|
} |