CustomsOfficeUpdater::addCustomsOffices()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 23
rs 9.0856
c 2
b 1
f 0
cc 2
eloc 19
nc 2
nop 2
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\CorpCustomsOffice;
9
10
/**
11
 * @DI\Service("tarioch.eveapi.corp.CustomsOffices")
12
 */
13
class CustomsOfficeUpdater extends AbstractCorpUpdater
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function update(ApiCall $call, ApiKey $key, Pheal $pheal)
19
    {
20
        $owner = $call->getOwner();
21
        $corpId = $owner->getCorporationId();
22
        $api = $pheal->corpScope->customsOffices();
23
24
        $this->entityManager
25
            ->createQuery('delete from TariochEveapiFetcherBundle:CorpCustomsOffice c where c.ownerId=:ownerId')
26
            ->setParameter('ownerId', $corpId)
27
            ->execute();
28
29
        $this->addCustomsOffices($api->pocos, $corpId);
30
31
        return $api->cached_until;
32
    }
33
34
    private function addCustomsOffices($customOffices, $corpId)
35
    {
36
        foreach ($customOffices as $customOffice) {
37
            $entity = new CorpCustomsOffice();
38
            $entity->setOwnerId($corpId);
39
            $entity->setItemId($customOffice->itemID);
40
            $entity->setSolarSystemId($customOffice->solarSystemID);
41
            $entity->setSolarSystemName($customOffice->solarSystemName);
42
            $entity->setReinforceHour($customOffice->reinforceHour);
43
            $entity->setAllowAlliance(filter_var($customOffice->allowAlliance, FILTER_VALIDATE_BOOLEAN));
44
            $entity->setAllowStandings(filter_var($customOffice->allowStandings, FILTER_VALIDATE_BOOLEAN));
45
            $entity->setStandingLevel($customOffice->standingLevel);
46
            $entity->setTaxRateAlliance($customOffice->taxRateAlliance);
47
            $entity->setTaxRateCorp($customOffice->taxRateCorp);
48
            $entity->setTaxRateStandingHigh($customOffice->taxRateStandingHigh);
49
            $entity->setTaxRateStandingGood($customOffice->taxRateStandingGood);
50
            $entity->setTaxRateStandingNeutral($customOffice->taxRateStandingNeutral);
51
            $entity->setTaxRateStandingBad($customOffice->taxRateStandingBad);
52
            $entity->setTaxRateStandingHorrible($customOffice->taxRateStandingHorrible);
53
54
            $this->entityManager->persist($entity);
55
        }
56
    }
57
}
58