|
1
|
|
|
<?php |
|
2
|
|
|
namespace Tarioch\EveapiFetcherBundle\Component\EveApi\Char; |
|
3
|
|
|
|
|
4
|
|
|
use JMS\DiExtraBundle\Annotation as DI; |
|
5
|
|
|
use Tarioch\EveapiFetcherBundle\Entity\ApiCall; |
|
6
|
|
|
use Pheal\Pheal; |
|
7
|
|
|
use Tarioch\EveapiFetcherBundle\Entity\ApiKey; |
|
8
|
|
|
use Tarioch\EveapiFetcherBundle\Entity\CharPlanetaryColony; |
|
9
|
|
|
use Tarioch\EveapiFetcherBundle\Entity\CharPlanetaryPin; |
|
10
|
|
|
use Tarioch\EveapiFetcherBundle\Entity\CharPlanetaryLink; |
|
11
|
|
|
use Tarioch\EveapiFetcherBundle\Entity\CharPlanetaryRoute; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @DI\Service("tarioch.eveapi.char.PlanetaryColonies") |
|
15
|
|
|
*/ |
|
16
|
|
|
class PlanetaryColonyUpdater extends AbstractCharUpdater |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @inheritdoc |
|
20
|
|
|
*/ |
|
21
|
|
|
public function update(ApiCall $call, ApiKey $key, Pheal $pheal) |
|
22
|
|
|
{ |
|
23
|
|
|
$owner = $call->getOwner(); |
|
24
|
|
|
$charId = $owner->getCharacterId(); |
|
25
|
|
|
|
|
26
|
|
|
$this->entityManager |
|
27
|
|
|
->createQuery('delete from TariochEveapiFetcherBundle:CharPlanetaryColony c where c.ownerId=:ownerId') |
|
28
|
|
|
->setParameter('ownerId', $charId) |
|
29
|
|
|
->execute(); |
|
30
|
|
|
$this->entityManager |
|
31
|
|
|
->createQuery('delete from TariochEveapiFetcherBundle:CharPlanetaryPin c where c.ownerId=:ownerId') |
|
32
|
|
|
->setParameter('ownerId', $charId) |
|
33
|
|
|
->execute(); |
|
34
|
|
|
$this->entityManager |
|
35
|
|
|
->createQuery('delete from TariochEveapiFetcherBundle:CharPlanetaryLink c where c.ownerId=:ownerId') |
|
36
|
|
|
->setParameter('ownerId', $charId) |
|
37
|
|
|
->execute(); |
|
38
|
|
|
$this->entityManager |
|
39
|
|
|
->createQuery('delete from TariochEveapiFetcherBundle:CharPlanetaryRoute c where c.ownerId=:ownerId') |
|
40
|
|
|
->setParameter('ownerId', $charId) |
|
41
|
|
|
->execute(); |
|
42
|
|
|
|
|
43
|
|
|
$api = $pheal->charScope->PlanetaryColonies(array( |
|
44
|
|
|
'characterID' => $charId |
|
45
|
|
|
)); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($api->colonies as $colony) { |
|
48
|
|
|
$planetId = $colony->planetID; |
|
49
|
|
|
|
|
50
|
|
|
$this->addColony($colony, $charId); |
|
51
|
|
|
|
|
52
|
|
|
$api = $pheal->charScope->PlanetaryPins(array( |
|
53
|
|
|
'characterID' => $charId, |
|
54
|
|
|
'planetID' => $planetId |
|
55
|
|
|
)); |
|
56
|
|
|
$this->addPins($api->pins, $planetId, $charId); |
|
57
|
|
|
|
|
58
|
|
|
$api = $pheal->charScope->PlanetaryLinks(array( |
|
59
|
|
|
'characterID' => $charId, |
|
60
|
|
|
'planetID' => $planetId |
|
61
|
|
|
)); |
|
62
|
|
|
$this->addLinks($api->links, $planetId, $charId); |
|
63
|
|
|
|
|
64
|
|
|
$api = $pheal->charScope->PlanetaryRoutes(array( |
|
65
|
|
|
'characterID' => $charId, |
|
66
|
|
|
'planetID' => $planetId |
|
67
|
|
|
)); |
|
68
|
|
|
$this->addRoutes($api->routes, $planetId, $charId); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $api->cached_until; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function addColony($colony, $charId) |
|
75
|
|
|
{ |
|
76
|
|
|
$entity = new CharPlanetaryColony(); |
|
77
|
|
|
$entity->setOwnerId($charId); |
|
78
|
|
|
$entity->setOwnerName($colony->ownerName); |
|
79
|
|
|
$entity->setSolarSystemId($colony->solarSystemID); |
|
80
|
|
|
$entity->setSolarSystemName($colony->solarSystemName); |
|
81
|
|
|
$entity->setPlanetId($colony->planetID); |
|
82
|
|
|
$entity->setPlanetName($colony->planetName); |
|
83
|
|
|
$entity->setPlanetTypeId($colony->planetTypeID); |
|
84
|
|
|
$entity->setPlanetTypeName($colony->planetTypeName); |
|
85
|
|
|
$entity->setLastUpdate(new \DateTime($colony->lastUpdate)); |
|
86
|
|
|
$entity->setUpgradeLevel($colony->upgradeLevel); |
|
87
|
|
|
$entity->setNumberOfPins($colony->numberOfPins); |
|
88
|
|
|
|
|
89
|
|
|
$this->entityManager->persist($entity); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
private function addPins($pins, $planetId, $charId) |
|
93
|
|
|
{ |
|
94
|
|
|
foreach ($pins as $pin) { |
|
95
|
|
|
$entity = new CharPlanetaryPin(); |
|
96
|
|
|
$entity->setOwnerId($charId); |
|
97
|
|
|
$entity->setPlanetId($planetId); |
|
98
|
|
|
$entity->setPinId($pin->pinID); |
|
99
|
|
|
$entity->setTypeId($pin->typeID); |
|
100
|
|
|
$entity->setTypeName($pin->typeName); |
|
101
|
|
|
$entity->setSchematicId($pin->schematicID); |
|
102
|
|
|
$entity->setLastLaunchTime(new \DateTime($pin->lastLaunchTime)); |
|
103
|
|
|
$entity->setCycleTime($pin->cycleTime); |
|
104
|
|
|
$entity->setQuantityPerCycle($pin->quantityPerCycle); |
|
105
|
|
|
$entity->setInstallTime(new \DateTime($pin->installTime)); |
|
106
|
|
|
$entity->setExpiryTime(new \DateTime($pin->expiryTime)); |
|
107
|
|
|
$entity->setContentTypeId($pin->contentTypeID); |
|
108
|
|
|
$entity->setContentTypeName($pin->contentTypeName); |
|
109
|
|
|
$entity->setContentQuantity($pin->contentQuantity); |
|
110
|
|
|
$entity->setLongitude($pin->longitude); |
|
111
|
|
|
$entity->setLatitude($pin->latitude); |
|
112
|
|
|
|
|
113
|
|
|
$this->entityManager->persist($entity); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
private function addLinks($links, $planetId, $charId) |
|
118
|
|
|
{ |
|
119
|
|
|
foreach ($links as $link) { |
|
120
|
|
|
$entity = new CharPlanetaryLink(); |
|
121
|
|
|
$entity->setOwnerId($charId); |
|
122
|
|
|
$entity->setPlanetId($planetId); |
|
123
|
|
|
$entity->setSourcePinId($link->sourcePinID); |
|
124
|
|
|
$entity->setDestinationPinId($link->destinationPinID); |
|
125
|
|
|
$entity->setLinkLevel($link->linkLevel); |
|
126
|
|
|
|
|
127
|
|
|
$this->entityManager->persist($entity); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
private function addRoutes($routes, $planetId, $charId) |
|
132
|
|
|
{ |
|
133
|
|
|
foreach ($routes as $route) { |
|
134
|
|
|
$entity = new CharPlanetaryRoute(); |
|
135
|
|
|
$entity->setOwnerId($charId); |
|
136
|
|
|
$entity->setPlanetId($planetId); |
|
137
|
|
|
$entity->setRouteId($route->routeID); |
|
138
|
|
|
$entity->setSourcePinId($route->sourcePinID); |
|
139
|
|
|
$entity->setDestinationPinId($route->destinationPinID); |
|
140
|
|
|
$entity->setContentTypeId($route->contentTypeID); |
|
141
|
|
|
$entity->setContentTypeName($route->contentTypeName); |
|
142
|
|
|
$entity->setQuantity($route->quantity); |
|
143
|
|
|
$entity->setWaypoint1($route->waypoint1); |
|
144
|
|
|
$entity->setWaypoint2($route->waypoint2); |
|
145
|
|
|
$entity->setWaypoint3($route->waypoint3); |
|
146
|
|
|
$entity->setWaypoint4($route->waypoint4); |
|
147
|
|
|
$entity->setWaypoint5($route->waypoint5); |
|
148
|
|
|
|
|
149
|
|
|
$this->entityManager->persist($entity); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|