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