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