1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GinoPane\BlogTaxonomy\Components; |
4
|
|
|
|
5
|
|
|
use Cms\Classes\Page; |
6
|
|
|
use Cms\Classes\ComponentBase; |
7
|
|
|
use GinoPane\BlogTaxonomy\Plugin; |
8
|
|
|
use GinoPane\BlogTaxonomy\Models\Series; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class SeriesList |
12
|
|
|
* |
13
|
|
|
* @package GinoPane\BlogTaxonomy\Components |
14
|
|
|
*/ |
15
|
|
|
class SeriesList extends ComponentBase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var Series |
19
|
|
|
*/ |
20
|
|
|
public $series; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Reference to the page name for linking to series |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $seriesPage; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* If the series list should be ordered by another attribute |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
public $sortOrder; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Whether display or not empty series |
38
|
|
|
* |
39
|
|
|
* @var bool |
40
|
|
|
*/ |
41
|
|
|
public $displayEmpty; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return array |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function componentDetails() |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
'name' => Plugin::LOCALIZATION_KEY . 'components.series_list.name', |
50
|
|
|
'description' => Plugin::LOCALIZATION_KEY . 'components.series_list.description' |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
public function defineProperties() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
'displayEmpty' => [ |
61
|
|
|
'title' => Plugin::LOCALIZATION_KEY . 'components.series_list.display_empty_title', |
62
|
|
|
'description' => Plugin::LOCALIZATION_KEY . 'components.series_list.display_empty_description', |
63
|
|
|
'type' => 'checkbox', |
64
|
|
|
'default' => false |
65
|
|
|
], |
66
|
|
|
'seriesPage' => [ |
67
|
|
|
'title' => Plugin::LOCALIZATION_KEY . 'components.series_list.series_page_title', |
68
|
|
|
'description' => Plugin::LOCALIZATION_KEY . 'components.series_list.series_page_description', |
69
|
|
|
'type' => 'dropdown', |
70
|
|
|
'default' => 'blog/series' |
71
|
|
|
], |
72
|
|
|
'sortOrder' => [ |
73
|
|
|
'title' => Plugin::LOCALIZATION_KEY . 'components.series_list.order_title', |
74
|
|
|
'description' => Plugin::LOCALIZATION_KEY . 'components.series_list.order_description', |
75
|
|
|
'type' => 'dropdown', |
76
|
|
|
'default' => 'title asc' |
77
|
|
|
], |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return mixed |
83
|
|
|
*/ |
84
|
|
|
public function getSeriesPageOptions() |
85
|
|
|
{ |
86
|
|
|
return Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @see BlogPost::$allowedSortingOptions |
91
|
|
|
* |
92
|
|
|
* @return mixed |
93
|
|
|
*/ |
94
|
|
|
public function getSortOrderOptions() |
95
|
|
|
{ |
96
|
|
|
return Series::$sortingOptions; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Prepare and return a series list |
101
|
|
|
* |
102
|
|
|
* @return mixed |
103
|
|
|
*/ |
104
|
|
|
public function onRun() |
105
|
|
|
{ |
106
|
|
|
// load series |
107
|
|
|
$this->seriesPage = $this->property('seriesPage', ''); |
108
|
|
|
$this->sortOrder = $this->property('sortOrder', 'title asc'); |
109
|
|
|
$this->displayEmpty = $this->property('displayEmpty', false); |
110
|
|
|
|
111
|
|
|
$this->series = $this->listSeries(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get Series |
116
|
|
|
* |
117
|
|
|
* @return mixed |
118
|
|
|
*/ |
119
|
|
|
protected function listSeries() |
120
|
|
|
{ |
121
|
|
|
// get series |
122
|
|
|
$series = Series::listFrontend([ |
123
|
|
|
'sort' => $this->sortOrder, |
124
|
|
|
'displayEmpty' => $this->property('displayEmpty') |
125
|
|
|
]); |
126
|
|
|
|
127
|
|
|
// Add a "url" helper attribute for linking to each post and category |
128
|
|
|
if ($series) { |
129
|
|
|
foreach ($series as $item) { |
130
|
|
|
$item->setUrl($this->seriesPage, $this->controller); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $series; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.