Completed
Pull Request — 2.1 (#1191)
by Rafał
09:16
created

Article::setUpdatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
    /** @var bool */
63
    protected $isPublishedToAppleNews = false;
64
65
    /** @var AppleNewsArticleInterface|null */
66
    protected $appleNewsArticle;
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function setId($id)
72
    {
73
        $this->id = $id;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getPackage(): ?PackageInterface
80
    {
81
        return $this->package;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function setPackage(?PackageInterface $package)
88
    {
89
        $this->package = $package;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function isPublishedFBIA(): bool
96
    {
97
        return $this->isPublishedFBIA;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public function setPublishedFBIA(bool $isPublished)
104
    {
105
        $this->isPublishedFBIA = $isPublished;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function getArticleStatistics(): ?ArticleStatisticsInterface
112
    {
113
        return $this->articleStatistics;
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    public function setArticleStatistics(ArticleStatisticsInterface $articleStatistics): void
120
    {
121
        $articleStatistics->setArticle($this);
122
        $this->articleStatistics = $articleStatistics;
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function getExternalArticle(): ?ExternalArticleInterface
129
    {
130
        return $this->externalArticle;
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function setExternalArticle(ExternalArticleInterface $externalArticle): void
137
    {
138
        $this->externalArticle = $externalArticle;
139
    }
140
141
    public function getPackageExternalData()
142
    {
143
        if (null === $this->getPackage()->getExternalData()) {
144
            return [];
145
        }
146
147
        $data = [];
148
        foreach ($this->getPackage()->getExternalData() as $singleData) {
149
            $data[$singleData->getKey()] = $singleData->getValue();
150
        }
151
152
        return $data;
153
    }
154
155
    public function getCommentsCount(): int
156
    {
157
        if (null === $this->commentsCount) {
158
            return 0;
159
        }
160
161
        return $this->commentsCount;
162
    }
163
164
    public function setCommentsCount(int $commentsCount): void
165
    {
166
        $this->commentsCount = $commentsCount;
167
    }
168
169
    public function getGeoIpPlaces(): array
170
    {
171
        $places = $this->getPlaces();
172
173
        $geoPlaces = [];
174
        foreach ($places as $place) {
175
            $geoPlaces[] = new Place($place['country'] ?? '', $place['state'] ?? '');
176
        }
177
178
        return $geoPlaces;
179
    }
180
181
    public function isPublishedToAppleNews(): bool
182
    {
183
        return $this->isPublishedToAppleNews;
184
    }
185
186
    public function setPublishedToAppleNews(bool $isPublished): void
187
    {
188
        $this->isPublishedToAppleNews = $isPublished;
189
    }
190
191
    public function getAppleNewsArticle(): ?AppleNewsArticleInterface
192
    {
193
        return $this->appleNewsArticle;
194
    }
195
196
    public function setAppleNewsArticle(?AppleNewsArticleInterface $appleNewsArticle): void
197
    {
198
        $this->appleNewsArticle = $appleNewsArticle;
199
    }
200
201
    public function setUpdatedAt(\DateTime $updatedAt)
202
    {
203
        $this->package->setUpdatedAt($updatedAt);
204
205
        parent::setUpdatedAt($updatedAt);
206
    }
207
}
208