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

WalletTransactions::preserveToWalletTransactions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 3
Metric Value
c 6
b 0
f 3
dl 0
loc 32
rs 8.8571
cc 1
eloc 29
nc 1
nop 1
1
<?php
2
/**
3
 * Contains class WalletTransactions.
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 WalletTransactions
42
 */
43
class WalletTransactions extends CharSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 4194304;
53
        $this->preserveTos = [
54
            'preserveToWalletTransactions'
55
        ];
56
    }
57
    /**
58
     * @param EveApiReadWriteInterface $data
59
     *
60
     * @return self Fluent interface.
61
     * @throws \LogicException
62
     */
63
    protected function preserveToWalletTransactions(EveApiReadWriteInterface $data)
64
    {
65
        $tableName = 'charWalletTransactions';
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
            'clientID' => null,
75
            'clientName' => '',
76
            'clientTypeID' => null,
77
            'journalTransactionID' => null,
78
            'ownerID' => $ownerID,
79
            'price' => null,
80
            'quantity' => null,
81
            'stationID' => null,
82
            'stationName' => '',
83
            'transactionDateTime' => '1970-01-01 00:00:01',
84
            'transactionFor' => null,
85
            'transactionID' => null,
86
            'transactionType' => null,
87
            'typeID' => null,
88
            'typeName' => ''
89
        ];
90
        $xPath = '//transactions/row';
91
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
92
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
93
        return $this;
94
    }
95
}
96