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

IndustryJobs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 4
c 5
b 0
f 3
lcom 2
cbo 6
dl 0
loc 89
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A startEveApi() 0 11 2
B preserveToIndustryJobs() 0 46 1
1
<?php
2
/**
3
 * Contains class IndustryJobs.
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\Event\EveApiEventInterface;
37
use Yapeal\Event\MediatorInterface;
38
use Yapeal\Log\Logger;
39
use Yapeal\Sql\PreserverTrait;
40
use Yapeal\Xml\EveApiReadWriteInterface;
41
42
/**
43
 * Class IndustryJobs
44
 */
45
class IndustryJobs extends CorpSection
46
{
47
    use PreserverTrait;
48
    /** @noinspection MagicMethodsValidityInspection */
49
    /**
50
     * Constructor
51
     */
52
    public function __construct()
53
    {
54
        $this->mask = 128;
55
        $this->preserveTos = [
56
            'preserveToIndustryJobs'
57
        ];
58
    }
59
    /**
60
     * @param EveApiEventInterface $event
61
     * @param string               $eventName
62
     * @param MediatorInterface    $yem
63
     *
64
     * @return EveApiEventInterface
65
     * @throws \DomainException
66
     * @throws \InvalidArgumentException
67
     * @throws \LogicException
68
     * @throws \Yapeal\Exception\YapealDatabaseException
69
     */
70
    public function startEveApi(EveApiEventInterface $event, $eventName, MediatorInterface $yem)
71
    {
72
        if (!$this->hasYem()) {
73
            $this->setYem($yem);
74
        }
75
        $data = $event->getData();
76
        $data->setEveApiName($data->getEveApiName() . 'History');
77
        // Insure history has already been updated first so current data overwrites old data.
78
        $this->emitEvents($data, 'start');
79
        return parent::startEveApi($event, $eventName, $yem);
80
    }
81
    /**
82
     * @param EveApiReadWriteInterface $data
83
     *
84
     * @return self Fluent interface.
85
     * @throws \LogicException
86
     */
87
    protected function preserveToIndustryJobs(EveApiReadWriteInterface $data)
88
    {
89
        $tableName = 'corpIndustryJobs';
90
        $ownerID = $this->extractOwnerID($data->getEveApiArguments());
91
        $sql = $this->getCsq()
92
            ->getDeleteFromTableWithOwnerID($tableName, $ownerID);
93
        $this->getYem()
94
            ->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql);
95
        $this->getPdo()
96
            ->exec($sql);
97
        $columnDefaults = [
98
            'activityID' => null,
99
            'blueprintID' => null,
100
            'blueprintLocationID' => null,
101
            'blueprintTypeID' => null,
102
            'blueprintTypeName' => '',
103
            'completedCharacterID' => null,
104
            'completedDate' => null,
105
            'cost' => null,
106
            'endDate' => null,
107
            'facilityID' => null,
108
            'installerID' => null,
109
            'installerName' => '',
110
            'jobID' => null,
111
            'licensedRuns' => null,
112
            'outputLocationID' => null,
113
            'ownerID' => $ownerID,
114
            'pauseDate' => null,
115
            'probability' => null,
116
            'productTypeID' => null,
117
            'productTypeName' => '',
118
            'runs' => null,
119
            'solarSystemID' => null,
120
            'solarSystemName' => '',
121
            'startDate' => null,
122
            'stationID' => null,
123
            'status' => null,
124
            'successfulRuns' => null,
125
            'teamID' => null,
126
            'timeInSeconds' => '1970-01-01 00:00:01'
127
        ];
128
        $xPath = '//jobs/row';
129
        $elements = (new \SimpleXMLElement($data->getEveApiXml()))->xpath($xPath);
130
        $this->attributePreserveData($elements, $columnDefaults, $tableName);
131
        return $this;
132
    }
133
}
134