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

Medals::preserveToOtherCorporations()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 26
rs 8.8571
cc 1
eloc 23
nc 1
nop 1
1
<?php
2
/**
3
 * Contains class Medals.
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 Medals
42
 */
43
class Medals extends CharSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 8192;
53
        $this->preserveTos = [
54
            'preserveToMedals',
55
            'preserveToOtherCorporations'
56
        ];
57
    }
58
    /**
59
     * @param EveApiReadWriteInterface $data
60
     *
61
     * @return self Fluent interface.
62
     * @throws \LogicException
63
     */
64
    protected function preserveToMedals(EveApiReadWriteInterface $data)
65
    {
66
        $tableName = 'charMedals';
67
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
68
        $sql = $this->getCsq()
69
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
70
        $this->getYem()
71
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
72
        $this->getPdo()
73
            ->exec($sql);
74
        $columnDefaults = [
75
            'issued' => null,
76
            'issuerID' => null,
77
            'medalID' => null,
78
            'ownerID' => $ownerID,
79
            'reason' => null,
80
            'status' => null
81
        ];
82
        $xPath = '//currentCorporation/row';
83
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
84
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
85
        return $this;
86
    }
87
    /**
88
     * @param EveApiReadWriteInterface $data
89
     *
90
     * @return self Fluent interface.
91
     * @throws \LogicException
92
     */
93
    protected function preserveToOtherCorporations(EveApiReadWriteInterface $data)
94
    {
95
        $tableName = 'charOtherCorporations';
96
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
97
        $sql = $this->getCsq()
98
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
99
        $this->getYem()
100
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
101
        $this->getPdo()
102
            ->exec($sql);
103
        $columnDefaults = [
104
            'corporationID' => null,
105
            'description' => '',
106
            'issued' => null,
107
            'issuerID' => null,
108
            'medalID' => null,
109
            'ownerID' => $ownerID,
110
            'reason' => null,
111
            'status' => null,
112
            'title' => null
113
        ];
114
        $xPath = '//otherCorporations/row';
115
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
116
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
117
        return $this;
118
    }
119
}
120