|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SDK to communicate with EDBBrugs |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category EDBBrugs |
|
8
|
|
|
* @package EDBBrugs |
|
9
|
|
|
* @author Lars Olesen <[email protected]> |
|
10
|
|
|
* @license MIT Open Source License https://opensource.org/licenses/MIT |
|
11
|
|
|
* @version GIT: <git_id> |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace EDBBrugs; |
|
15
|
|
|
|
|
16
|
|
|
use EDBBrugs\ClientInterface; |
|
17
|
|
|
use EDBBrugs\UtilityInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Service Communicator with EDB-Brugs |
|
21
|
|
|
* |
|
22
|
|
|
* @category EDBBrugs |
|
23
|
|
|
* @package EDBBrugs |
|
24
|
|
|
* @author Lars Olesen <[email protected]> |
|
25
|
|
|
* @license MIT Open Source License https://opensource.org/licenses/MIT |
|
26
|
|
|
* @version GIT: <git_id> |
|
27
|
|
|
*/ |
|
28
|
|
|
class Client implements ClientInterface |
|
29
|
|
|
{ |
|
30
|
|
|
protected $soap; |
|
31
|
|
|
protected $credentials; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Constructor |
|
35
|
|
|
* |
|
36
|
|
|
* @param object $soap Soap Client |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(CredentialsInterface $credentials, $soap) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->credentials = $credentials; |
|
41
|
|
|
$this->soap = $soap; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Gets the utility class for |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function getUtilityClass() |
|
48
|
|
|
{ |
|
49
|
|
|
return new Utility; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Create new registrations from array |
|
54
|
|
|
* |
|
55
|
|
|
* @param array $registrations |
|
56
|
|
|
* |
|
57
|
|
|
* @return RegistrationsCreateResponse |
|
58
|
|
|
*/ |
|
59
|
|
|
public function createNewRegistrations(array $registrations) |
|
60
|
|
|
{ |
|
61
|
|
|
$xml = new \SimpleXMLElement('<Tilmeldinger/>'); |
|
62
|
|
|
$user = $xml->addChild('User'); |
|
63
|
|
|
$user->addChild('Username', $this->credentials->getUsername()); |
|
64
|
|
|
$user->addChild('Passw', $this->credentials->getPassword()); |
|
65
|
|
|
$user->addChild('Skolekode', $this->credentials->getSchoolCode()); |
|
66
|
|
|
foreach ($registrations as $registration) { |
|
67
|
|
|
$reg = $xml->addChild('Tilmelding'); |
|
68
|
|
|
foreach ($registration as $key => $value) { |
|
69
|
|
|
if (strpos($key, '.Land') !== false) { |
|
70
|
|
|
$value = $this->getUtilityClass()->getCountryCode($value); |
|
71
|
|
|
} |
|
72
|
|
|
if (strpos($key, '.Kommune') !== false) { |
|
73
|
|
|
$value = $this->getUtilityClass()->getMunicipalityCode($value); |
|
74
|
|
|
} |
|
75
|
|
|
$reg->addChild($key, $value); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$params = array(); |
|
80
|
|
|
$params['XmlData'] = new \SoapVar($xml->asXml(), XSD_STRING); |
|
81
|
|
|
|
|
82
|
|
|
return new RegistrationsCreateResponse($this->soap->NyTilmelding2($params)); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Gets new registrations |
|
87
|
|
|
* |
|
88
|
|
|
* @return Response |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getNewRegistrations() |
|
91
|
|
|
{ |
|
92
|
|
|
$params = $this->credentials->getArray(); |
|
93
|
|
|
return new Response($this->soap->HentNyeTilmeldingerV2($params)); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Gets handled registrations |
|
98
|
|
|
* |
|
99
|
|
|
* @return Response |
|
100
|
|
|
*/ |
|
101
|
|
|
public function getHandledRegistrations() |
|
102
|
|
|
{ |
|
103
|
|
|
$params = $this->credentials->getArray(); |
|
104
|
|
|
return new Response($this->soap->HentBehandledeTilmeldingerV2($params)); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Delete registrations |
|
109
|
|
|
* |
|
110
|
|
|
* @throws \Exception |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
|
|
public function deleteRegistrations() |
|
114
|
|
|
{ |
|
115
|
|
|
throw new \Exception('It is not possible to delete registrations using the SOAP webservice'); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|