CharacterSheet::preserveToJumpCloneImplants()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
ccs 0
cts 21
cp 0
rs 9.3142
cc 1
eloc 18
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * Contains class CharacterSheet.
5
 *
6
 * PHP version 7.0+
7
 *
8
 * LICENSE:
9
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
10
 * which can be used to access the Eve Online API data and place it into a
11
 * database.
12
 * Copyright (C) 2016-2017 Michael Cummings
13
 *
14
 * This program is free software: you can redistribute it and/or modify it
15
 * under the terms of the GNU Lesser General Public License as published by the
16
 * Free Software Foundation, either version 3 of the License, or (at your
17
 * option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful, but WITHOUT
20
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
22
 * for more details.
23
 *
24
 * You should have received a copy of the GNU Lesser General Public License
25
 * along with this program. If not, see
26
 * <http://spdx.org/licenses/LGPL-3.0.html>.
27
 *
28
 * You should be able to find a copy of this license in the COPYING-LESSER.md
29
 * file. A copy of the GNU GPL should also be available in the COPYING.md file.
30
 *
31
 * @copyright 2016-2017 Michael Cummings
32
 * @license   LGPL-3.0+
33
 * @author    Michael Cummings <[email protected]>
34
 */
35
namespace Yapeal\EveApi\Char;
36
37
use Yapeal\Event\EveApiPreserverInterface;
38
use Yapeal\Log\Logger;
39
use Yapeal\Sql\PreserverTrait;
40
use Yapeal\Xml\EveApiReadWriteInterface;
41
42
/**
43
 * Class CharacterSheet
44
 */
45
class CharacterSheet extends CharSection implements EveApiPreserverInterface
46
{
47
    use PreserverTrait;
48
49
    /**
50
     * Constructor
51
     */
52
    public function __construct()
53
    {
54
        $this->mask = 8;
55
        $this->preserveTos = [
56
            'preserveToAttributes',
57
            'preserveToCertificates',
58
            'preserveToCharacterSheet',
59
            'preserveToCorporationRoles',
60
            'preserveToCorporationRolesAtBase',
61
            'preserveToCorporationRolesAtHQ',
62
            'preserveToCorporationRolesAtOther',
63
            'preserveToCorporationTitles',
64
            'preserveToImplants',
65
            'preserveToJumpCloneImplants',
66
            'preserveToJumpClones',
67
            'preserveToSkills'
68
        ];
69
    }
70
    /**
71
     * @param EveApiReadWriteInterface $data
72
     *
73
     * @return self Fluent interface.
74
     * @throws \DomainException
75
     * @throws \InvalidArgumentException
76
     * @throws \UnexpectedValueException
77
     */
78
    protected function preserveToAttributes(EveApiReadWriteInterface $data): self
79
    {
80
        $tableName = 'charAttributes';
81
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
82
        $sql = $this->getCsq()
83
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
84
        $this->getYem()
85
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
86
        $this->getPdo()
87
            ->exec($sql);
88
        $columnDefaults = [
89
            'charisma' => null,
90
            'intelligence' => null,
91
            'memory' => null,
92
            'ownerID' => $ownerID,
93
            'perception' => null,
94
            'willpower' => null
95
        ];
96
        $xPath = '//attributes/*';
97
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
98
        $this->valuesPreserveData($elements, $columnDefaults, $tableName);
99
        return $this;
100
    }
101
    /**
102
     * @param EveApiReadWriteInterface $data
103
     *
104
     * @return self Fluent interface.
105
     * @throws \DomainException
106
     * @throws \InvalidArgumentException
107
     * @throws \UnexpectedValueException
108
     */
109
    protected function preserveToCertificates(EveApiReadWriteInterface $data): self
110
    {
111
        $tableName = 'charCertificates';
112
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
113
        $sql = $this->getCsq()
114
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
115
        $this->getYem()
116
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
117
        $this->getPdo()
118
            ->exec($sql);
119
        $columnDefaults = [
120
            'certificateID' => null,
121
            'ownerID' => $ownerID
122
        ];
123
        $xPath = '//certificates/row';
124
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
125
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
126
        return $this;
127
    }
128
    /**
129
     * @param EveApiReadWriteInterface $data
130
     *
131
     * @return self Fluent interface.
132
     * @throws \DomainException
133
     * @throws \InvalidArgumentException
134
     * @throws \UnexpectedValueException
135
     */
136
    protected function preserveToCharacterSheet(EveApiReadWriteInterface $data): self
137
    {
138
        $tableName = 'charCharacterSheet';
139
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
140
        $sql = $this->getCsq()
141
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
142
        $this->getYem()
143
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
144
        $this->getPdo()
145
            ->exec($sql);
146
        $columnDefaults = [
147
            'allianceID' => null,
148
            'allianceName' => '',
149
            'ancestry' => null,
150
            'ancestryID' => null,
151
            'balance' => '0.0',
152
            'bloodLine' => null,
153
            'bloodLineID' => null,
154
            'characterID' => null,
155
            'cloneJumpDate' => '1970-01-01 00:00:01',
156
            'cloneName' => '',
157
            'cloneSkillPoints' => 0,
158
            'cloneTypeID' => 0,
159
            'corporationID' => null,
160
            'corporationName' => '',
161
            'DoB' => null,
162
            'factionID' => 0,
163
            'factionName' => '',
164
            'freeRespecs' => null,
165
            'freeSkillPoints' => 0,
166
            'gender' => null,
167
            'homeStationID' => 0,
168
            'jumpActivation' => '1970-01-01 00:00:01',
169
            'jumpFatigue' => '1970-01-01 00:00:01',
170
            'jumpLastUpdate' => '1970-01-01 00:00:01',
171
            'lastRespecDate' => '1970-01-01 00:00:01',
172
            'lastTimedRespec' => '1970-01-01 00:00:01',
173
            'name' => '',
174
            'ownerID' => $ownerID,
175
            'race' => null,
176
            'remoteStationDate' => '1970-01-01 00:00:01'
177
        ];
178
        $xPath = '//result/child::*[not(*|@*|self::dataTime)]';
179
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
180
        $this->valuesPreserveData($elements, $columnDefaults, $tableName);
181
        return $this;
182
    }
183
    /**
184
     * @param EveApiReadWriteInterface $data
185
     *
186
     * @return self Fluent interface.
187
     * @throws \DomainException
188
     * @throws \InvalidArgumentException
189
     * @throws \UnexpectedValueException
190
     */
191
    protected function preserveToCorporationRoles(EveApiReadWriteInterface $data): self
192
    {
193
        $tableName = 'charCorporationRoles';
194
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
195
        $sql = $this->getCsq()
196
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
197
        $this->getYem()
198
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
199
        $this->getPdo()
200
            ->exec($sql);
201
        $columnDefaults = [
202
            'ownerID' => $ownerID,
203
            'roleID' => null,
204
            'roleName' => ''
205
        ];
206
        $xPath = '//corporationRoles/row';
207
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
208
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
209
        return $this;
210
    }
211
    /**
212
     * @param EveApiReadWriteInterface $data
213
     *
214
     * @return self Fluent interface.
215
     * @throws \DomainException
216
     * @throws \InvalidArgumentException
217
     * @throws \UnexpectedValueException
218
     */
219
    protected function preserveToCorporationRolesAtBase(EveApiReadWriteInterface $data): self
220
    {
221
        $tableName = 'charCorporationRolesAtBase';
222
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
223
        $sql = $this->getCsq()
224
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
225
        $this->getYem()
226
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
227
        $this->getPdo()
228
            ->exec($sql);
229
        $columnDefaults = [
230
            'ownerID' => $ownerID,
231
            'roleID' => null,
232
            'roleName' => ''
233
        ];
234
        $xPath = '//corporationRolesAtBase/row';
235
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
236
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
237
        return $this;
238
    }
239
    /**
240
     * @param EveApiReadWriteInterface $data
241
     *
242
     * @return self Fluent interface.
243
     * @throws \DomainException
244
     * @throws \InvalidArgumentException
245
     * @throws \UnexpectedValueException
246
     */
247
    protected function preserveToCorporationRolesAtHQ(EveApiReadWriteInterface $data): self
248
    {
249
        $tableName = 'charCorporationRolesAtHQ';
250
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
251
        $sql = $this->getCsq()
252
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
253
        $this->getYem()
254
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
255
        $this->getPdo()
256
            ->exec($sql);
257
        $columnDefaults = [
258
            'ownerID' => $ownerID,
259
            'roleID' => null,
260
            'roleName' => ''
261
        ];
262
        $xPath = '//corporationRolesAtHQ/row';
263
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
264
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
265
        return $this;
266
    }
267
    /**
268
     * @param EveApiReadWriteInterface $data
269
     *
270
     * @return self Fluent interface.
271
     * @throws \DomainException
272
     * @throws \InvalidArgumentException
273
     * @throws \UnexpectedValueException
274
     */
275
    protected function preserveToCorporationRolesAtOther(EveApiReadWriteInterface $data): self
276
    {
277
        $tableName = 'charCorporationRolesAtOther';
278
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
279
        $sql = $this->getCsq()
280
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
281
        $this->getYem()
282
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
283
        $this->getPdo()
284
            ->exec($sql);
285
        $columnDefaults = [
286
            'ownerID' => $ownerID,
287
            'roleID' => null,
288
            'roleName' => ''
289
        ];
290
        $xPath = '//corporationRolesAtOther/row';
291
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
292
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
293
        return $this;
294
    }
295
    /**
296
     * @param EveApiReadWriteInterface $data
297
     *
298
     * @return self Fluent interface.
299
     * @throws \DomainException
300
     * @throws \InvalidArgumentException
301
     * @throws \UnexpectedValueException
302
     */
303
    protected function preserveToCorporationTitles(EveApiReadWriteInterface $data): self
304
    {
305
        $tableName = 'charCorporationTitles';
306
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
307
        $sql = $this->getCsq()
308
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
309
        $this->getYem()
310
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
311
        $this->getPdo()
312
            ->exec($sql);
313
        $columnDefaults = [
314
            'ownerID' => $ownerID,
315
            'titleID' => null,
316
            'titleName' => ''
317
        ];
318
        $xPath = '//corporationTitles/row';
319
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
320
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
321
        return $this;
322
    }
323
    /**
324
     * @param EveApiReadWriteInterface $data
325
     *
326
     * @return self Fluent interface.
327
     * @throws \DomainException
328
     * @throws \InvalidArgumentException
329
     * @throws \UnexpectedValueException
330
     */
331
    protected function preserveToImplants(EveApiReadWriteInterface $data): self
332
    {
333
        $tableName = 'charImplants';
334
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
335
        $sql = $this->getCsq()
336
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
337
        $this->getYem()
338
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
339
        $this->getPdo()
340
            ->exec($sql);
341
        $columnDefaults = [
342
            'ownerID' => $ownerID,
343
            'typeID' => null,
344
            'typeName' => ''
345
        ];
346
        $xPath = '//implants/row';
347
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
348
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
349
        return $this;
350
    }
351
    /**
352
     * @param EveApiReadWriteInterface $data
353
     *
354
     * @return self Fluent interface.
355
     * @throws \DomainException
356
     * @throws \InvalidArgumentException
357
     * @throws \UnexpectedValueException
358
     */
359
    protected function preserveToJumpCloneImplants(EveApiReadWriteInterface $data): self
360
    {
361
        $tableName = 'charJumpCloneImplants';
362
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
363
        $sql = $this->getCsq()
364
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
365
        $this->getYem()
366
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
367
        $this->getPdo()
368
            ->exec($sql);
369
        $columnDefaults = [
370
            'jumpCloneID' => null,
371
            'ownerID' => $ownerID,
372
            'typeID' => null,
373
            'typeName' => ''
374
        ];
375
        $xPath = '//jumpCloneImplants/row';
376
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
377
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
378
        return $this;
379
    }
380
    /**
381
     * @param EveApiReadWriteInterface $data
382
     *
383
     * @return self Fluent interface.
384
     * @throws \DomainException
385
     * @throws \InvalidArgumentException
386
     * @throws \UnexpectedValueException
387
     */
388
    protected function preserveToJumpClones(EveApiReadWriteInterface $data): self
389
    {
390
        $tableName = 'charJumpClones';
391
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
392
        $sql = $this->getCsq()
393
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
394
        $this->getYem()
395
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
396
        $this->getPdo()
397
            ->exec($sql);
398
        $columnDefaults = [
399
            'cloneName' => '',
400
            'jumpCloneID' => null,
401
            'locationID' => null,
402
            'ownerID' => $ownerID,
403
            'typeID' => null
404
        ];
405
        $xPath = '//jumpClones/row';
406
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
407
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
408
        return $this;
409
    }
410
    /**
411
     * @param EveApiReadWriteInterface $data
412
     *
413
     * @return self Fluent interface.
414
     * @throws \DomainException
415
     * @throws \InvalidArgumentException
416
     * @throws \UnexpectedValueException
417
     */
418
    protected function preserveToSkills(EveApiReadWriteInterface $data): self
419
    {
420
        $tableName = 'charSkills';
421
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
422
        $sql = $this->getCsq()
423
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
424
        $this->getYem()
425
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, 'sql - ' . $sql);
426
        $this->getPdo()
427
            ->exec($sql);
428
        $columnDefaults = [
429
            'level' => null,
430
            'ownerID' => $ownerID,
431
            'published' => null,
432
            'skillpoints' => null,
433
            'typeID' => null
434
        ];
435
        $xPath = '//skills/row';
436
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
437
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
438
        return $this;
439
    }
440
}
441