Completed
Pull Request — 1.4 (#683)
by Paweł
08:30
created

Article::isTimestampableCanceled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2016 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 2016 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\Model;
18
19
use Behat\Transliterator\Transliterator;
20
use Doctrine\Common\Collections\ArrayCollection;
21
use Doctrine\Common\Collections\Collection;
22
use SWP\Component\Bridge\Model\AuthorsAwareTrait;
23
use SWP\Component\Common\Model\SoftDeletableTrait;
24
use SWP\Component\Common\Model\TimestampableTrait;
25
use SWP\Component\Common\Model\TranslatableTrait;
26
27
/**
28
 * Class Article.
29
 */
30
class Article implements ArticleInterface
31
{
32
    use TranslatableTrait, SoftDeletableTrait, TimestampableTrait, AuthorsAwareTrait, KeywordsAwareTrait;
33
34
    /**
35
     * @var mixed
36
     */
37
    protected $id;
38
39
    /**
40
     * @var string
41
     */
42
    protected $title;
43
44
    /**
45
     * @var string
46
     */
47
    protected $body;
48
49
    /**
50
     * @var string
51
     */
52
    protected $slug;
53
54
    /**
55
     * @var \DateTime
56
     */
57
    protected $publishedAt;
58
59
    /**
60
     * @var string
61
     */
62
    protected $status = ArticleInterface::STATUS_NEW;
63
64
    /**
65
     * @var RouteInterface
66
     */
67
    protected $route;
68
69
    /**
70
     * @var string
71
     */
72
    protected $templateName;
73
74
    /**
75
     * @var \DateTime
76
     */
77
    protected $publishStartDate;
78
79
    /**
80
     * @var \DateTime
81
     */
82
    protected $publishEndDate;
83
84
    /**
85
     * @var bool
86
     */
87
    protected $isPublishable;
88
89
    /**
90
     * @var array
91
     */
92
    protected $metadata = [];
93
94
    /**
95
     * @var Collection
96
     */
97
    protected $media;
98
99
    /**
100
     * @var ArticleMediaInterface
101
     */
102
    protected $featureMedia;
103
104
    /**
105
     * @var string
106
     */
107
    protected $lead;
108
109
    /**
110
     * @var string
111
     */
112
    protected $code;
113
114
    /**
115
     * @var Collection|ArticleSourceInterface[]
116
     */
117
    protected $sources;
118
119
    /**
120
     * @var array|null
121
     */
122
    protected $extra;
123
124
    /**
125
     * @var Collection|SlideshowInterface[]
126
     */
127
    protected $slideshows;
128
129
    private $isTimestampableCanceled = false;
130
131
    public function __construct()
132
    {
133
        $this->setCreatedAt(new \DateTime());
134
        $this->setPublishable(false);
135
        $this->setMedia(new ArrayCollection());
136
        $this->sources = new ArrayCollection();
137
        $this->authors = new ArrayCollection();
138
        $this->keywords = new ArrayCollection();
139
        $this->slideshows = new ArrayCollection();
140
    }
141
142
    public function setPublishStartDate(\DateTime $startDate = null)
143
    {
144
        $this->publishStartDate = $startDate;
145
    }
146
147
    public function getPublishStartDate()
148
    {
149
        return $this->publishStartDate;
150
    }
151
152
    public function setPublishEndDate(\DateTime $endDate = null)
153
    {
154
        $this->publishEndDate = $endDate;
155
    }
156
157
    public function getPublishEndDate()
158
    {
159
        return $this->publishEndDate;
160
    }
161
162
    public function isPublishable()
163
    {
164
        return $this->isPublishable;
165
    }
166
167
    public function setPublishable($boolean)
168
    {
169
        $this->isPublishable = $boolean;
170
    }
171
172
    public function isPublished()
173
    {
174
        return ArticleInterface::STATUS_PUBLISHED === $this->getStatus();
175
    }
176
177
    public function setRoute(RouteInterface $route = null)
178
    {
179
        $this->route = $route;
180
    }
181
182
    public function getRoute()
183
    {
184
        return $this->route;
185
    }
186
187
    public function getId()
188
    {
189
        return $this->id;
190
    }
191
192
    public function getBody()
193
    {
194
        return $this->body;
195
    }
196
197
    public function setBody($body)
198
    {
199
        $this->body = $body;
200
    }
201
202
    public function getMedia()
203
    {
204
        return $this->media;
205
    }
206
207
    public function setMedia(Collection $media)
208
    {
209
        $this->media = $media;
210
    }
211
212
    public function getTitle()
213
    {
214
        return $this->title;
215
    }
216
217
    public function setTitle($title)
218
    {
219
        $this->title = $title;
220
221
        if (null !== $this->slug) {
222
            $this->setSlug($this->slug);
223
224
            return;
225
        }
226
227
        $this->setSlug($this->title);
228
    }
229
230
    public function getSlug()
231
    {
232
        return $this->slug;
233
    }
234
235
    public function setSlug($slug)
236
    {
237
        $urlizedSlug = Transliterator::urlize($slug);
238
239
        if ('' === $urlizedSlug) {
240
            $slug = str_replace('\'', '-', $slug);
241
            $this->slug = Transliterator::transliterate($slug);
242
243
            return;
244
        }
245
246
        $this->slug = $urlizedSlug;
247
    }
248
249
    public function getPublishedAt()
250
    {
251
        return $this->publishedAt;
252
    }
253
254
    public function setPublishedAt(\DateTime $publishedAt)
255
    {
256
        $this->publishedAt = $publishedAt;
257
    }
258
259
    public function getStatus()
260
    {
261
        return $this->status;
262
    }
263
264
    public function setStatus($status)
265
    {
266
        $this->status = $status;
267
    }
268
269
    public function getTemplateName()
270
    {
271
        return $this->templateName;
272
    }
273
274
    public function setTemplateName($templateName)
275
    {
276
        $this->templateName = $templateName;
277
    }
278
279
    public function getMetadata()
280
    {
281
        return $this->metadata;
282
    }
283
284
    public function getMetadataByKey(string $key)
285
    {
286
        $metadata = $this->getMetadata();
287
288
        if (isset($metadata[$key])) {
289
            return $metadata[$key];
290
        }
291
    }
292
293
    public function setMetadata(array $metadata)
294
    {
295
        $this->metadata = $metadata;
296
    }
297
298
    public function getSubjectType()
299
    {
300
        return 'article';
301
    }
302
303
    public function getLead()
304
    {
305
        return $this->lead;
306
    }
307
308
    public function setLead($lead)
309
    {
310
        $this->lead = $lead;
311
    }
312
313
    public function getFeatureMedia()
314
    {
315
        return $this->featureMedia;
316
    }
317
318
    public function setFeatureMedia(ArticleMediaInterface $featureMedia = null)
319
    {
320
        $this->featureMedia = $featureMedia;
321
    }
322
323
    public function getCode(): string
324
    {
325
        return $this->code;
326
    }
327
328
    public function setCode(string $code)
329
    {
330
        $this->code = $code;
331
    }
332
333
    public function addSourceReference(ArticleSourceReferenceInterface $source)
334
    {
335
        if (!$this->hasSourceReference($source)) {
336
            $this->sources->add($source);
337
        }
338
    }
339
340
    public function removeSourceReference(ArticleSourceReferenceInterface $source)
341
    {
342
        $this->sources->removeElement($source);
343
    }
344
345
    public function hasSourceReference(ArticleSourceReferenceInterface $source): bool
346
    {
347
        return $this->sources->contains($source);
348
    }
349
350
    public function getSources(): Collection
351
    {
352
        if (0 < $this->sources->count()) {
353
            $sources = new ArrayCollection();
354
            /** @var ArticleSourceReferenceInterface $source */
355
            foreach ($this->sources as $source) {
356
                $sources->add($source->getArticleSource());
357
            }
358
359
            return $sources;
360
        }
361
362
        return $this->sources;
363
    }
364
365
    public function getExtra(): ?array
366
    {
367
        return $this->extra;
368
    }
369
370
    public function setExtra(?array $extra): void
371
    {
372
        $this->extra = $extra;
373
    }
374
375
    public function getSlideshows(): Collection
376
    {
377
        return $this->slideshows;
378
    }
379
380
    public function hasSlideshow(SlideshowInterface $slideshow): bool
381
    {
382
        return $this->slideshows->contains($slideshow);
383
    }
384
385
    public function addSlideshow(SlideshowInterface $slideshow): void
386
    {
387
        if (!$this->hasSlideshow($slideshow)) {
388
            $slideshow->setArticle($this);
389
            $this->slideshows->add($slideshow);
390
        }
391
    }
392
393
    public function removeSlideshow(SlideshowInterface $slideshow): void
394
    {
395
        if ($this->hasSlideshow($slideshow)) {
396
            $slideshow->setArticle(null);
397
            $this->slideshows->removeElement($slideshow);
398
        }
399
    }
400
401
    public function cancelTimestampable(bool $cancel = true): void
402
    {
403
        $this->isTimestampableCanceled = $cancel;
404
    }
405
406
    public function isTimestampableCanceled(): bool
407
    {
408
        return $this->isTimestampableCanceled;
409
    }
410
}
411