1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Charcoal\Cms\Service\Manager; |
4
|
|
|
|
5
|
|
|
// dependencies from `charcoal-core` |
6
|
|
|
use Charcoal\Model\Collection; |
7
|
|
|
|
8
|
|
|
// dependencies from `charcoal-base` |
9
|
|
|
use Charcoal\Object\CategoryInterface; |
10
|
|
|
use Charcoal\Object\CategoryTrait; |
11
|
|
|
|
12
|
|
|
// Local dependencies |
13
|
|
|
use Charcoal\Cms\Config\CmsConfig; |
14
|
|
|
use Charcoal\Cms\NewsInterface; |
15
|
|
|
use Charcoal\Cms\Service\Loader\NewsLoader; |
16
|
|
|
|
17
|
|
|
// Psr-7 dependencies |
18
|
|
|
use Exception; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* News manager |
22
|
|
|
*/ |
23
|
|
|
class NewsManager extends AbstractManager |
24
|
|
|
{ |
25
|
|
|
use CategoryTrait; |
26
|
|
|
|
27
|
|
|
/** @var NewsInterface $currentNews The current news. */ |
28
|
|
|
protected $currentNews; |
29
|
|
|
|
30
|
|
|
/** @var integer $currentPage The current Page. */ |
31
|
|
|
protected $currentPage; |
32
|
|
|
|
33
|
|
|
/** @var integer $numPerPage News by page. */ |
34
|
|
|
protected $numPerPage = 0; |
35
|
|
|
|
36
|
|
|
/** @var integer $numPage How many pages. */ |
37
|
|
|
protected $numPage; |
38
|
|
|
|
39
|
|
|
/** @var boolean $pageCycle Does the pager can cycle indefinitely. */ |
40
|
|
|
protected $entryCycle = false; |
41
|
|
|
|
42
|
|
|
/** @var NewsInterface $nextNews */ |
43
|
|
|
protected $nextNews; |
44
|
|
|
|
45
|
|
|
/** @var NewsInterface $prevNews */ |
46
|
|
|
protected $prevNews; |
47
|
|
|
|
48
|
|
|
/** @var integer $page */ |
49
|
|
|
protected $page = 0; |
50
|
|
|
|
51
|
|
|
/** @var integer $category */ |
52
|
|
|
protected $category = 0; |
53
|
|
|
|
54
|
|
|
/** @var NewsInterface[] $all All the news. */ |
55
|
|
|
protected $all = []; |
56
|
|
|
|
57
|
|
|
/** @var NewsInterface[] $entries The news collection. */ |
58
|
|
|
protected $entries = []; |
59
|
|
|
|
60
|
|
|
/** @var NewsInterface[] $archive The archive news collection. */ |
61
|
|
|
protected $archive = []; |
62
|
|
|
|
63
|
|
|
/** @var NewsInterface $entry A news. */ |
64
|
|
|
protected $entry; |
65
|
|
|
|
66
|
|
|
/** @var object $objType The news object model. */ |
67
|
|
|
protected $objType; |
68
|
|
|
|
69
|
|
|
/** @var string $featIdent The config ident for featured news. */ |
70
|
|
|
protected $featIdent; |
71
|
|
|
|
72
|
|
|
/** @var NewsInterface[] $featList The config ident for featured news. */ |
73
|
|
|
protected $featList = []; |
74
|
|
|
|
75
|
|
|
/** @var NewsLoader $loader The news loader provider. */ |
76
|
|
|
protected $loader; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var array |
80
|
|
|
*/ |
81
|
|
|
protected $categoryItem = []; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* NewsManager constructor. |
85
|
|
|
* @param array $data The Data. |
86
|
|
|
* @throws Exception When $data index is not set. |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function __construct(array $data) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
parent::__construct($data); |
91
|
|
|
|
92
|
|
|
if (!isset($data['news/loader'])) { |
93
|
|
|
throw new Exception('News Loader must be defined in the NewsManager constructor.'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
$this->setLoader($data['news/loader']); |
97
|
|
|
|
98
|
|
|
/** @var CmsConfig $newsConfig */ |
99
|
|
|
$newsConfig = $this->adminConfig()->newsConfig(); |
100
|
|
|
|
101
|
|
|
$this->setNumPerPage($newsConfig->get('numPerPage')); |
102
|
|
|
$this->setEntryCycle($newsConfig->get('entryCycle')); |
103
|
|
|
$this->setObjType($newsConfig->get('objType')); |
104
|
|
|
$this->setCategoryItemType($newsConfig->get('category')); |
105
|
|
|
$this->setFeatIdent($newsConfig->get('configFeatIdent')); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* To be displayed news list. |
110
|
|
|
* @return mixed The news collection. |
111
|
|
|
*/ |
112
|
|
View Code Duplication |
public function entries() |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
$page = $this->page(); |
115
|
|
|
$cat = $this->category(); |
116
|
|
|
if (isset($this->entries[$cat])) { |
117
|
|
|
if (isset($this->entries[$cat][$page])) { |
118
|
|
|
return $this->entries[$cat][$page]; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
$loader = $this->loader()->upcoming(); |
122
|
|
|
$loader->addOrder('news_date', 'desc'); |
123
|
|
|
|
124
|
|
|
if ($this->category()) { |
125
|
|
|
$loader->addFilter('category', $this->category(), [ 'operator' => 'in' ]); |
126
|
|
|
} |
127
|
|
|
if ($this->numPerPage()) { |
128
|
|
|
$loader->setPage($this->page()); |
129
|
|
|
$loader->setNumPerPage($this->numPerPage()); |
130
|
|
|
} |
131
|
|
|
$this->entries[$cat][$page] = $loader->load(); |
132
|
|
|
|
133
|
|
|
return $this->entries[$cat][$page]; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param integer|null $id The news id. |
138
|
|
|
* @return mixed |
139
|
|
|
*/ |
140
|
|
View Code Duplication |
public function entry($id = null) |
|
|
|
|
141
|
|
|
{ |
142
|
|
|
if (!$id) { |
|
|
|
|
143
|
|
|
return $this->currentNews(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
if (!isset($this->entry[$id])) { |
147
|
|
|
$entry = $this->modelFactory()->get($this->objType())->loadFrom('id', $id); |
148
|
|
|
$this->entry[$id] = $entry->id() ? $entry : $this->currentNews(); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $this->entry[$id]; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* All available news. |
156
|
|
|
* @return NewsInterface[]|Collection The news collection. |
157
|
|
|
*/ |
158
|
|
|
public function all() |
159
|
|
|
{ |
160
|
|
|
if ($this->all) { |
|
|
|
|
161
|
|
|
return $this->all; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
$this->all = $this->loader()->all()->addOrder('news_date', 'desc')->load(); |
|
|
|
|
165
|
|
|
|
166
|
|
|
return $this->all; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return CategoryInterface[]|Collection The category collection. |
171
|
|
|
*/ |
172
|
|
View Code Duplication |
public function loadCategoryItems() |
|
|
|
|
173
|
|
|
{ |
174
|
|
|
$proto = $this->modelFactory()->create($this->categoryItemType()); |
175
|
|
|
$loader = $this->collectionLoader()->setModel($proto); |
176
|
|
|
$loader->addFilter('active', true); |
177
|
|
|
|
178
|
|
|
return $loader->load(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param integer $id The category id. |
183
|
|
|
* @return CategoryInterface |
184
|
|
|
*/ |
185
|
|
|
public function categoryItem($id) |
186
|
|
|
{ |
187
|
|
|
if (isset($this->categoryItem[$id])) { |
188
|
|
|
return $this->categoryItem[$id]; |
189
|
|
|
} |
190
|
|
|
$category = $this->modelFactory()->create($this->categoryItemType()); |
191
|
|
|
|
192
|
|
|
$this->categoryItem[$id] = $category->load($id); |
193
|
|
|
return $this->categoryItem[$id]; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return mixed |
198
|
|
|
* @param array $options The options for the collection loader. |
199
|
|
|
* @throws Exception When featured news ident is not valid. |
200
|
|
|
*/ |
201
|
|
View Code Duplication |
public function featList(array $options = []) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
if ($this->featList) { |
|
|
|
|
204
|
|
|
return $this->featList; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$loader = $this->loader()->published(); |
208
|
|
|
$ident = $this->featIdent(); |
209
|
|
|
$config = $this->adminConfig(); |
210
|
|
|
|
211
|
|
|
if (!$ident || !method_exists($config, $ident)) { |
212
|
|
|
throw new Exception(sprintf( |
213
|
|
|
'The featured news ident "%s" doesn\'t exist the class "%s"', |
214
|
|
|
$ident, |
215
|
|
|
get_class($config) |
216
|
|
|
)); |
217
|
|
|
} |
218
|
|
|
$ids = $config->{$ident}(); |
219
|
|
|
|
220
|
|
|
if (!$ids) { |
221
|
|
|
return null; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$ids = explode(',', $ids); |
225
|
|
|
|
226
|
|
|
$loader->addFilter('id', $ids, [ 'operator' => 'in' ]) |
227
|
|
|
->addOrder('id', 'values', [ 'values' => $ids ]); |
228
|
|
|
|
229
|
|
|
if (count($options) > 0) { |
230
|
|
|
foreach ($options as $key => $option) { |
231
|
|
|
switch ($key) { |
232
|
|
|
case 'filters': |
233
|
|
|
$filters = $option; |
234
|
|
|
foreach ($filters as $f) { |
235
|
|
|
$filter[] = $f['property'] ?: ''; |
|
|
|
|
236
|
|
|
$filter[] = $f['val'] ?: ''; |
|
|
|
|
237
|
|
|
$filter[] = $f['options'] ?: ''; |
238
|
|
|
$filter = join(',', $filter); |
239
|
|
|
|
240
|
|
|
$loader->addFilter($filter); |
241
|
|
|
} |
242
|
|
|
break; |
243
|
|
|
case 'page': |
244
|
|
|
$loader->setPage($option); |
245
|
|
|
break; |
246
|
|
|
case 'numPerPage': |
247
|
|
|
$loader->setNumPerPage($option); |
248
|
|
|
break; |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
$this->featList = $loader->load(); |
|
|
|
|
254
|
|
|
|
255
|
|
|
return $this->featList; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return NewsInterface[]|Collection |
260
|
|
|
*/ |
261
|
|
View Code Duplication |
public function archive() |
|
|
|
|
262
|
|
|
{ |
263
|
|
|
$page = $this->page(); |
264
|
|
|
$cat = $this->category(); |
265
|
|
|
if (isset($this->archive[$cat])) { |
266
|
|
|
if (isset($this->archive[$cat][$page])) { |
267
|
|
|
return $this->archive[$cat][$page]; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
$loader = $this->loader()->archive(); |
272
|
|
|
$loader->addOrder('news_date', 'desc'); |
273
|
|
|
|
274
|
|
|
if ($this->category()) { |
275
|
|
|
$loader->addFilter('category', $this->category(), [ 'operator' => 'in' ]); |
276
|
|
|
} |
277
|
|
|
if ($this->numPerPage()) { |
278
|
|
|
$loader->setPage($this->page()); |
279
|
|
|
$loader->setNumPerPage($this->numPerPage()); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
$this->archive[$cat][$page] = $loader->load(); |
283
|
|
|
|
284
|
|
|
return $this->archive[$cat][$page]; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Get the latest news. |
289
|
|
|
* @return NewsInterface|array The latest news. |
290
|
|
|
*/ |
291
|
|
View Code Duplication |
public function latest() |
|
|
|
|
292
|
|
|
{ |
293
|
|
|
$entries = $this->entries(); |
294
|
|
|
|
295
|
|
|
if (isset($entries[0])) { |
296
|
|
|
return $entries[0]; |
297
|
|
|
} else { |
298
|
|
|
// NO NEWS! |
299
|
|
|
return []; |
300
|
|
|
} |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @return mixed The previous news |
305
|
|
|
*/ |
306
|
|
|
public function prev() |
307
|
|
|
{ |
308
|
|
|
if ($this->prevNews) { |
309
|
|
|
return $this->prevNews; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
return $this->setPrevNext()->prevNews; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @return mixed The next news |
317
|
|
|
*/ |
318
|
|
|
public function next() |
319
|
|
|
{ |
320
|
|
|
if ($this->nextNews) { |
321
|
|
|
return $this->nextNews; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
return $this->setPrevNext()->nextNews; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @return float|int The current news index page ident. |
329
|
|
|
*/ |
330
|
|
View Code Duplication |
public function currentPage() |
|
|
|
|
331
|
|
|
{ |
332
|
|
|
if ($this->currentPage) { |
333
|
|
|
return $this->currentPage; |
334
|
|
|
} |
335
|
|
|
if (!$this->currentNews() || !$this->currentNews()['id']) { |
336
|
|
|
$this->currentPage = 1; |
337
|
|
|
|
338
|
|
|
return 1; |
339
|
|
|
} |
340
|
|
|
$all = $this->all(); |
341
|
|
|
$i = 0; |
342
|
|
|
foreach ($all as $news) { |
343
|
|
|
$i++; |
344
|
|
|
if ($news->id() == $this->currentNews()['id']) { |
345
|
|
|
break; |
346
|
|
|
} |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
$this->currentPage = $this->numPerPage() ? ceil($i / $this->numPerPage()) : 1; |
|
|
|
|
350
|
|
|
|
351
|
|
|
return $this->currentPage; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
// ========================================================================== |
355
|
|
|
// GETTERS |
356
|
|
|
// ========================================================================== |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @return mixed |
360
|
|
|
*/ |
361
|
|
|
public function currentNews() |
362
|
|
|
{ |
363
|
|
|
if (!$this->currentNews) { |
364
|
|
|
$this->currentNews = $this->latest(); |
|
|
|
|
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
return $this->currentNews; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @return integer |
372
|
|
|
*/ |
373
|
|
|
public function numPerPage() |
374
|
|
|
{ |
375
|
|
|
return $this->numPerPage; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @return boolean |
380
|
|
|
*/ |
381
|
|
|
public function entryCycle() |
382
|
|
|
{ |
383
|
|
|
return $this->entryCycle; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Amount of news (total) |
388
|
|
|
* @return integer How many news? |
389
|
|
|
*/ |
390
|
|
|
public function numNews() |
391
|
|
|
{ |
392
|
|
|
return !!(count($this->entries())); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
/** |
396
|
|
|
* The total amount of pages. |
397
|
|
|
* @return float |
398
|
|
|
*/ |
399
|
|
View Code Duplication |
public function numPages() |
|
|
|
|
400
|
|
|
{ |
401
|
|
|
if ($this->numPage) { |
402
|
|
|
$this->numPage; |
403
|
|
|
}; |
404
|
|
|
|
405
|
|
|
$entries = $this->entries(); |
406
|
|
|
$count = count($entries); |
407
|
|
|
|
408
|
|
|
if ($this->numPerPage()) { |
409
|
|
|
$this->numPage = ceil($count / $this->numPerPage()); |
|
|
|
|
410
|
|
|
} else { |
411
|
|
|
$this->numPage = 1; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
return $this->numPage; |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Is there a pager. |
419
|
|
|
* @return boolean |
420
|
|
|
*/ |
421
|
|
|
public function hasPager() |
422
|
|
|
{ |
423
|
|
|
return ($this->numPages() > 1); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @return integer |
428
|
|
|
*/ |
429
|
|
|
public function page() |
430
|
|
|
{ |
431
|
|
|
return $this->page; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @return integer |
436
|
|
|
*/ |
437
|
|
|
public function category() |
438
|
|
|
{ |
439
|
|
|
return $this->category; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return mixed |
444
|
|
|
*/ |
445
|
|
|
public function objType() |
446
|
|
|
{ |
447
|
|
|
return $this->objType; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @return mixed |
452
|
|
|
*/ |
453
|
|
|
public function featIdent() |
454
|
|
|
{ |
455
|
|
|
return $this->featIdent; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @return NewsLoader |
460
|
|
|
*/ |
461
|
|
|
public function loader() |
462
|
|
|
{ |
463
|
|
|
return $this->loader; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
// ========================================================================== |
467
|
|
|
// SETTERS |
468
|
|
|
// ========================================================================== |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* @param mixed $currentNews The current news context. |
472
|
|
|
* @return self . |
473
|
|
|
*/ |
474
|
|
|
public function setCurrentNews($currentNews) |
475
|
|
|
{ |
476
|
|
|
$this->currentNews = $currentNews; |
477
|
|
|
|
478
|
|
|
return $this; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* @param integer $numPerPage The number of news per page. |
483
|
|
|
* @return self |
484
|
|
|
*/ |
485
|
|
|
public function setNumPerPage($numPerPage) |
486
|
|
|
{ |
487
|
|
|
$this->numPerPage = $numPerPage; |
488
|
|
|
|
489
|
|
|
return $this; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* @param boolean $entryCycle Next and Prev cycles indefinitely. |
494
|
|
|
* @return self |
495
|
|
|
*/ |
496
|
|
|
public function setEntryCycle($entryCycle) |
497
|
|
|
{ |
498
|
|
|
$this->entryCycle = $entryCycle; |
499
|
|
|
|
500
|
|
|
return $this; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* @param integer $page The page number to load. |
505
|
|
|
* @return self |
506
|
|
|
*/ |
507
|
|
|
public function setPage($page) |
508
|
|
|
{ |
509
|
|
|
$this->page = $page; |
510
|
|
|
|
511
|
|
|
return $this; |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/** |
515
|
|
|
* @param integer $category The current news category. |
516
|
|
|
* @return self |
517
|
|
|
*/ |
518
|
|
|
public function setCategory($category) |
519
|
|
|
{ |
520
|
|
|
$this->category = $category; |
521
|
|
|
|
522
|
|
|
return $this; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* @param mixed $objType The object type. |
527
|
|
|
* @return self |
528
|
|
|
*/ |
529
|
|
|
public function setObjType($objType) |
530
|
|
|
{ |
531
|
|
|
$this->objType = $objType; |
532
|
|
|
|
533
|
|
|
return $this; |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* @param mixed $featIdent The featured list ident. |
538
|
|
|
* @return self |
539
|
|
|
*/ |
540
|
|
|
public function setFeatIdent($featIdent) |
541
|
|
|
{ |
542
|
|
|
$this->featIdent = $featIdent; |
543
|
|
|
|
544
|
|
|
return $this; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* @param NewsLoader $loader The news loader provider. |
549
|
|
|
* @return self |
550
|
|
|
*/ |
551
|
|
|
public function setLoader(NewsLoader $loader) |
552
|
|
|
{ |
553
|
|
|
$this->loader = $loader; |
554
|
|
|
|
555
|
|
|
return $this; |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
// ========================================================================== |
559
|
|
|
// UTILS |
560
|
|
|
// ========================================================================== |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* Set the Prev and Next news |
564
|
|
|
* @return $this |
565
|
|
|
*/ |
566
|
|
View Code Duplication |
public function setPrevNext() |
|
|
|
|
567
|
|
|
{ |
568
|
|
|
if ($this->nextNews && $this->prevNews) { |
569
|
|
|
return $this; |
570
|
|
|
} |
571
|
|
|
$entries = $this->entries(); |
572
|
|
|
|
573
|
|
|
$isPrev = false; |
574
|
|
|
$isNext = false; |
575
|
|
|
$firstNews = false; |
576
|
|
|
$lastNews = false; |
577
|
|
|
|
578
|
|
|
/** @var NewsInterface $news */ |
579
|
|
|
foreach ($entries as $news) { |
580
|
|
|
// Obtain th first news. |
581
|
|
|
if (!$firstNews) { |
582
|
|
|
$firstNews = $news; |
583
|
|
|
} |
584
|
|
|
$lastNews = $news; |
585
|
|
|
// Find the current news |
586
|
|
|
if ($news->id() == $this->currentNews()['id']) { |
587
|
|
|
$isNext = true; |
588
|
|
|
$isPrev = true; |
589
|
|
|
|
590
|
|
|
continue; |
591
|
|
|
} |
592
|
|
|
if (!$isPrev) { |
593
|
|
|
$this->prevNews = $news; |
594
|
|
|
} |
595
|
|
|
// Store the next news |
596
|
|
|
if ($isNext) { |
597
|
|
|
$this->nextNews = $news; |
598
|
|
|
|
599
|
|
|
$isNext = false; |
600
|
|
|
} |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
if ($this->entryCycle()) { |
604
|
|
|
if (!$this->nextNews) { |
605
|
|
|
$this->nextNews = $firstNews; |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
if (!$this->prevNews) { |
609
|
|
|
$this->prevNews = $lastNews; |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
return $this; |
614
|
|
|
} |
615
|
|
|
} |
616
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.