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\CharMailMessage; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @DI\Service("tarioch.eveapi.char.MailMessages") |
12
|
|
|
*/ |
13
|
|
|
class MailMessageUpdater extends AbstractCharUpdater |
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
|
|
|
|
23
|
|
|
$api = $pheal->charScope->MailMessages(array('characterID' => $charId)); |
24
|
|
|
|
25
|
|
|
foreach ($api->messages as $message) { |
26
|
|
|
$messageId = $message->messageID; |
27
|
|
|
|
28
|
|
|
$repo = $this->entityManager->getRepository('TariochEveapiFetcherBundle:CharMailMessage'); |
29
|
|
|
$entity = $repo->findBy(array('messageId' => $messageId, 'ownerId' => $charId)); |
30
|
|
|
if ($entity === null) { |
31
|
|
|
$entity = new CharMailMessage($messageId, $charId); |
32
|
|
|
$this->entityManager->persist($entity); |
33
|
|
|
|
34
|
|
|
$entity->setSenderId($message->senderID); |
35
|
|
|
$entity->setSentDate(new \DateTime($message->sentDate)); |
36
|
|
|
$entity->setTitle($message->title); |
37
|
|
|
$entity->setToCharacterIds($message->toCharacterIDs); |
38
|
|
|
$entity->setToCorpOrAllianceId($message->toCorpOrAllianceID); |
39
|
|
|
$entity->setToListId($message->toListID); |
40
|
|
|
|
41
|
|
|
$this->entityManager->persist($entity); |
42
|
|
|
$this->entityManager->flush($entity); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $api->cached_until; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|