|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vinicinbgs\Autentique; |
|
4
|
|
|
|
|
5
|
|
|
use vinicinbgs\Autentique\Utils\Query; |
|
6
|
|
|
|
|
7
|
|
|
class Documents extends BaseResource |
|
8
|
|
|
{ |
|
9
|
|
|
private $query; |
|
10
|
|
|
private $token; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Documents constructor. |
|
14
|
|
|
* |
|
15
|
|
|
* @param $token |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct(string $token = null) |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct(); |
|
20
|
|
|
|
|
21
|
|
|
$this->query = new Query($this->resourcesEnum::DOCUMENTS); |
|
22
|
|
|
$this->token = $token ?? $_ENV["AUTENTIQUE_TOKEN"]; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* List all documents |
|
27
|
|
|
* |
|
28
|
|
|
* @param int $page |
|
29
|
|
|
* @return bool|array |
|
30
|
|
|
*/ |
|
31
|
|
|
public function listAll(int $page = 1) |
|
32
|
|
|
{ |
|
33
|
|
|
$graphQuery = $this->query->query(__FUNCTION__); |
|
34
|
|
|
|
|
35
|
|
|
$graphQuery = $this->query->setVariables("page", $page, $graphQuery); |
|
36
|
|
|
|
|
37
|
|
|
return $this->api->request($this->token, $graphQuery, "json"); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* List document by id |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $documentId |
|
44
|
|
|
* |
|
45
|
|
|
* @return bool|array |
|
46
|
|
|
*/ |
|
47
|
|
|
public function listById(string $documentId) |
|
48
|
|
|
{ |
|
49
|
|
|
$graphQuery = $this->query->query(__FUNCTION__); |
|
50
|
|
|
$graphQuery = $this->query->setVariables( |
|
51
|
|
|
"documentId", |
|
52
|
|
|
$documentId, |
|
53
|
|
|
$graphQuery |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
return $this->api->request($this->token, $graphQuery, "json"); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Create Document |
|
61
|
|
|
* |
|
62
|
|
|
* @param array $attributes |
|
63
|
|
|
* @return bool|array |
|
64
|
|
|
*/ |
|
65
|
|
|
public function create(array $attributes) |
|
66
|
|
|
{ |
|
67
|
|
|
$variables = [ |
|
68
|
|
|
"document" => $attributes["document"], |
|
69
|
|
|
"signers" => $attributes["signers"], |
|
70
|
|
|
"file" => null, |
|
71
|
|
|
]; |
|
72
|
|
|
|
|
73
|
|
|
$graphMutation = $this->query->query(__FUNCTION__); |
|
74
|
|
|
$graphMutation = $this->query->setVariables( |
|
75
|
|
|
["variables", "sandbox"], |
|
76
|
|
|
[json_encode($variables), $this->sandbox], |
|
77
|
|
|
$graphMutation |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
return $this->api->request( |
|
|
|
|
|
|
81
|
|
|
$this->token, |
|
82
|
|
|
$graphMutation, |
|
83
|
|
|
"form", |
|
84
|
|
|
$attributes["file"] |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Sign document by id |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $documentId |
|
92
|
|
|
* |
|
93
|
|
|
* @return bool|array |
|
94
|
|
|
*/ |
|
95
|
|
|
public function signById(string $documentId) |
|
96
|
|
|
{ |
|
97
|
|
|
$graphQuery = $this->query->query(__FUNCTION__); |
|
98
|
|
|
$graphQuery = $this->query->setVariables( |
|
99
|
|
|
"documentId", |
|
100
|
|
|
$documentId, |
|
101
|
|
|
$graphQuery |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
return $this->api->request($this->token, $graphQuery, "json"); |
|
|
|
|
|
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Delete document by id |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $documentId |
|
111
|
|
|
* |
|
112
|
|
|
* @return bool|array |
|
113
|
|
|
*/ |
|
114
|
|
|
public function deleteById(string $documentId) |
|
115
|
|
|
{ |
|
116
|
|
|
$graphQuery = $this->query->query(__FUNCTION__); |
|
117
|
|
|
$graphQuery = $this->query->setVariables( |
|
118
|
|
|
"documentId", |
|
119
|
|
|
$documentId, |
|
120
|
|
|
$graphQuery |
|
121
|
|
|
); |
|
122
|
|
|
|
|
123
|
|
|
return $this->api->request($this->token, $graphQuery, "json"); |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Move document to folder |
|
128
|
|
|
* |
|
129
|
|
|
* @param string $documentId |
|
130
|
|
|
* @param string $folderId |
|
131
|
|
|
* |
|
132
|
|
|
* @return bool|array |
|
133
|
|
|
*/ |
|
134
|
|
|
public function moveToFolder(string $documentId, string $folderId) |
|
135
|
|
|
{ |
|
136
|
|
|
$graphQuery = $this->query->query(__FUNCTION__); |
|
137
|
|
|
|
|
138
|
|
|
$graphQuery = $this->query->setVariables( |
|
139
|
|
|
["documentId", "folderId"], |
|
140
|
|
|
[$documentId, $folderId], |
|
141
|
|
|
$graphQuery |
|
142
|
|
|
); |
|
143
|
|
|
|
|
144
|
|
|
return $this->api->request($this->token, $graphQuery, "json"); |
|
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Move document from folder to folder |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $documentId |
|
151
|
|
|
* @param string $folderId |
|
152
|
|
|
* @param string $currentFolderId |
|
153
|
|
|
* |
|
154
|
|
|
* @return bool|array |
|
155
|
|
|
*/ |
|
156
|
|
|
public function moveToFolderByFolder(string $documentId, string $folderId, string $currentFolderId) |
|
157
|
|
|
{ |
|
158
|
|
|
$graphQuery = $this->query->query(__FUNCTION__); |
|
159
|
|
|
|
|
160
|
|
|
$graphQuery = $this->query->setVariables( |
|
161
|
|
|
["documentId", "folderId", "currentFolderId"], |
|
162
|
|
|
[$documentId, $folderId, $currentFolderId], |
|
163
|
|
|
$graphQuery |
|
164
|
|
|
); |
|
165
|
|
|
|
|
166
|
|
|
return $this->api->request($this->token, $graphQuery, "json"); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|