MailingListUpdater::update()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 20
rs 9.4285
c 2
b 0
f 1
cc 2
eloc 13
nc 2
nop 3
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\CharMailingList;
9
10
/**
11
 * @DI\Service("tarioch.eveapi.char.MailingLists")
12
 */
13
class MailingListUpdater extends AbstractCharUpdater
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function update(ApiCall $call, ApiKey $key, Pheal $pheal)
19
    {
20
        $charId = $call->getOwner()->getCharacterId();
21
22
        $query = 'delete from TariochEveapiFetcherBundle:CharMailingList c where c.ownerId=:ownerId';
23
        $this->entityManager
24
            ->createQuery($query)
25
            ->setParameter('ownerId', $charId)
26
            ->execute();
27
28
        $api = $pheal->charScope->MailingLists(array('characterID' => $charId));
29
30
        foreach ($api->mailingLists as $listApi) {
31
            $entity = new CharMailingList($charId, $listApi->listID);
32
            $entity->setDisplayName($listApi->displayName);
33
            $this->entityManager->persist($entity);
34
        }
35
36
        return $api->cached_until;
37
    }
38
}
39