Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 222
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Service
0.00% covered (danger)
0.00%
0 / 222
0.00% covered (danger)
0.00%
0 / 4
72
0.00% covered (danger)
0.00%
0 / 1
 setupMapping
0.00% covered (danger)
0.00%
0 / 204
0.00% covered (danger)
0.00%
0 / 1
2
 preSetup
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
 deleteEntity
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 clearEntity
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace BO\Zmsdldb\Importer\MySQL\Entity;
4
5use Error;
6
7class Service extends Base
8{
9    protected array $fieldMapping = [
10        'id' => 'id',
11        'name' => 'name',
12        'hint' => 'hint',
13        'leika' => 'leika',
14        'fees' => 'fees',
15        'appointment.link' => 'appointment_all_link',
16        'responsibility' => 'responsibility',
17        'responsibility_all' => 'responsibility_all',
18        'description' => 'description',
19        'processing_time' => 'processing_time',
20        'relation.root_topic' => 'root_topic_id',
21        'meta.locale' => 'locale',
22        'residence' => 'residence',
23        'representation' => 'representation',
24        'authorities' => 'authorities_json',
25        'onlineprocessing' => 'onlineprocessing_json',
26        'relation' => 'relation_json',
27        '__RAW__' => 'data_json'
28    ];
29
30    /**
31     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
32     */
33    #[\Override]
34    protected function setupMapping(): void
35    {
36        $this->referanceMapping = [
37            'name' => [
38                'class' => Search::class,
39                'neededFields' => [
40                    'id' => 'object_id',
41                    'meta.locale' => 'locale',
42                    'name' => 'search_value'
43                ],
44                'addFields' => [
45                    'entity_type' => static::getTableName(),
46                    'search_type' => 'name'
47                ],
48                'multiple' => false,
49                'clearFields' => [
50                    'entity_type' => static::getTableName(),
51                    'locale' => $this->get('meta.locale')
52                ],
53                'deleteFields' => [
54                    'object_id' => $this->get('id'),
55                    'locale' => $this->get('meta.locale'),
56                    'entity_type' => static::getTableName()
57                ],
58                'selfAsArray' => true
59            ],
60            /*
61            'description' => [
62                'class' => Search::class,
63                'neededFields' => [
64                    'id' => 'object_id',
65                    'meta.locale' => 'locale',
66                    'description' => 'search_value'
67                ],
68                'addFields' => [
69                    'entity_type' => static::getTableName(),
70                    'search_type' => 'description'
71                ],
72                'deleteFields' => [
73                    'object_id' => $this->get('id'),
74                    'locale' => $this->get('meta.locale'),
75                    'entity_type' => static::getTableName()
76                ],
77                'multiple' => false,
78                'clearFields' => [
79                    'entity_type' => static::getTableName(),
80                    'locale' => $this->get('meta.locale')
81                ],
82                'selfAsArray' => true
83            ],
84            */
85            'meta.keywords' => [
86                'class' => Search::class,
87                'neededFields' => [
88                    'id' => 'object_id',
89                    'meta.locale' => 'locale',
90                    'meta.keywords' => 'search_value',
91                ],
92                'addFields' => [
93                    'entity_type' => static::getTableName(),
94                    'search_type' => 'keywords'
95                ],
96                'deleteFields' => [
97                    'object_id' => $this->get('id'),
98                    'locale' => $this->get('meta.locale'),
99                    'entity_type' => static::getTableName()
100                ],
101                'multiple' => false,
102                'clearFields' => [
103                    'entity_type' => static::getTableName(),
104                    'locale' => $this->get('meta.locale')
105                ],
106                'selfAsArray' => true
107            ],
108            'meta' => [
109                'class' => Meta::class,
110                'neededFields' => ['id' => 'object_id', 'meta.locale' => 'locale'],
111                'addFields' => [
112                    'type' => static::getTableName()
113                ],
114                'deleteFields' => [
115                    'object_id' => $this->get('id'),
116                    'locale' => $this->get('meta.locale'),
117                    'type' => static::getTableName()
118                ],
119                'multiple' => false,
120                'clearFields' => [
121                    'type' => static::getTableName(),
122                    'locale' => $this->get('meta.locale')
123                ],
124            ],
125            'authorities' => [
126                'class' => AuthorityService::class,
127                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
128                'addFields' => [
129
130                ],
131                'deleteFields' => [
132                    'service_id' => $this->get('id'),
133                    'locale' => $this->get('meta.locale')
134                ],
135                'clearFields' => [
136                    'locale' => $this->get('meta.locale')
137                ]
138            ],
139            'locations' => [
140                'class' => LocationService::class,
141                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
142                'addFields' => [],
143                'deleteFields' => [
144                    'service_id' => $this->get('id'),
145                    'locale' => $this->get('meta.locale')
146                ],
147                'clearFields' => [
148                    'locale' => $this->get('meta.locale')
149                ]
150            ],
151            'requirements' => [
152                'class' => ServiceInformation::class,
153                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
154                'addFields' => [
155                    'type' => 'requirements',
156                    'sort' => static function (int $position): int {
157                        return $position;
158                    }
159                ],
160                'deleteFields' => [
161                    'service_id' => $this->get('id'),
162                    'locale' => $this->get('meta.locale'),
163                    'type' => 'requirements',
164                ],
165                'clearFields' => [
166                    'type' => 'requirements',
167                    'locale' => $this->get('meta.locale')
168                ],
169            ],
170            'forms' => [
171                'class' => ServiceInformation::class,
172                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
173                'addFields' => [
174                    'type' => 'forms',
175                    'sort' => static function (int $position): int {
176                        return $position;
177                    }
178                ],
179                'deleteFields' => [
180                    'service_id' => $this->get('id'),
181                    'locale' => $this->get('meta.locale'),
182                    'type' => 'forms',
183                ],
184                'clearFields' => [
185                    'type' => 'forms',
186                    'locale' => $this->get('meta.locale')
187                ],
188            ],
189            'prerequisites' => [
190                'class' => ServiceInformation::class,
191                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
192                'addFields' => [
193                    'type' => 'prerequisites',
194                    'sort' => static function (int $position): int {
195                        return $position;
196                    }
197                ],
198                'deleteFields' => [
199                    'service_id' => $this->get('id'),
200                    'locale' => $this->get('meta.locale'),
201                    'type' => 'prerequisites',
202                ],
203                'clearFields' => [
204                    'type' => 'prerequisites',
205                    'locale' => $this->get('meta.locale')
206                ],
207            ],
208            'links' => [
209                'class' => ServiceInformation::class,
210                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
211                'addFields' => [
212                    'type' => 'links',
213                    'sort' => static function (int $position): int {
214                        return $position;
215                    }
216                ],
217                'deleteFields' => [
218                    'service_id' => $this->get('id'),
219                    'locale' => $this->get('meta.locale'),
220                    'type' => 'links',
221                ],
222                'clearFields' => [
223                    'type' => 'links',
224                    'locale' => $this->get('meta.locale')
225                ],
226            ],
227            'publications' => [
228                'class' => ServiceInformation::class,
229                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
230                'addFields' => [
231                    'type' => 'publications',
232                    'sort' => static function (int $position): int {
233                        return $position;
234                    }
235                ],
236                'deleteFields' => [
237                    'service_id' => $this->get('id'),
238                    'locale' => $this->get('meta.locale'),
239                    'type' => 'publications',
240                ],
241                'clearFields' => [
242                    'type' => 'publications',
243                    'locale' => $this->get('meta.locale')
244                ],
245            ],
246            'legal' => [
247                'class' => ServiceInformation::class,
248                'neededFields' => ['id' => 'service_id', 'meta.locale' => 'locale'],
249                'addFields' => [
250                    'type' => 'legal',
251                    'sort' => static function (int $position): int {
252                        return $position;
253                    }
254                ],
255                'deleteFields' => [
256                    'service_id' => $this->get('id'),
257                    'locale' => $this->get('meta.locale'),
258                    'type' => 'legal',
259                ],
260                'clearFields' => [
261                    'type' => 'legal',
262                    'locale' => $this->get('meta.locale')
263                ],
264            ]
265        ];
266    }
267
268    #[\Override]
269    public function preSetup(): void
270    {
271        try {
272            $this->setStatus(static::STATUS_OLD);
273            if ($this->entityNeedsUpdate()) {
274                $this->setStatus(static::STATUS_NEW);
275                $this->setupFields();
276                $this->deleteEntity();
277                $this->deleteReferences();
278            }
279        } catch (\Exception $e) {
280            throw $e;
281        }
282    }
283
284    #[\Override]
285    public function deleteEntity(): void
286    {
287        try {
288            $this->deleteWith(
289                array_combine(['id', 'locale'], array_values($this->get(['id', 'meta.locale'])))
290            );
291        } catch (\Exception $e) {
292            throw $e;
293        }
294    }
295
296    #[\Override]
297    public function clearEntity(array $addWhere = []): void
298    {
299        try {
300            #print_r((array)$this->get(['meta.locale']));exit;
301            $this->deleteWith(
302                ['locale' => $this->get('meta.locale')]
303            );
304        } catch (\Exception $e) {
305            throw $e;
306        }
307    }
308}