Completed
Push — master ( 1cf9f7...7f0cbd )
by Rafał
08:07
created

Article::getGeoIpPlaces()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\Model;
18
19
use SWP\Bundle\AnalyticsBundle\Model\ContentListsAwareTrait;
20
use SWP\Bundle\ContentBundle\Model\Article as BaseArticle;
21
use SWP\Component\GeoIP\Model\GeoIpPlaceInterface;
22
use SWP\Component\GeoIP\Model\Place;
23
use SWP\Component\MultiTenancy\Model\OrganizationAwareTrait;
24
use SWP\Component\MultiTenancy\Model\TenantAwareTrait;
25
use SWP\Component\Paywall\Model\PaywallSecuredTrait;
26
27
class Article extends BaseArticle implements ArticleInterface, GeoIpPlaceInterface
28
{
29
    use TenantAwareTrait;
30
    use OrganizationAwareTrait;
31
    use PaywallSecuredTrait;
32
    use ContentListsAwareTrait;
33
34
    /**
35
     * @var PackageInterface
36
     */
37
    protected $package;
38
39
    /**
40
     * @var bool
41
     */
42
    protected $isPublishedFBIA = false;
43
44
    /**
45
     * @var ArticleStatisticsInterface
46
     */
47
    protected $articleStatistics;
48
49
    /**
50
     * @var ExternalArticleInterface
51
     */
52
    protected $externalArticle;
53
54
    /**
55
     * @var int
56
     */
57
    protected $commentsCount = 0;
58
59
    /** @var Place */
60
    protected $geoIpPlace;
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function setId($id)
66
    {
67
        $this->id = $id;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getPackage(): ?PackageInterface
74
    {
75
        return $this->package;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function setPackage(?PackageInterface $package)
82
    {
83
        $this->package = $package;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function isPublishedFBIA(): bool
90
    {
91
        return $this->isPublishedFBIA;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function setPublishedFBIA(bool $isPublished)
98
    {
99
        $this->isPublishedFBIA = $isPublished;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getArticleStatistics(): ?ArticleStatisticsInterface
106
    {
107
        return $this->articleStatistics;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function setArticleStatistics(ArticleStatisticsInterface $articleStatistics): void
114
    {
115
        $articleStatistics->setArticle($this);
116
        $this->articleStatistics = $articleStatistics;
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function getExternalArticle(): ?ExternalArticleInterface
123
    {
124
        return $this->externalArticle;
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function setExternalArticle(ExternalArticleInterface $externalArticle): void
131
    {
132
        $this->externalArticle = $externalArticle;
133
    }
134
135
    public function getPackageExternalData()
136
    {
137
        if (null === $this->getPackage()->getExternalData()) {
138
            return [];
139
        }
140
141
        $data = [];
142
        foreach ($this->getPackage()->getExternalData() as $singleData) {
143
            $data[$singleData->getKey()] = $singleData->getValue();
144
        }
145
146
        return $data;
147
    }
148
149
    public function getCommentsCount(): int
150
    {
151
        if (null === $this->commentsCount) {
152
            return 0;
153
        }
154
155
        return $this->commentsCount;
156
    }
157
158
    public function setCommentsCount(int $commentsCount): void
159
    {
160
        $this->commentsCount = $commentsCount;
161
    }
162
163
    public function getGeoIpPlaces(): array
164
    {
165
        $places = $this->getPlaces();
166
167
        $geoPlaces = [];
168
        foreach ($places as $place) {
169
            $geoPlaces[] = new Place($place['country'] ?? '', $place['state'] ?? '');
170
        }
171
172
        return $geoPlaces;
173
    }
174
}
175