|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Skautis; |
|
4
|
|
|
|
|
5
|
|
|
use Skautis\Wsdl\WsdlManager; |
|
6
|
|
|
use Skautis\Wsdl\WebService; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Třída pro práci se skautISem |
|
10
|
|
|
* |
|
11
|
|
|
* Sdružuje všechny komponenty a zprostředkovává jejich komunikaci. |
|
12
|
|
|
* |
|
13
|
|
|
* @author Hána František <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class Skautis |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
use HelperTrait; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var WsdlManager |
|
22
|
|
|
*/ |
|
23
|
|
|
private $wsdlManager; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var User |
|
27
|
|
|
*/ |
|
28
|
|
|
private $user; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var SkautisQuery[] |
|
32
|
|
|
*/ |
|
33
|
|
|
private $log; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param WsdlManager $wsdlManager |
|
38
|
|
|
* @param User $user |
|
39
|
|
|
*/ |
|
40
|
1 |
|
public function __construct(WsdlManager $wsdlManager, User $user) |
|
41
|
|
|
{ |
|
42
|
1 |
|
$this->wsdlManager = $wsdlManager; |
|
43
|
1 |
|
$this->user = $user; |
|
44
|
1 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return WsdlManager |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getWsdlManager() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->wsdlManager; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return Config |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getConfig() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->wsdlManager->getConfig(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return User |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getUser() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->user; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Získá objekt webové služby |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $name |
|
74
|
|
|
* @return WebService|mixed |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getWebService($name) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->wsdlManager->getWebService($name, $this->user->getLoginId()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Trocha magie pro snadnější přístup k webovým službám. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $name |
|
85
|
|
|
* @return WebServiceInterface|mixed |
|
86
|
|
|
*/ |
|
87
|
|
|
public function __get($name) |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->getWebService($name); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Vrací URL na přihlášení |
|
94
|
|
|
* |
|
95
|
|
|
* @param string|null $backlink |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getLoginUrl($backlink = null) |
|
99
|
|
|
{ |
|
100
|
|
|
$query = []; |
|
101
|
|
|
$query['appid'] = $this->getConfig()->getAppId(); |
|
102
|
|
|
if (!empty($backlink)) { |
|
103
|
|
|
$query['ReturnUrl'] = $backlink; |
|
104
|
|
|
} |
|
105
|
|
|
return $this->getConfig()->getBaseUrl() . "Login/?" . http_build_query($query, '', '&'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Vrací URL na odhlášení |
|
110
|
|
|
* |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getLogoutUrl() |
|
114
|
|
|
{ |
|
115
|
|
|
$query = []; |
|
116
|
|
|
$query['appid'] = $this->getConfig()->getAppId(); |
|
117
|
|
|
$query['token'] = $this->user->getLoginId(); |
|
118
|
|
|
return $this->getConfig()->getBaseUrl() . "Login/LogOut.aspx?" . http_build_query($query, '', '&'); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Vrací URL k registraci |
|
123
|
|
|
* |
|
124
|
|
|
* @param string|null $backlink |
|
125
|
|
|
* @return string |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getRegisterUrl($backlink = null) |
|
128
|
|
|
{ |
|
129
|
|
|
$query = []; |
|
130
|
|
|
$query['appid'] = $this->getConfig()->getAppId(); |
|
131
|
|
|
if (!empty($backlink)) { |
|
132
|
|
|
$query['ReturnUrl'] = $backlink; |
|
133
|
|
|
} |
|
134
|
|
|
return $this->getConfig()->getBaseUrl() . "Login/Registration.aspx?" . http_build_query($query, '', '&'); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Hromadné nastavení po přihlášení |
|
139
|
|
|
* |
|
140
|
|
|
* @param array $data |
|
141
|
|
|
*/ |
|
142
|
|
|
public function setLoginData(array $data) |
|
143
|
|
|
{ |
|
144
|
|
|
$data = Helpers::parseLoginData($data); |
|
145
|
|
|
$this->getUser()->setLoginData($data[User::ID_LOGIN], $data[User::ID_ROLE], $data[User::ID_UNIT], $data[User::LOGOUT_DATE]); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Ověřuje, zda je skautIS odstaven pro údržbu |
|
150
|
|
|
* |
|
151
|
|
|
* @return boolean |
|
152
|
|
|
*/ |
|
153
|
|
|
public function isMaintenance() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->wsdlManager->isMaintenance(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Zapne logování všech SOAP callů |
|
160
|
|
|
*/ |
|
161
|
|
|
public function enableDebugLog() |
|
162
|
|
|
{ |
|
163
|
|
|
if ($this->log !== null) { |
|
164
|
|
|
// Debug log byl již zapnut dříve. |
|
165
|
|
|
return; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
$this->log = []; |
|
169
|
|
|
$logger = function (SkautisQuery $query) { |
|
170
|
|
|
$this->log[] = $query; |
|
171
|
|
|
}; |
|
172
|
|
|
$this->wsdlManager->addWebServiceListener(WebService::EVENT_SUCCESS, $logger); |
|
173
|
|
|
$this->wsdlManager->addWebServiceListener(WebService::EVENT_FAILURE, $logger); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Vrací zalogované SOAP cally |
|
178
|
|
|
* |
|
179
|
|
|
* @return SkautisQuery[] |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getDebugLog() |
|
182
|
|
|
{ |
|
183
|
|
|
return ($this->log !== null) ? $this->log : []; |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|