1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GinoPane\BlogTaxonomy\Components; |
4
|
|
|
|
5
|
|
|
use GinoPane\BlogTaxonomy\Plugin; |
6
|
|
|
use GinoPane\BlogTaxonomy\Models\Series; |
7
|
|
|
use GinoPane\BlogTaxonomy\Classes\TranslateArrayTrait; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class RelatedSeries |
11
|
|
|
* |
12
|
|
|
* @package GinoPane\BlogTaxonomy\Components |
13
|
|
|
*/ |
14
|
|
|
class RelatedSeries extends SeriesList |
15
|
|
|
{ |
16
|
|
|
const NAME = 'relatedSeries'; |
17
|
|
|
|
18
|
|
|
use TranslateArrayTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return array |
22
|
|
|
*/ |
23
|
|
|
public function componentDetails(): array |
24
|
|
|
{ |
25
|
|
|
return [ |
26
|
|
|
'name' => Plugin::LOCALIZATION_KEY . 'components.related_series.name', |
27
|
|
|
'description' => Plugin::LOCALIZATION_KEY . 'components.related_series.description' |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
public function defineProperties(): array |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
'series' => [ |
38
|
|
|
'title' => Plugin::LOCALIZATION_KEY . 'components.series_posts.series_title', |
39
|
|
|
'description' => Plugin::LOCALIZATION_KEY . 'components.series_posts.series_description', |
40
|
|
|
'type' => 'string', |
41
|
|
|
'default' => '{{ :series }}', |
42
|
|
|
], |
43
|
|
|
'seriesPage' => [ |
44
|
|
|
'group' => Plugin::LOCALIZATION_KEY . 'components.post_list_abstract.links_group', |
45
|
|
|
'title' => Plugin::LOCALIZATION_KEY . 'components.series_list.series_page_title', |
46
|
|
|
'description' => Plugin::LOCALIZATION_KEY . 'components.series_list.series_page_description', |
47
|
|
|
'type' => 'dropdown', |
48
|
|
|
'default' => 'blog/series', |
49
|
|
|
'showExternalParam' => false |
50
|
|
|
], |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Prepare and return a series list |
56
|
|
|
* |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
|
|
public function onRun() |
60
|
|
|
{ |
61
|
|
|
$this->seriesPage = $this->getProperty('seriesPage'); |
62
|
|
|
|
63
|
|
|
$this->series = $this->listRelatedSeries(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get Series |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
protected function listRelatedSeries() |
72
|
|
|
{ |
73
|
|
|
$series = Series::whereTranslatable('slug', $this->property('series')) |
74
|
|
|
->with( |
75
|
|
|
[ |
76
|
|
|
'related_series' => static function ($query) { |
77
|
|
|
$query->withCount( |
78
|
|
|
[ |
79
|
|
|
'posts' => static function ($query) { |
80
|
|
|
$query->isPublished(); |
81
|
|
|
} |
82
|
|
|
] |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
] |
86
|
|
|
) |
87
|
|
|
->first(); |
88
|
|
|
|
89
|
|
|
$relatedSeries = $series->related_series; |
90
|
|
|
|
91
|
|
|
$this->handleUrls($relatedSeries); |
92
|
|
|
|
93
|
|
|
return $relatedSeries; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|