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

IndustryJobs::startEveApi()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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