Completed
Push — master ( df4948...3b59f8 )
by Michael
02:51
created

SkillInTraining::preserveToSkillInTraining()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 25
rs 8.8571
cc 1
eloc 22
nc 1
nop 1
1
<?php
2
/**
3
 * Contains class SkillInTraining.
4
 *
5
 * PHP version 5.4
6
 *
7
 * LICENSE:
8
 * This file is part of Yet Another Php Eve Api Library also know as Yapeal
9
 * which can be used to access the Eve Online API data and place it into a
10
 * database.
11
 * Copyright (C) 2016 Michael Cummings
12
 *
13
 * This program is free software: you can redistribute it and/or modify it
14
 * under the terms of the GNU Lesser General Public License as published by the
15
 * Free Software Foundation, either version 3 of the License, or (at your
16
 * option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21
 * for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public License
24
 * along with this program. If not, see
25
 * <http://www.gnu.org/licenses/>.
26
 *
27
 * You should be able to find a copy of this license in the LICENSE.md file. A
28
 * copy of the GNU GPL should also be available in the GNU-GPL.md file.
29
 *
30
 * @copyright 2016 Michael Cummings
31
 * @license   http://www.gnu.org/copyleft/lesser.html GNU LGPL
32
 * @author    Michael Cummings <[email protected]>
33
 */
34
namespace Yapeal\EveApi\Char;
35
36
use Yapeal\Log\Logger;
37
use Yapeal\Sql\PreserverTrait;
38
use Yapeal\Xml\EveApiReadWriteInterface;
39
40
/**
41
 * Class SkillInTraining
42
 */
43
class SkillInTraining extends CharSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 131072;
53
        $this->preserveTos = [
54
            'preserveToSkillInTraining'
55
        ];
56
    }
57
    /**
58
     * @param EveApiReadWriteInterface $data
59
     *
60
     * @return self Fluent interface.
61
     * @throws \LogicException
62
     */
63
    protected function preserveToSkillInTraining(EveApiReadWriteInterface $data)
64
    {
65
        $tableName = 'charSkillInTraining';
66
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
67
        $sql = $this->getCsq()
68
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
69
        $this->getYem()
70
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
71
        $this->getPdo()
72
            ->exec($sql);
73
        $columnDefaults = [
74
            'ownerID' => $ownerID,
75
            'skillInTraining' => null,
76
            'trainingDestinationSP' => null,
77
            'trainingEndTime' => '1970-01-01 00:00:01',
78
            'trainingStartSP' => null,
79
            'trainingStartTime' => '1970-01-01 00:00:01',
80
            'trainingToLevel' => null,
81
            'trainingTypeID' => null
82
        ];
83
        $xPath = '//result/child::*[not(*|@*|self::dataTime)]';
84
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
85
        $this->valuesPreserveData($elements, $columnDefaults, $tableName);
86
        return $this;
87
    }
88
}
89