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

Contracts::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * Contains class Contracts.
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 Contracts
42
 */
43
class Contracts extends CharSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 67108864;
53
        $this->preserveTos = [
54
            'preserveToContracts'
55
        ];
56
    }
57
    /**
58
     * @param EveApiReadWriteInterface $data
59
     *
60
     * @return self Fluent interface.
61
     * @throws \LogicException
62
     */
63
    protected function preserveToContracts(EveApiReadWriteInterface $data)
64
    {
65
        $tableName = 'charContracts';
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
            'acceptorID' => null,
75
            'assigneeID' => null,
76
            'availability' => null,
77
            'buyout' => null,
78
            'collateral' => null,
79
            'contractID' => null,
80
            'dateAccepted' => '1970-01-01 00:00:01',
81
            'dateCompleted' => '1970-01-01 00:00:01',
82
            'dateExpired' => '1970-01-01 00:00:01',
83
            'dateIssued' => '1970-01-01 00:00:01',
84
            'endStationID' => null,
85
            'forCorp' => null,
86
            'issuerCorpID' => null,
87
            'issuerID' => null,
88
            'numDays' => null,
89
            'ownerID' => $ownerID,
90
            'price' => null,
91
            'reward' => null,
92
            'startStationID' => null,
93
            'status' => null,
94
            'title' => null,
95
            'type' => null,
96
            'volume' => null
97
        ];
98
        $xPath = '//contractList/row';
99
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
100
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
101
        return $this;
102
    }
103
}
104