1
|
|
|
<?php |
2
|
|
|
/* Copyright (C) 2017 Michael Giesler |
3
|
|
|
* |
4
|
|
|
* This file is part of Dembelo. |
5
|
|
|
* |
6
|
|
|
* Dembelo is free software: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Affero General Public License as published by |
8
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* Dembelo is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU Affero General Public License 3 for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU Affero General Public License 3 |
17
|
|
|
* along with Dembelo. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
*/ |
19
|
|
|
namespace AdminBundle\Service\TwineImport; |
20
|
|
|
|
21
|
|
|
use DembeloMain\Document\Importfile; |
22
|
|
|
use DembeloMain\Document\Textnode; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class ParserContext |
26
|
|
|
*/ |
27
|
|
|
class ParserContext |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var Importfile |
31
|
|
|
*/ |
32
|
|
|
private $importfile; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
private $twineRelevant = false; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Textnode |
41
|
|
|
*/ |
42
|
|
|
private $currentTextnode; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
private $twineText = false; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* twineId => $textnode |
51
|
|
|
* @var Textnode[] |
52
|
|
|
*/ |
53
|
|
|
private $textnodeMapping = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var int |
57
|
|
|
*/ |
58
|
|
|
private $twineStartnodeId; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
private $accessSet = false; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* textnodename => textnode |
67
|
|
|
* @var Textnode[] |
68
|
|
|
*/ |
69
|
|
|
private $nodenameMapping = []; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param Importfile $importfile |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
* |
76
|
|
|
* @throws \Exception |
77
|
|
|
*/ |
78
|
4 |
|
public function init(Importfile $importfile): void |
79
|
|
|
{ |
80
|
4 |
|
$this->importfile = $importfile; |
81
|
|
|
|
82
|
4 |
|
if (null === $this->importfile->getLicenseeId()) { |
83
|
1 |
|
throw new \Exception('no licensee available'); |
84
|
|
|
} |
85
|
|
|
|
86
|
3 |
|
if (null === $this->importfile->getFilename()) { |
87
|
1 |
|
throw new \Exception('no filename available'); |
88
|
|
|
} |
89
|
2 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return Importfile |
93
|
|
|
*/ |
94
|
1 |
|
public function getImportfile(): Importfile |
95
|
|
|
{ |
96
|
1 |
|
return $this->importfile; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
1 |
|
public function getFilename(): string |
103
|
|
|
{ |
104
|
1 |
|
return $this->importfile->getFilename(); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return bool |
109
|
|
|
*/ |
110
|
1 |
|
public function isTwineRelevant(): bool |
111
|
|
|
{ |
112
|
1 |
|
return $this->twineRelevant; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param bool $twineRelevant |
117
|
|
|
* |
118
|
|
|
* @return void |
119
|
|
|
*/ |
120
|
1 |
|
public function setTwineRelevant(bool $twineRelevant): void |
121
|
|
|
{ |
122
|
1 |
|
$this->twineRelevant = $twineRelevant; |
123
|
1 |
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return Textnode|null |
127
|
|
|
*/ |
128
|
1 |
|
public function getCurrentTextnode(): ?Textnode |
129
|
|
|
{ |
130
|
1 |
|
return $this->currentTextnode; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param Textnode $currentTextnode |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
1 |
|
public function setCurrentTextnode(Textnode $currentTextnode): void |
139
|
|
|
{ |
140
|
1 |
|
$this->currentTextnode = $currentTextnode; |
141
|
1 |
|
$twineId = $currentTextnode->getTwineId(); |
142
|
1 |
|
$this->textnodeMapping[$twineId] = $currentTextnode; |
143
|
1 |
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return bool |
147
|
|
|
*/ |
148
|
1 |
|
public function isTwineText(): bool |
149
|
|
|
{ |
150
|
1 |
|
return $this->twineText; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param bool $twineText |
155
|
|
|
* |
156
|
|
|
* @return void |
157
|
|
|
*/ |
158
|
1 |
|
public function setTwineText(bool $twineText): void |
159
|
|
|
{ |
160
|
1 |
|
$this->twineText = $twineText; |
161
|
1 |
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return void |
165
|
|
|
*/ |
166
|
1 |
|
public function clearTextnodeMapping(): void |
167
|
|
|
{ |
168
|
1 |
|
$this->textnodeMapping = []; |
169
|
1 |
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return Textnode[] |
173
|
|
|
*/ |
174
|
1 |
|
public function getTextnodeMapping(): array |
175
|
|
|
{ |
176
|
1 |
|
return $this->textnodeMapping; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return int |
181
|
|
|
*/ |
182
|
1 |
|
public function getTwineStartnodeId(): ?int |
183
|
|
|
{ |
184
|
1 |
|
return $this->twineStartnodeId; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param mixed $twineStartnodeId |
189
|
|
|
* |
190
|
|
|
* @return void |
191
|
|
|
*/ |
192
|
1 |
|
public function setTwineStartnodeId(int $twineStartnodeId): void |
193
|
|
|
{ |
194
|
1 |
|
$this->twineStartnodeId = $twineStartnodeId; |
195
|
1 |
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return bool |
199
|
|
|
*/ |
200
|
1 |
|
public function isAccessSet(): bool |
201
|
|
|
{ |
202
|
1 |
|
return $this->accessSet; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param bool $accessSet |
207
|
|
|
* |
208
|
|
|
* @return void |
209
|
|
|
*/ |
210
|
1 |
|
public function setAccessSet(bool $accessSet): void |
211
|
|
|
{ |
212
|
1 |
|
$this->accessSet = $accessSet; |
213
|
1 |
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return Textnode[] |
217
|
|
|
*/ |
218
|
|
|
public function getNodenameMapping(): array |
219
|
|
|
{ |
220
|
|
|
return $this->nodenameMapping; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param Textnode[] $nodenameMapping |
225
|
|
|
* |
226
|
|
|
* @return void |
227
|
|
|
*/ |
228
|
|
|
public function setNodenameMapping(array $nodenameMapping): void |
229
|
|
|
{ |
230
|
|
|
$this->nodenameMapping = $nodenameMapping; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|