|
1
|
|
|
<?php |
|
2
|
|
|
namespace Tarioch\EveapiFetcherBundle\Component\EveApi\Corp; |
|
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\CorpWalletTransaction; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @DI\Service("tarioch.eveapi.corp.WalletTransactions") |
|
12
|
|
|
*/ |
|
13
|
|
|
class WalletTransactionUpdater extends AbstractCorpUpdater |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @inheritdoc |
|
17
|
|
|
*/ |
|
18
|
|
|
public function update(ApiCall $call, ApiKey $key, Pheal $pheal) |
|
19
|
|
|
{ |
|
20
|
|
|
$owner = $call->getOwner(); |
|
21
|
|
|
$charId = $owner->getCharacterId(); |
|
22
|
|
|
$corpId = $owner->getCorporationId(); |
|
23
|
|
|
|
|
24
|
|
|
$accountRepo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:CorpAccountBalance'); |
|
25
|
|
|
$accounts = $accountRepo->findByOwnerId($corpId); |
|
26
|
|
|
|
|
27
|
|
|
$cached = 'now'; |
|
28
|
|
|
foreach ($accounts as $account) { |
|
29
|
|
|
$accountKey = $account->getAccountKey(); |
|
30
|
|
|
|
|
31
|
|
|
$api = $pheal->corpScope->WalletTransactions(array( |
|
32
|
|
|
'characterID' => $charId, |
|
33
|
|
|
'rowCount' => 2560, |
|
34
|
|
|
'accountKey' => $accountKey |
|
35
|
|
|
)); |
|
36
|
|
|
$cached = $api->cached_until; |
|
37
|
|
|
|
|
38
|
|
|
$repo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:CorpWalletTransaction'); |
|
39
|
|
|
foreach ($api->transactions as $transaction) { |
|
40
|
|
|
$transId = $transaction->transactionID; |
|
41
|
|
|
|
|
42
|
|
|
$criteria = array('transactionId' => $transId, 'ownerId' => $corpId, 'accountKey' => $accountKey); |
|
43
|
|
|
$entity = $repo->findOneBy($criteria); |
|
44
|
|
|
if ($entity === null) { |
|
45
|
|
|
$entity = new CorpWalletTransaction($transId, $corpId, $accountKey); |
|
46
|
|
|
$this->entityManager->persist($entity); |
|
47
|
|
|
|
|
48
|
|
|
$entity->setJournalTransactionId($transaction->journalTransactionID); |
|
49
|
|
|
$entity->setTransactionDateTime(new \DateTime($transaction->transactionDateTime)); |
|
50
|
|
|
$entity->setQuantity($transaction->quantity); |
|
51
|
|
|
$entity->setTypeName($transaction->typeName); |
|
52
|
|
|
$entity->setTypeId($transaction->typeID); |
|
53
|
|
|
$entity->setPrice($transaction->price); |
|
54
|
|
|
$entity->setClientId($transaction->clientID); |
|
55
|
|
|
$entity->setClientName($transaction->clientName); |
|
56
|
|
|
$entity->setClientTypeId($transaction->clientTypeID); |
|
57
|
|
|
$entity->setStationId($transaction->stationID); |
|
58
|
|
|
$entity->setStationName($transaction->stationName); |
|
59
|
|
|
$entity->setTransactionType($transaction->transactionType); |
|
60
|
|
|
$entity->setTransactionFor($transaction->transactionFor); |
|
61
|
|
|
$entity->setCharacterId($transaction->characterID); |
|
62
|
|
|
$entity->setCharacterName($transaction->characterName); |
|
63
|
|
|
|
|
64
|
|
|
$this->entityManager->flush($entity); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $cached; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|