Completed
Push — master ( 381bc0...2b9053 )
by Lars
05:55 queued 02:03
created

Client::getHandledRegistrations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
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
18
/**
19
 * Service Communicator with EDB-Brugs
20
 *
21
 * @category EDBBrugs
22
 * @package  EDBBrugs
23
 * @author   Lars Olesen <[email protected]>
24
 * @license  MIT Open Source License https://opensource.org/licenses/MIT
25
 * @version  GIT: <git_id>
26
 */
27
class Client implements ClientInterface
28
{
29
    protected $soap;
30
    protected $credentials;
31
32
    /**
33
     * Constructor
34
     *
35
     * @param object $soap Soap Client
36
     */
37
    public function __construct(CredentialsInterface $credentials, $soap)
38
    {
39
        $this->credentials = $credentials;
40
        $this->soap = $soap;
41
    }
42
43
    /**
44
     * Create new registrations from array
45
     *
46
     * @param array $registrations
47
     *
48
     * @return RegistrationsCreateResponse
49
     */
50
    public function createNewRegistrations(array $registrations)
51
    {
52
        $xml = new \SimpleXMLElement('<Tilmeldinger/>');
53
        $user = $xml->addChild('User');
54
        $user->addChild('Username', $this->credentials->getUsername());
55
        $user->addChild('Passw', $this->credentials->getPassword());
56
        $user->addChild('Skolekode', $this->credentials->getSchoolCode());
57
        foreach ($registrations as $registration) {
58
            $reg = $xml->addChild('Tilmelding');
59
            foreach ($registration as $key => $value) {
60
                $reg->addChild($key, $value);
61
            }
62
        }
63
64
        $params = array();
65
        $params['XmlData'] = new \SoapVar($xml->asXml(), XSD_STRING);
66
67
        return new RegistrationsCreateResponse($this->soap->NyTilmelding2($params));
68
    }
69
70
    /**
71
     * Gets new registrations
72
     *
73
     * @return Response
74
     */
75
    public function getNewRegistrations()
76
    {
77
        $params = $this->credentials->getArray();
78
        return new Response($this->soap->HentNyeTilmeldingerV2($params));
79
    }
80
81
    /**
82
     * Gets handled registrations
83
     *
84
     * @return Response
85
     */
86
    public function getHandledRegistrations()
87
    {
88
        $params = $this->credentials->getArray();
89
        return new Response($this->soap->HentBehandledeTilmeldingerV2($params));
90
    }
91
92
    /**
93
     * Delete registrations
94
     *
95
     * @throws \Exception
96
     * @return void
97
     */
98
    public function deleteRegistrations()
99
    {
100
        throw new \Exception('It is not possible to delete registrations using the SOAP webservice');
101
    }
102
}
103