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

EventPage::getCMSFields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
class EventPage extends DatedUpdatePage {
4
5
	private static $description = 'Describes an event occurring on a specific date.';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
6
7
	static $default_parent = 'EventHolder';
8
9
	static $can_be_root = false;
10
11
	static $icon = 'cwp/images/icons/sitetree_images/event_page.png';
12
13
	public $pageIcon =  'images/icons/sitetree_images/event_page.png';
14
15
	private static $singular_name = 'Event Page';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
16
17
	private static $plural_name = 'Event Pages';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
18
19
	static $db = array(
20
		'StartTime' => 'Time',
21
		'EndTime' => 'Time',
22
		'Location' => 'Text'
23
	);
24
25
	public function fieldLabels($includerelations = true) {
26
		$labels = parent::fieldLabels($includerelations);
27
		$labels['StartTime'] = _t('DateUpdatePage.StartTimeFieldLabel', 'Start Time');
28
		$labels['EndTime'] = _t('DateUpdatePage.EndTimeFieldLabel', 'End Time');
29
		$labels['Location'] = _t('DateUpdatePage.LocationFieldLabel', 'Location');
30
31
		return $labels;
32
	}
33
34
	/**
35
	 * Add the default for the Date being the current day.
36
	 */
37
	public function populateDefaults() {
38
		if(!isset($this->Date) || $this->Date === null) {
39
			$this->Date = SS_Datetime::now()->Format('Y-m-d');
0 ignored issues
show
Bug Best Practice introduced by
The property Date does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
40
		}
41
42
		if(!isset($this->StartTime) || $this->StartTime === null) {
43
			$this->StartTime = '09:00:00';
0 ignored issues
show
Bug Best Practice introduced by
The property StartTime does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
44
		}
45
46
		if(!isset($this->EndTime) || $this->EndTime === null) {
47
			$this->EndTime = '17:00:00';
0 ignored issues
show
Bug Best Practice introduced by
The property EndTime does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
48
		}
49
50
		parent::populateDefaults();
51
	}
52
53
	public function getCMSFields() {
54
		$this->beforeUpdateCMSFields(function (FieldList $fields) {
55
			$fields->removeByName('Date');
56
57
			$dateTimeFields = array();
58
59
			$dateTimeFields[] = $dateField = DateField::create('Date', 'Date');
60
			$dateField->setConfig('showcalendar', true);
61
			$dateField->setConfig('dateformat', Member::currentUser()->getDateFormat());
62
63
			$dateTimeFields[] = $startTimeField = TimeField::create('StartTime', '&nbsp;&nbsp;' . $this->fieldLabel('StartTime'));
64
			$dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime'));
65
			// Would like to do this, but the width of the form field doesn't scale based on the time
66
			// format. OS ticket raised: http://open.silverstripe.org/ticket/8260
67
			//$startTimeField->setConfig('timeformat', Member::currentUser()->getTimeFormat());
68
			//$endTimeField->setConfig('timeformat', Member::currentUser()->getTimeFormat());
69
			$startTimeField->setConfig('timeformat', 'h:ma');
70
			$endTimeField->setConfig('timeformat', 'h:ma');
71
72
			$fields->addfieldToTab('Root.Main', $dateTimeField = new FieldGroup('Date and time', $dateTimeFields), 'Abstract');
73
74
			$fields->addfieldToTab('Root.Main', $locationField = TextareaField::create('Location', $this->fieldLabel('Location')), 'Abstract');
75
			$locationField->setRows(4);
76
		});
77
		return parent::getCMSFields();
78
	}
79
80
	public function NiceLocation() {
81
		return (nl2br(Convert::raw2xml($this->Location), true));
0 ignored issues
show
Bug introduced by
It seems like Convert::raw2xml($this->Location) can also be of type array; however, parameter $string of nl2br() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
		return (nl2br(/** @scrutinizer ignore-type */ Convert::raw2xml($this->Location), true));
Loading history...
82
	}
83
}
84
85
class EventPage_Controller extends Page_Controller {
0 ignored issues
show
Bug introduced by
The type Page_Controller 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...
86
87
}
88