Passed
Push — 1.8 ( 8b2854...6b63e4 )
by Robbie
15:17 queued 11:24
created

EventHolder_Controller   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseParams() 0 7 4
A FilteredUpdates() 0 19 2
A getUpdateName() 0 7 2
1
<?php
2
3
class EventHolder extends DatedUpdateHolder {
4
	
5
	private static $description = 'Container page for Event Pages, provides event filtering and pagination';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
6
7
	private static $allowed_children = array('EventPage');
0 ignored issues
show
introduced by
The private property $allowed_children is not used, and could be removed.
Loading history...
8
9
	private static $default_child = 'EventPage';
0 ignored issues
show
introduced by
The private property $default_child is not used, and could be removed.
Loading history...
10
11
	private static $update_name = 'Events';
0 ignored issues
show
introduced by
The private property $update_name is not used, and could be removed.
Loading history...
12
13
	private static $update_class = 'EventPage';
0 ignored issues
show
introduced by
The private property $update_class is not used, and could be removed.
Loading history...
14
15
	private static $icon = 'cwp/images/icons/sitetree_images/event_holder.png';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
16
17
	public $pageIcon =  'images/icons/sitetree_images/event_holder.png';
18
19
	private static $singular_name = 'Event Holder';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
20
21
	private static $plural_name = 'Event Holders';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
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.
0 ignored issues
show
Bug introduced by
The type The was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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.
0 ignored issues
show
Bug introduced by
The type Set was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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