1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Skaut\Skautis; |
5
|
|
|
|
6
|
|
|
use Skaut\Skautis\Wsdl\WebService; |
7
|
|
|
use Skaut\Skautis\Wsdl\WebServiceAlias; |
8
|
|
|
use Skaut\Skautis\Wsdl\WebServiceAliasNotFoundException; |
9
|
|
|
use Skaut\Skautis\Wsdl\WebServiceInterface; |
10
|
|
|
use Skaut\Skautis\Wsdl\WebServiceName; |
11
|
|
|
use Skaut\Skautis\Wsdl\WebServiceNotFoundException; |
12
|
|
|
use Skaut\Skautis\Wsdl\WsdlException; |
13
|
|
|
use Skaut\Skautis\Wsdl\WsdlManager; |
14
|
|
|
use Skaut\Skautis\SkautisQuery; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Třída pro práci se skautISem |
18
|
|
|
* |
19
|
|
|
* Sdružuje všechny komponenty a zprostředkovává jejich komunikaci. |
20
|
|
|
* |
21
|
|
|
* @author Hána František <[email protected]> |
22
|
|
|
* |
23
|
|
|
* @property-read WebServiceInterface $ApplicationManagement |
24
|
|
|
* @property-read WebServiceInterface $ContentManagement |
25
|
|
|
* @property-read WebServiceInterface $Evaluation |
26
|
|
|
* @property-read WebServiceInterface $Events |
27
|
|
|
* @property-read WebServiceInterface $Exports |
28
|
|
|
* @property-read WebServiceInterface $GoogleApps |
29
|
|
|
* @property-read WebServiceInterface $Journal |
30
|
|
|
* @property-read WebServiceInterface $Material |
31
|
|
|
* @property-read WebServiceInterface $Message |
32
|
|
|
* @property-read WebServiceInterface $OrganizationUnit |
33
|
|
|
* @property-read WebServiceInterface $Power |
34
|
|
|
* @property-read WebServiceInterface $Reports |
35
|
|
|
* @property-read WebServiceInterface $Summary |
36
|
|
|
* @property-read WebServiceInterface $Task |
37
|
|
|
* @property-read WebServiceInterface $Telephony |
38
|
|
|
* @property-read WebServiceInterface $UserManagement |
39
|
|
|
* @property-read WebServiceInterface $Vivant |
40
|
|
|
* @property-read WebServiceInterface $Welcome |
41
|
|
|
*/ |
42
|
|
|
class Skautis |
43
|
|
|
{ |
44
|
|
|
|
45
|
|
|
use HelperTrait; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var WsdlManager |
49
|
|
|
*/ |
50
|
|
|
private $wsdlManager; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var User |
54
|
|
|
*/ |
55
|
|
|
private $user; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Zaznamy o provedenych dotazech na Skautis |
59
|
|
|
* Pokud je null, query logging je vypnuto |
60
|
|
|
* |
61
|
|
|
* @var SkautisQuery[]|null |
62
|
|
|
*/ |
63
|
|
|
private $log; |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param WsdlManager $wsdlManager |
68
|
|
|
* @param User $user |
69
|
|
|
*/ |
70
|
4 |
|
public function __construct(WsdlManager $wsdlManager, User $user) |
71
|
|
|
{ |
72
|
4 |
|
$this->wsdlManager = $wsdlManager; |
73
|
4 |
|
$this->user = $user; |
74
|
4 |
|
} |
75
|
|
|
|
76
|
|
|
public function getWsdlManager(): WsdlManager |
77
|
|
|
{ |
78
|
|
|
return $this->wsdlManager; |
79
|
|
|
} |
80
|
|
|
|
81
|
3 |
|
public function getConfig(): Config |
82
|
|
|
{ |
83
|
3 |
|
return $this->wsdlManager->getConfig(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getUser(): User |
87
|
|
|
{ |
88
|
|
|
return $this->user; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Získá objekt webové služby |
93
|
|
|
*/ |
94
|
2 |
|
public function getWebService(string $name): WebServiceInterface |
95
|
|
|
{ |
96
|
2 |
|
$realServiceName = $this->getWebServiceName($name); |
97
|
2 |
|
return $this->wsdlManager->getWebService($realServiceName, $this->user->getLoginId()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Trocha magie pro snadnější přístup k webovým službám. |
102
|
|
|
*/ |
103
|
2 |
|
public function __get(string $name): WebServiceInterface |
104
|
|
|
{ |
105
|
2 |
|
return $this->getWebService($name); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* NEPOUŽÍVAT - vždy vyhodí výjimku |
110
|
|
|
* |
111
|
|
|
* @deprecated |
112
|
|
|
* @param string $name |
113
|
|
|
* @param mixed $value |
114
|
|
|
* |
115
|
|
|
* @return void |
116
|
|
|
* |
117
|
|
|
* @phpstan-return never |
118
|
|
|
*/ |
119
|
1 |
|
public function __set( |
120
|
|
|
$name, |
121
|
|
|
$value |
122
|
|
|
) { |
123
|
1 |
|
throw new DynamicPropertiesDisabledException(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Vrací URL na přihlášení |
129
|
|
|
*/ |
130
|
1 |
|
public function getLoginUrl(string $backlink = ''): string |
131
|
|
|
{ |
132
|
1 |
|
$query = []; |
133
|
1 |
|
$query['appid'] = $this->getConfig()->getAppId(); |
134
|
1 |
|
if (!empty($backlink)) { |
135
|
1 |
|
$query['ReturnUrl'] = $backlink; |
136
|
|
|
} |
137
|
1 |
|
return $this->getConfig()->getBaseUrl() . 'Login/?' . http_build_query($query, '', '&'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Vrací URL na odhlášení |
142
|
|
|
*/ |
143
|
1 |
|
public function getLogoutUrl(): string |
144
|
|
|
{ |
145
|
1 |
|
$query = []; |
146
|
1 |
|
$query['appid'] = $this->getConfig()->getAppId(); |
147
|
1 |
|
$query['token'] = $this->user->getLoginId(); |
148
|
1 |
|
return $this->getConfig()->getBaseUrl() . 'Login/LogOut.aspx?' . http_build_query($query, '', '&'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Vrací URL k registraci |
153
|
|
|
*/ |
154
|
1 |
|
public function getRegisterUrl(string $backlink = ''): string |
155
|
|
|
{ |
156
|
1 |
|
$query = []; |
157
|
1 |
|
$query['appid'] = $this->getConfig()->getAppId(); |
158
|
1 |
|
if (!empty($backlink)) { |
159
|
|
|
$query['ReturnUrl'] = $backlink; |
160
|
|
|
} |
161
|
1 |
|
return $this->getConfig()->getBaseUrl() . 'Login/Registration.aspx?' . http_build_query($query, '', '&'); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Hromadné nastavení po přihlášení |
166
|
|
|
* |
167
|
|
|
* @param array<string, mixed> $data |
168
|
|
|
*/ |
169
|
|
|
public function setLoginData(array $data): void |
170
|
|
|
{ |
171
|
|
|
$data = Helpers::parseLoginData($data); |
172
|
|
|
$this->getUser()->setLoginData($data[User::ID_LOGIN], $data[User::ID_ROLE], $data[User::ID_UNIT], $data[User::LOGOUT_DATE]); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Ověřuje, zda je skautIS odstaven pro údržbu |
177
|
|
|
*/ |
178
|
|
|
public function isMaintenance(): bool |
179
|
|
|
{ |
180
|
|
|
return $this->wsdlManager->isMaintenance(); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Zapne logování všech SOAP callů |
185
|
|
|
*/ |
186
|
|
|
public function enableDebugLog(): void |
187
|
|
|
{ |
188
|
|
|
if ($this->log !== null) { |
189
|
|
|
// Debug log byl již zapnut dříve. |
190
|
|
|
return; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$this->log = []; |
194
|
|
|
$logger = function (SkautisQuery $query): void { |
195
|
|
|
$this->log[] = $query; |
196
|
|
|
}; |
197
|
|
|
$this->wsdlManager->addWebServiceListener(WebService::EVENT_SUCCESS, $logger); |
198
|
|
|
$this->wsdlManager->addWebServiceListener(WebService::EVENT_FAILURE, $logger); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Vrací zalogované SOAP cally |
203
|
|
|
* |
204
|
|
|
* @return SkautisQuery[] |
205
|
|
|
*/ |
206
|
|
|
public function getDebugLog(): array |
207
|
|
|
{ |
208
|
|
|
return $this->log ?? []; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Vrací celé jméno webové služby |
213
|
|
|
* |
214
|
|
|
* @param string $name jméno nebo alias webové služby |
215
|
|
|
* |
216
|
|
|
* @throws WsdlException |
217
|
|
|
*/ |
218
|
2 |
|
protected function getWebServiceName(string $name): string |
219
|
|
|
{ |
220
|
2 |
|
if (WebServiceName::isValidServiceName($name)) { |
221
|
2 |
|
return $name; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
try { |
225
|
1 |
|
return WebServiceAlias::resolveAlias($name); |
226
|
|
|
} |
227
|
|
|
catch (WebServiceAliasNotFoundException $ex) { |
228
|
|
|
throw new WebServiceNotFoundException($name, 0, $ex); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|