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

SkiDataCustomerParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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\SkiDataCustomer;
17
18
/**
19
 * SkiData customer parser.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Library\Core\SkiData\Parser
23
 */
24
class SkiDataCustomerParser extends AbstractSkiDataParser {
25
26
    /**
27
     * Constructor.
28
     */
29
    public function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Parse a customer entity.
35
     *
36
     * @param SkiDataCustomer $entity The customer entity.
37
     * @return string Returns the parsed customer entity.
38
     */
39
    public function parseEntity(SkiDataCustomer $entity) {
40
41
        // Initialise the output.
42
        $output = [];
43
44
        $output[] = $this->encodeInteger($entity->getCustomerNumber(), 9);
45
        $output[] = $this->encodeString($entity->getTitle(), 10);
46
        $output[] = $this->encodeString($entity->getSurname(), 25);
47
        $output[] = $this->encodeString($entity->getFirstname(), 25);
48
        $output[] = $this->encodeString($entity->getStreet(), 25);
49
        $output[] = $this->encodeString($entity->getPCode(), 10);
50
        $output[] = $this->encodeString($entity->getCity(), 25);
51
        $output[] = $this->encodeString($entity->getCountry(), 3);
52
        $output[] = $this->encodeString($entity->getTaxCode(), 16);
53
        $output[] = $this->encodeString($entity->getIdDocumentNo(), 15);
54
        $output[] = $this->encodeString($entity->getTelephone(), 20);
55
        $output[] = $this->encodeString($entity->getRentalAgreementNo(), 20);
56
        $output[] = $this->encodeDate($entity->getBeginDate());
57
        $output[] = $this->encodeDate($entity->getTerminationDate());
58
        $output[] = $this->encodeInteger($entity->getDeposit(), 12);
59
        $output[] = $this->encodeInteger($entity->getMaximumLevel(), 4);
60
        $output[] = $this->encodeString($entity->getRemarks(), 50);
61
        $output[] = $this->encodeDateTime($entity->getDatetimeLastModification());
62
        $output[] = $this->encodeBoolean($entity->getBlocked());
63
        $output[] = $this->encodeDate($entity->getBlockedDate());
64
        $output[] = $this->encodeBoolean($entity->getDeletedRecord());
65
        $output[] = $this->encodeBoolean($entity->getTicketReturnAllowed());
66
        $output[] = $this->encodeBoolean($entity->getGroupCounting());
67
        $output[] = $this->encodeBoolean($entity->getEntryMaxLevelAllowed());
68
        $output[] = $this->encodeBoolean($entity->getMaxLevelCarPark());
69
        $output[] = $this->encodeString($entity->getRemarks2(), 50);
70
        $output[] = $this->encodeString($entity->getRemarks3(), 50);
71
        $output[] = $this->encodeString($entity->getDivision(), 25);
72
        $output[] = $this->encodeString($entity->getEmail(), 120);
73
        $output[] = $this->encodeBoolean($entity->getCountingNeutralCards());
74
        $output[] = $this->encodeString($entity->getNationality(), 3);
75
        $output[] = $this->encodeString($entity->getAccountingNumber(), 20);
76
77
        // Return the output.
78
        return implode(";", $output);
79
    }
80
81
    /**
82
     * Parse a line.
83
     *
84
     * @param string $line The line.
85
     * @return SkiDataCustomer Returns a customer entity.
86
     */
87
    public function parseLine($line) {
88
89
        // Split the line.
90
        $data = explode(";", $line);
91
        $i    = 0;
92
93
        // Initialize the entity.
94
        $entity = new SkiDataCustomer();
95
96
        $entity->setCustomerNumber(IntegerHelper::parseString($data[$i++]));
97
        $entity->setTitle($this->decodeString($data[$i++]));
98
        $entity->setSurname($this->decodeString($data[$i++]));
99
        $entity->setFirstname($this->decodeString($data[$i++]));
100
        $entity->setStreet($this->decodeString($data[$i++]));
101
        $entity->setPCode($this->decodeString($data[$i++]));
102
        $entity->setCity($this->decodeString($data[$i++]));
103
        $entity->setCountry($this->decodeString($data[$i++]));
104
        $entity->setTaxCode($this->decodeString($data[$i++]));
105
        $entity->setIdDocumentNo($this->decodeString($data[$i++]));
106
        $entity->setTelephone($this->decodeString($data[$i++]));
107
        $entity->setRentalAgreementNo($this->decodeString($data[$i++]));
108
        $entity->setBeginDate($this->decodeDate($data[$i++]));
109
        $entity->setTerminationDate($this->decodeDate($data[$i++]));
110
        $entity->setDeposit(IntegerHelper::parseString($data[$i++]));
111
        $entity->setMaximumLevel(IntegerHelper::parseString($data[$i++]));
112
        $entity->setRemarks($this->decodeString($data[$i++]));
113
        $entity->setDatetimeLastModification($this->decodeDateTime($data[$i++]));
114
        $entity->setBlocked(BooleanHelper::parseString($data[$i++]));
115
        $entity->setBlockedDate($this->decodeDate($data[$i++]));
116
        $entity->setDeletedRecord(BooleanHelper::parseString($data[$i++]));
117
        $entity->setTicketReturnAllowed(BooleanHelper::parseString($data[$i++]));
118
        $entity->setGroupCounting(BooleanHelper::parseString($data[$i++]));
119
        $entity->setEntryMaxLevelAllowed(BooleanHelper::parseString($data[$i++]));
120
        $entity->setMaxLevelCarPark(BooleanHelper::parseString($data[$i++]));
121
        $entity->setRemarks2($this->decodeString($data[$i++]));
122
        $entity->setRemarks3($this->decodeString($data[$i++]));
123
        $entity->setDivision($this->decodeString($data[$i++]));
124
        $entity->setEmail($this->decodeString($data[$i++]));
125
        $entity->setCountingNeutralCards(BooleanHelper::parseString($data[$i++]));
126
        $entity->setNationality($this->decodeString($data[$i++]));
127
        $entity->setAccountingNumber($this->decodeString($data[$i++]));
128
129
        // Return the entity.
130
        return $entity;
131
    }
132
133
}
134