Completed
Push — master ( 2cff5f...81de03 )
by Michael
03:19
created

IndustryJobsHistory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 2
c 5
b 0
f 3
lcom 1
cbo 5
dl 0
loc 68
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A preserveToIndustryJobsHistory() 0 47 1
1
<?php
2
/**
3
 * Contains class IndustryJobsHistory.
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 IndustryJobsHistory
42
 */
43
class IndustryJobsHistory extends CorpSection
44
{
45
    use PreserverTrait;
46
    /** @noinspection MagicMethodsValidityInspection */
47
    /**
48
     * Constructor
49
     */
50
    public function __construct()
51
    {
52
        $this->mask = 128;
53
        $this->preserveTos = [
54
            'preserveToIndustryJobsHistory'
55
        ];
56
    }
57
    /**
58
     * @param EveApiReadWriteInterface $data
59
     *
60
     * @return self Fluent interface.
61
     * @throws \LogicException
62
     */
63
    protected function preserveToIndustryJobsHistory(EveApiReadWriteInterface $data)
64
    {
65
        // Shared table.
66
        $tableName = 'corpIndustryJobs';
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
            'activityID' => null,
76
            'blueprintID' => null,
77
            'blueprintLocationID' => null,
78
            'blueprintTypeID' => null,
79
            'blueprintTypeName' => '',
80
            'completedCharacterID' => null,
81
            'completedDate' => null,
82
            'cost' => null,
83
            'endDate' => null,
84
            'facilityID' => null,
85
            'installerID' => null,
86
            'installerName' => '',
87
            'jobID' => null,
88
            'licensedRuns' => null,
89
            'outputLocationID' => null,
90
            'ownerID' => $ownerID,
91
            'pauseDate' => null,
92
            'probability' => null,
93
            'productTypeID' => null,
94
            'productTypeName' => '',
95
            'runs' => null,
96
            'solarSystemID' => null,
97
            'solarSystemName' => '',
98
            'startDate' => null,
99
            'stationID' => null,
100
            'status' => null,
101
            'successfulRuns' => null,
102
            'teamID' => null,
103
            'timeInSeconds' => null
104
        ];
105
        $xPath = '//jobs/row';
106
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
107
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
108
        return $this;
109
    }
110
}
111