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
|
|
|
foreach (array('.Fastnet', '.Mobil', '.ArbejdeTlf') as $variable) { |
70
|
|
|
if (strpos($key, '.Fastnet') !== false) { |
71
|
|
|
$value = $this->getUtilityClass()->fixPhoneNumber($value); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
foreach (array('.Kursus', '.Email') as $variable) { |
75
|
|
|
if (strpos($key, $variable) !== false) { |
76
|
|
|
$value = substr($value, 0, 50); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
foreach (array('.Fornavn', '.Efternavn', '.Adresse', '.Lokalby', '.Bynavn') as $variable) { |
80
|
|
|
if (strpos($key, $variable) !== false) { |
81
|
|
|
$value = substr($value, 0, 35); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
View Code Duplication |
foreach (array('.Linje') as $variable) { |
|
|
|
|
85
|
|
|
if (strpos($key, $variable) !== false) { |
86
|
|
|
$value = substr($value, 0, 30); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
View Code Duplication |
foreach (array('.CprNr') as $variable) { |
|
|
|
|
90
|
|
|
if (strpos($key, $variable) !== false) { |
91
|
|
|
$value = substr($value, 0, 20); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
foreach (array('.Postnr', '.Fastnet', '.Mobil', 'ArbejdeTlf') as $variable) { |
95
|
|
|
if (strpos($key, $variable) !== false) { |
96
|
|
|
$value = substr($value, 0, 15); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
if (strpos($key, '.Land') !== false) { |
100
|
|
|
$value = $this->getUtilityClass()->getCountryCode($value); |
101
|
|
|
} |
102
|
|
|
if (strpos($key, '.Kommune') !== false) { |
103
|
|
|
$value = $this->getUtilityClass()->getMunicipalityCode($value); |
104
|
|
|
} |
105
|
|
|
$reg->addChild($key, $value); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$params = array(); |
110
|
|
|
$params['XmlData'] = new \SoapVar($xml->asXml(), XSD_STRING); |
111
|
|
|
|
112
|
|
|
return new RegistrationsCreateResponse($this->soap->NyTilmelding2($params)); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Gets new registrations |
117
|
|
|
* |
118
|
|
|
* @return Response |
119
|
|
|
*/ |
120
|
|
|
public function getNewRegistrations() |
121
|
|
|
{ |
122
|
|
|
$params = $this->credentials->getArray(); |
123
|
|
|
return new Response($this->soap->HentNyeTilmeldingerV2($params)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Gets handled registrations |
128
|
|
|
* |
129
|
|
|
* @return Response |
130
|
|
|
*/ |
131
|
|
|
public function getHandledRegistrations() |
132
|
|
|
{ |
133
|
|
|
$params = $this->credentials->getArray(); |
134
|
|
|
return new Response($this->soap->HentBehandledeTilmeldingerV2($params)); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Delete registrations |
139
|
|
|
* |
140
|
|
|
* @throws \Exception |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
public function deleteRegistrations() |
144
|
|
|
{ |
145
|
|
|
throw new \Exception('It is not possible to delete registrations using the SOAP webservice'); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.