|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Superdesk Web Publisher Content List Component. |
|
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\Component\ContentList\Model; |
|
18
|
|
|
|
|
19
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
20
|
|
|
use Doctrine\Common\Collections\Collection; |
|
21
|
|
|
use SWP\Component\Common\Model\EnableableTrait; |
|
22
|
|
|
use SWP\Component\Common\Model\SoftDeletableTrait; |
|
23
|
|
|
use SWP\Component\Common\Model\TimestampableTrait; |
|
24
|
|
|
|
|
25
|
|
|
class ContentList implements ContentListInterface |
|
26
|
|
|
{ |
|
27
|
|
|
use TimestampableTrait, SoftDeletableTrait, EnableableTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var mixed |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $id; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $name; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string|null |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $description; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var string |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $type; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var int |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $cacheLifeTime; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var int |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $limit; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var Collection|ContentListItemInterface[] |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $items; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var array |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $filters = []; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* ContentList constructor. |
|
71
|
|
|
*/ |
|
72
|
17 |
|
public function __construct() |
|
73
|
|
|
{ |
|
74
|
17 |
|
$this->createdAt = new \DateTime(); |
|
75
|
17 |
|
$this->items = new ArrayCollection(); |
|
76
|
17 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
14 |
|
public function getId() |
|
82
|
|
|
{ |
|
83
|
14 |
|
return $this->id; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritdoc} |
|
88
|
|
|
*/ |
|
89
|
12 |
|
public function getName() |
|
90
|
|
|
{ |
|
91
|
12 |
|
return $this->name; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* {@inheritdoc} |
|
96
|
|
|
*/ |
|
97
|
17 |
|
public function setName(string $name) |
|
98
|
|
|
{ |
|
99
|
17 |
|
$this->name = $name; |
|
100
|
17 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* {@inheritdoc} |
|
104
|
|
|
*/ |
|
105
|
12 |
|
public function getDescription() |
|
106
|
|
|
{ |
|
107
|
12 |
|
return $this->description; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* {@inheritdoc} |
|
112
|
|
|
*/ |
|
113
|
13 |
|
public function setDescription(string $description = null) |
|
114
|
|
|
{ |
|
115
|
13 |
|
$this->description = $description; |
|
116
|
13 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* {@inheritdoc} |
|
120
|
|
|
*/ |
|
121
|
12 |
|
public function getType() |
|
122
|
|
|
{ |
|
123
|
12 |
|
return $this->type; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* {@inheritdoc} |
|
128
|
|
|
*/ |
|
129
|
16 |
|
public function setType(string $type) |
|
130
|
|
|
{ |
|
131
|
16 |
|
$this->type = $type; |
|
132
|
16 |
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* {@inheritdoc} |
|
136
|
|
|
*/ |
|
137
|
12 |
|
public function getCacheLifeTime() |
|
138
|
|
|
{ |
|
139
|
12 |
|
return $this->cacheLifeTime; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* {@inheritdoc} |
|
144
|
|
|
*/ |
|
145
|
13 |
|
public function setCacheLifeTime(int $cacheLifeTime = 0) |
|
146
|
|
|
{ |
|
147
|
13 |
|
$this->cacheLifeTime = $cacheLifeTime; |
|
148
|
13 |
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* {@inheritdoc} |
|
152
|
|
|
*/ |
|
153
|
12 |
|
public function getLimit() |
|
154
|
|
|
{ |
|
155
|
12 |
|
return $this->limit; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* {@inheritdoc} |
|
160
|
|
|
*/ |
|
161
|
13 |
|
public function setLimit(int $limit = 0) |
|
162
|
|
|
{ |
|
163
|
13 |
|
$this->limit = $limit; |
|
164
|
13 |
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* {@inheritdoc} |
|
168
|
|
|
*/ |
|
169
|
2 |
|
public function getItems() |
|
170
|
|
|
{ |
|
171
|
2 |
|
return $this->items; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* {@inheritdoc} |
|
176
|
|
|
*/ |
|
177
|
|
|
public function setItems($items) |
|
178
|
|
|
{ |
|
179
|
|
|
$this->items = $items; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* {@inheritdoc} |
|
184
|
|
|
*/ |
|
185
|
2 |
|
public function addItem(ContentListItemInterface $item) |
|
186
|
|
|
{ |
|
187
|
2 |
|
if (!$this->items->contains($item)) { |
|
188
|
2 |
|
$item->setContentList($this); |
|
189
|
2 |
|
$this->items->add($item); |
|
190
|
|
|
} |
|
191
|
2 |
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* {@inheritdoc} |
|
195
|
|
|
*/ |
|
196
|
|
|
public function removeItem(ContentListItemInterface $item) |
|
197
|
|
|
{ |
|
198
|
|
|
if ($this->items->contains($item)) { |
|
199
|
|
|
$this->items->removeElement($item); |
|
200
|
|
|
$item->setContentList(null); |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* {@inheritdoc} |
|
206
|
|
|
*/ |
|
207
|
12 |
|
public function getFilters() |
|
208
|
|
|
{ |
|
209
|
12 |
|
return $this->filters; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* {@inheritdoc} |
|
214
|
|
|
*/ |
|
215
|
8 |
|
public function setFilters(array $filters) |
|
216
|
|
|
{ |
|
217
|
8 |
|
$this->filters = $filters; |
|
218
|
8 |
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* {@inheritdoc} |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getFilter(string $key) |
|
224
|
|
|
{ |
|
225
|
|
|
$filters = $this->getFilters(); |
|
226
|
|
|
|
|
227
|
|
|
if (isset($filters[$key])) { |
|
228
|
|
|
return $filters[$key]; |
|
229
|
|
|
} |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|