|
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\ThirdParty\SkiData\Parser; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Library\Core\Argument\BooleanHelper; |
|
15
|
|
|
use WBW\Library\Core\Argument\IntegerHelper; |
|
16
|
|
|
use WBW\Library\Core\Exception\Argument\IntegerArgumentException; |
|
17
|
|
|
use WBW\Library\Core\ThirdParty\SkiData\Exception\TooLongDataException; |
|
18
|
|
|
use WBW\Library\Core\ThirdParty\SkiData\Model\Card; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Card parser. |
|
22
|
|
|
* |
|
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
24
|
|
|
* @package WBW\Library\Core\ThirdParty\SkiData\Parser |
|
25
|
|
|
*/ |
|
26
|
|
|
class CardParser extends AbstractParser { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Constructor. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() { |
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Parse a card entity. |
|
37
|
|
|
* |
|
38
|
|
|
* @param Card $entity The card. |
|
39
|
|
|
* @return string Returns the parsed card. |
|
40
|
|
|
* @throws TooLongDataException Throws a too long data exception if a data is too long. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function parseEntity(Card $entity) { |
|
43
|
|
|
|
|
44
|
|
|
$output = [ |
|
45
|
|
|
$this->encodeString($entity->getTicketNumber(), 23), |
|
46
|
|
|
$this->encodeInteger($entity->getUserNumber(), 9), |
|
47
|
|
|
$this->encodeInteger($entity->getArticleNumber(), 3), |
|
48
|
|
|
$this->encodeDate($entity->getValidFrom()), |
|
49
|
|
|
$this->encodeDate($entity->getExpires()), |
|
50
|
|
|
$this->encodeBoolean($entity->getBlocked()), |
|
51
|
|
|
$this->encodeDate($entity->getBlockedDate()), |
|
52
|
|
|
$this->encodeInteger($entity->getProductionState(), 1), |
|
53
|
|
|
$this->encodeInteger($entity->getReasonProduction(), 1), |
|
54
|
|
|
$this->encodeInteger($entity->getProductionCounter(), 4), |
|
55
|
|
|
$this->encodeBoolean($entity->getNeutral()), |
|
56
|
|
|
$this->encodeBoolean($entity->getRetainTicketEntry()), |
|
57
|
|
|
$this->encodeBoolean($entity->getEntryBarrierClosed()), |
|
58
|
|
|
$this->encodeBoolean($entity->getExitBarrierClosed()), |
|
59
|
|
|
$this->encodeBoolean($entity->getRetainTicketExit()), |
|
60
|
|
|
$this->encodeBoolean($entity->getDisplayText()), |
|
61
|
|
|
$this->encodeString($entity->getDisplayText1(), 16), |
|
62
|
|
|
$this->encodeString($entity->getDisplayText2(), 16), |
|
63
|
|
|
$this->encodeInteger($entity->getPersonnalNo(), 4), |
|
64
|
|
|
$this->encodeInteger($entity->getResidualValue(), 12), |
|
65
|
|
|
$this->encodeString($entity->getSerialNumberKeyCardSwatch(), 20), |
|
66
|
|
|
$this->encodeString($entity->getCurrencyResidualValue(), 3), |
|
67
|
|
|
$this->encodeInteger($entity->getTicketType(), 1), |
|
68
|
|
|
$this->encodeString($entity->getTicketSubType(), 5), |
|
69
|
|
|
$this->encodeString($entity->getSerialNo(), 30), |
|
70
|
|
|
$this->encodeDate($entity->getSuspendPeriodFrom()), |
|
71
|
|
|
$this->encodeDate($entity->getSuspendPeriodUntil()), |
|
72
|
|
|
$this->encodeBoolean($entity->getUseValidCarParks()), |
|
73
|
|
|
$this->encodeInteger($entity->getProductionFacilityNumber(), 7), |
|
74
|
|
|
]; |
|
75
|
|
|
|
|
76
|
|
|
return implode(";", $output); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Parse a line. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $line The line. |
|
83
|
|
|
* @return Card Returns a card. |
|
84
|
|
|
* @throws IntegerArgumentException Throws an integer argument exception. |
|
85
|
|
|
*/ |
|
86
|
|
|
public function parseLine($line) { |
|
87
|
|
|
|
|
88
|
|
|
$data = explode(";", $line); |
|
89
|
|
|
$i = -1; |
|
90
|
|
|
|
|
91
|
|
|
$model = new Card(); |
|
92
|
|
|
$model->setTicketNumber($this->decodeString($data[++$i])); |
|
93
|
|
|
$model->setUserNumber(IntegerHelper::parseString($data[++$i])); |
|
94
|
|
|
$model->setArticleNumber(IntegerHelper::parseString($data[++$i])); |
|
95
|
|
|
$model->setValidFrom($this->decodeDate($data[++$i])); |
|
96
|
|
|
$model->setExpires($this->decodeDate($data[++$i])); |
|
97
|
|
|
$model->setBlocked(BooleanHelper::parseString($data[++$i])); |
|
98
|
|
|
$model->setBlockedDate($this->decodeDate($data[++$i])); |
|
99
|
|
|
$model->setProductionState(IntegerHelper::parseString($data[++$i])); |
|
100
|
|
|
$model->setReasonProduction(IntegerHelper::parseString($data[++$i])); |
|
101
|
|
|
$model->setProductionCounter(IntegerHelper::parseString($data[++$i])); |
|
102
|
|
|
$model->setNeutral(BooleanHelper::parseString($data[++$i])); |
|
103
|
|
|
$model->setRetainTicketEntry(BooleanHelper::parseString($data[++$i])); |
|
104
|
|
|
$model->setEntryBarrierClosed(BooleanHelper::parseString($data[++$i])); |
|
105
|
|
|
$model->setExitBarrierClosed(BooleanHelper::parseString($data[++$i])); |
|
106
|
|
|
$model->setRetainTicketExit(BooleanHelper::parseString($data[++$i])); |
|
107
|
|
|
$model->setDisplayText(BooleanHelper::parseString($data[++$i])); |
|
108
|
|
|
$model->setDisplayText1($this->decodeString($data[++$i])); |
|
109
|
|
|
$model->setDisplayText2($this->decodeString($data[++$i])); |
|
110
|
|
|
$model->setPersonnalNo(IntegerHelper::parseString($data[++$i])); |
|
111
|
|
|
$model->setResidualValue(IntegerHelper::parseString($data[++$i])); |
|
112
|
|
|
$model->setSerialNumberKeyCardSwatch($this->decodeString($data[++$i])); |
|
113
|
|
|
$model->setCurrencyResidualValue($this->decodeString($data[++$i])); |
|
114
|
|
|
$model->setTicketType(IntegerHelper::parseString($data[++$i])); |
|
115
|
|
|
$model->setTicketSubType($this->decodeString($data[++$i])); |
|
116
|
|
|
$model->setSerialNo($this->decodeString($data[++$i])); |
|
117
|
|
|
$model->setSuspendPeriodFrom($this->decodeDate($data[++$i])); |
|
118
|
|
|
$model->setSuspendPeriodUntil($this->decodeDate($data[++$i])); |
|
119
|
|
|
$model->setUseValidCarParks(BooleanHelper::parseString($data[++$i])); |
|
120
|
|
|
$model->setProductionFacilityNumber(IntegerHelper::parseString($data[++$i])); |
|
121
|
|
|
|
|
122
|
|
|
return $model; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|