|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class EventHolder extends DatedUpdateHolder { |
|
4
|
|
|
|
|
5
|
|
|
private static $description = 'Container page for Event Pages, provides event filtering and pagination'; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
private static $allowed_children = array('EventPage'); |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
private static $default_child = 'EventPage'; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
private static $update_name = 'Events'; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
private static $update_class = 'EventPage'; |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
private static $icon = 'cwp/images/icons/sitetree_images/event_holder.png'; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
public $pageIcon = 'images/icons/sitetree_images/event_holder.png'; |
|
18
|
|
|
|
|
19
|
|
|
private static $singular_name = 'Event Holder'; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
private static $plural_name = 'Event Holders'; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Find all site's news items, based on some filters. |
|
25
|
|
|
* Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
|
|
|
|
|
26
|
|
|
* |
|
27
|
|
|
* @param $className The name of the class to fetch. |
|
28
|
|
|
* @param $parentID The ID of the holder to extract the news items from. |
|
29
|
|
|
* @param $tagID The ID of the tag to filter the news items by. |
|
30
|
|
|
* @param $dateFrom The beginning of a date filter range. |
|
31
|
|
|
* @param $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
32
|
|
|
* @param $year Numeric value of the year to show. |
|
33
|
|
|
* @param $monthNumber Numeric value of the month to show. |
|
34
|
|
|
* |
|
35
|
|
|
* @returns DataList | PaginatedList |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function AllUpdates($className = 'Events', $parentID = null, $tagID = null, $dateFrom = null, |
|
38
|
|
|
$dateTo = null, $year = null, $monthNumber = null) { |
|
39
|
|
|
|
|
40
|
|
|
return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber)->Sort('Date', 'ASC'); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The parameters apply in the following preference order: |
|
46
|
|
|
* - Highest priority: Tag & date (or date range) |
|
47
|
|
|
* - Month (and Year) |
|
48
|
|
|
* - Pagination |
|
49
|
|
|
* |
|
50
|
|
|
* So, when the user click on a tag link, the pagination, and month will be reset, but not the date filter. Also, |
|
51
|
|
|
* changing the date will not affect the tag, but will reset the month and pagination. |
|
52
|
|
|
* |
|
53
|
|
|
* When the user clicks on a month, pagination will be reset, but tags retained. Pagination retains all other |
|
54
|
|
|
* parameters. |
|
55
|
|
|
*/ |
|
56
|
|
|
class EventHolder_Controller extends DatedUpdateHolder_Controller { |
|
57
|
|
|
|
|
58
|
|
|
public function getUpdateName() { |
|
59
|
|
|
$params = $this->parseParams(); |
|
60
|
|
|
if ($params['upcomingOnly']) { |
|
61
|
|
|
return _t('EventHolder.Upcoming','Upcoming events'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return 'Events'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Parse URL parameters. |
|
69
|
|
|
* |
|
70
|
|
|
* @param $produceErrorMessages Set to false to omit session messages. |
|
|
|
|
|
|
71
|
|
|
*/ |
|
72
|
|
|
public function parseParams($produceErrorMessages = true) { |
|
73
|
|
|
$params = parent::parseParams($produceErrorMessages); |
|
74
|
|
|
|
|
75
|
|
|
// We need to set whether or not we're supposed to be displaying only upcoming events or all events. |
|
76
|
|
|
$params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']); |
|
77
|
|
|
|
|
78
|
|
|
return $params; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Get the events based on the current query. |
|
83
|
|
|
*/ |
|
84
|
|
|
public function FilteredUpdates($pageSize = 20) { |
|
85
|
|
|
$params = $this->parseParams(); |
|
86
|
|
|
|
|
87
|
|
|
$items = $this->Updates( |
|
88
|
|
|
$params['tag'], |
|
89
|
|
|
$params['from'], |
|
90
|
|
|
$params['to'], |
|
91
|
|
|
$params['year'], |
|
92
|
|
|
$params['month'] |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
if ($params['upcomingOnly']) { |
|
96
|
|
|
$items = $items->filter(array('Date:LessThan:Not' => SS_Datetime::now()->Format('Y-m-d'))); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
// Apply pagination |
|
100
|
|
|
$list = new PaginatedList($items, $this->request); |
|
101
|
|
|
$list->setPageLength($pageSize); |
|
102
|
|
|
return $list; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|