Completed
Push — master ( bc8fac...f29534 )
by WEBEWEB
01:55
created

SkiDataUserParser::parseEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
rs 9.36
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\SkiData\Parser;
13
14
use WBW\Library\Core\Argument\BooleanHelper;
15
use WBW\Library\Core\Argument\IntegerHelper;
16
use WBW\Library\Core\SkiData\Entity\SkiDataUser;
17
18
/**
19
 * SkiData user parser.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Library\Core\SkiData\Parser
23
 */
24
class SkiDataUserParser extends AbstractSkiDataParser {
25
26
    /**
27
     * Constructor.
28
     */
29
    public function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Parse a user entity.
35
     *
36
     * @param SkiDataUser $entity The user entity.
37
     * @return string Returns the parsed user entity.
38
     */
39
    public function parseEntity(SkiDataUser $entity) {
40
41
        // Initialise the output.
42
        $output = [];
43
44
        $output[] = $this->encodeInteger($entity->getUserNumber(), 9);
45
        $output[] = $this->encodeInteger($entity->getCustomerNumber(), 9);
46
        $output[] = $this->encodeString($entity->getTitle(), 10);
47
        $output[] = $this->encodeString($entity->getSurname(), 25);
48
        $output[] = $this->encodeString($entity->getFirstname(), 25);
49
        $output[] = $this->encodeDate($entity->getDateBirth());
50
        $output[] = $this->encodeString($entity->getParkingSpace(), 5);
51
        $output[] = $this->encodeString($entity->getRemarks(), 50);
52
        $output[] = $this->encodeDateTime($entity->getDatetimeLastModification());
53
        $output[] = $this->encodeBoolean($entity->getDeletedRecord());
54
        $output[] = $this->encodeString($entity->getIdentificationNumber(), 20);
55
        $output[] = $this->encodeBoolean($entity->getCheckLicensePlate());
56
        $output[] = $this->encodeBoolean($entity->getPassageLicensePlatePermitted());
57
        $output[] = $this->encodeBoolean($entity->getExcessTimesCreditCard());
58
        $output[] = $this->encodeString($entity->getCreditCardNumber(), 20);
59
        $output[] = $this->encodeDate($entity->getExpiryDate());
60
        $output[] = $this->encodeString($entity->getRemarks2(), 50);
61
        $output[] = $this->encodeString($entity->getRemarks3(), 50);
62
        $output[] = $this->encodeString($entity->getDivision(), 50);
63
        $output[] = $this->encodeString($entity->getEmail(), 120);
64
        $output[] = $this->encodeBoolean($entity->getGroupCounting());
65
        $output[] = $this->encodeInteger($entity->getETicketTypeP(), 1);
66
        $output[] = $this->encodeString($entity->getETicketEmailTelephone(), 120);
67
        $output[] = $this->encodeInteger($entity->getETicketAuthentication(), 1);
68
        $output[] = $this->encodeInteger($entity->getETicketServiceTyp(), 1);
69
        $output[] = $this->encodeInteger($entity->getETicketServiceArt(), 1);
70
71
        // Return the output.
72
        return implode(";", $output);
73
    }
74
75
    /**
76
     * Parse a line.
77
     *
78
     * @param string $line The line.
79
     * @return SkiDataUser Returns a user entity.
80
     */
81
    public function parseLine($line) {
82
83
        // Split the line.
84
        $data = explode(";", $line);
85
        $i    = 0;
86
87
        // Initialize the entity.
88
        $entity = new SkiDataUser();
89
90
        $entity->setUserNumber(IntegerHelper::parseString($data[$i++]));
91
        $entity->setCustomerNumber(IntegerHelper::parseString($data[$i++]));
92
        $entity->setTitle($this->decodeString($data[$i++]));
93
        $entity->setSurname($this->decodeString($data[$i++]));
94
        $entity->setFirstname($this->decodeString($data[$i++]));
95
        $entity->setDateBirth($this->decodeDate($data[$i++]));
96
        $entity->setParkingSpace($this->decodeString($data[$i++]));
97
        $entity->setRemarks($this->decodeString($data[$i++]));
98
        $entity->setDatetimeLastModification($this->decodeDateTime($data[$i++]));
99
        $entity->setDeletedRecord(BooleanHelper::parseString($data[$i++]));
100
        $entity->setIdentificationNumber($this->decodeString($data[$i++]));
101
        $entity->setCheckLicensePlate(BooleanHelper::parseString($data[$i++]));
102
        $entity->setPassageLicensePlatePermitted(BooleanHelper::parseString($data[$i++]));
103
        $entity->setExcessTimesCreditCard(BooleanHelper::parseString($data[$i++]));
104
        $entity->setCreditCardNumber($this->decodeString($data[$i++]));
105
        $entity->setExpiryDate($this->decodeDate($data[$i++]));
106
        $entity->setRemarks2($this->decodeString($data[$i++]));
107
        $entity->setRemarks3($this->decodeString($data[$i++]));
108
        $entity->setDivision($this->decodeString($data[$i++]));
109
        $entity->setEmail($this->decodeString($data[$i++]));
110
        $entity->setGroupCounting(BooleanHelper::parseString($data[$i++]));
111
        $entity->setETicketTypeP(IntegerHelper::parseString($data[$i++]));
112
        $entity->setETicketEmailTelephone($this->decodeString($data[$i++]));
113
        $entity->setETicketAuthentication(IntegerHelper::parseString($data[$i++]));
114
        $entity->setETicketServiceTyp(IntegerHelper::parseString($data[$i++]));
115
        $entity->setETicketServiceArt(IntegerHelper::parseString($data[$i++]));
116
117
        // Return the entity.
118
        return $entity;
119
    }
120
121
}
122