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

ContactList::preserveToContactList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 23
rs 9.0856
cc 1
eloc 20
nc 1
nop 1
1
<?php
2
/**
3
 * Contains class ContactList.
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\Corp;
35
36
use Yapeal\Log\Logger;
37
use Yapeal\Sql\PreserverTrait;
38
use Yapeal\Xml\EveApiReadWriteInterface;
39
40
/**
41
 * Class ContactList
42
 */
43
class ContactList extends CorpSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 16;
53
        $this->preserveTos = [
54
            'preserveToAllianceContactLabels',
55
            'preserveToAllianceContactList',
56
            'preserveToContactList',
57
            'preserveToCorporateContactLabels'
58
        ];
59
    }
60
    /**
61
     * @param EveApiReadWriteInterface $data
62
     *
63
     * @return self Fluent interface.
64
     * @throws \LogicException
65
     */
66
    protected function preserveToAllianceContactLabels(EveApiReadWriteInterface $data)
67
    {
68
        $tableName = 'corpAllianceContactLabels';
69
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
70
        $sql = $this->getCsq()
71
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
72
        $this->getYem()
73
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
74
        $this->getPdo()
75
            ->exec($sql);
76
        $columnDefaults = [
77
            'labelID' => null,
78
            'name' => '',
79
            'ownerID' => $ownerID
80
        ];
81
        $xPath = '//allianceContactLabels/row';
82
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
83
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
84
        return $this;
85
    }
86
    /**
87
     * @param EveApiReadWriteInterface $data
88
     *
89
     * @return self Fluent interface.
90
     * @throws \LogicException
91
     */
92
    protected function preserveToAllianceContactList(EveApiReadWriteInterface $data)
93
    {
94
        $tableName = 'corpAllianceContactList';
95
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
96
        $sql = $this->getCsq()
97
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
98
        $this->getYem()
99
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
100
        $this->getPdo()
101
            ->exec($sql);
102
        $columnDefaults = [
103
            'contactID' => null,
104
            'contactName' => '',
105
            'contactTypeID' => null,
106
            'labelMask' => null,
107
            'ownerID' => $ownerID,
108
            'standing' => null
109
        ];
110
        $xPath = '//allianceContactList/row';
111
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
112
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
113
        return $this;
114
    }
115
    /**
116
     * @param EveApiReadWriteInterface $data
117
     *
118
     * @return self Fluent interface.
119
     * @throws \LogicException
120
     */
121
    protected function preserveToContactList(EveApiReadWriteInterface $data)
122
    {
123
        $tableName = 'corpContactList';
124
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
125
        $sql = $this->getCsq()
126
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
127
        $this->getYem()
128
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
129
        $this->getPdo()
130
            ->exec($sql);
131
        $columnDefaults = [
132
            'contactID' => null,
133
            'contactName' => '',
134
            'contactTypeID' => null,
135
            'labelMask' => null,
136
            'ownerID' => $ownerID,
137
            'standing' => null
138
        ];
139
        $xPath = '//corporateContactList/row';
140
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
141
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
142
        return $this;
143
    }
144
    /**
145
     * @param EveApiReadWriteInterface $data
146
     *
147
     * @return self Fluent interface.
148
     * @throws \LogicException
149
     */
150
    protected function preserveToCorporateContactLabels(EveApiReadWriteInterface $data)
151
    {
152
        $tableName = 'corpCorporateContactLabels';
153
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
154
        $sql = $this->getCsq()
155
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
156
        $this->getYem()
157
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
158
        $this->getPdo()
159
            ->exec($sql);
160
        $columnDefaults = [
161
            'labelID' => null,
162
            'name' => '',
163
            'ownerID' => $ownerID
164
        ];
165
        $xPath = '//corporateContactLabels/row';
166
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
167
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
168
        return $this;
169
    }
170
}
171