1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CWP\CWP\PageTypes; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Convert; |
6
|
|
|
use SilverStripe\Forms\DateField; |
7
|
|
|
use SilverStripe\Forms\FieldGroup; |
8
|
|
|
use SilverStripe\Forms\FieldList; |
9
|
|
|
use SilverStripe\Forms\TextareaField; |
10
|
|
|
use SilverStripe\Forms\TimeField; |
11
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime; |
12
|
|
|
|
13
|
|
|
class EventPage extends DatedUpdatePage |
14
|
|
|
{ |
15
|
|
|
private static $description = 'Describes an event occurring on a specific date.'; |
|
|
|
|
16
|
|
|
|
17
|
|
|
private static $default_parent = EventHolder::class; |
|
|
|
|
18
|
|
|
|
19
|
|
|
private static $can_be_root = false; |
|
|
|
|
20
|
|
|
|
21
|
|
|
private static $icon_class = 'font-icon-p-event'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
private static $singular_name = 'Event Page'; |
|
|
|
|
24
|
|
|
|
25
|
|
|
private static $plural_name = 'Event Pages'; |
|
|
|
|
26
|
|
|
|
27
|
|
|
private static $db = [ |
|
|
|
|
28
|
|
|
'StartTime' => 'Time', |
29
|
|
|
'EndTime' => 'Time', |
30
|
|
|
'Location' => 'Text', |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
private static $table_name = 'EventPage'; |
|
|
|
|
34
|
|
|
|
35
|
|
|
public function fieldLabels($includerelations = true) |
36
|
|
|
{ |
37
|
|
|
$labels = parent::fieldLabels($includerelations); |
38
|
|
|
$labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time'); |
39
|
|
|
$labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time'); |
40
|
|
|
$labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location'); |
41
|
|
|
|
42
|
|
|
return $labels; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Add the default for the Date being the current day. |
47
|
|
|
*/ |
48
|
|
|
public function populateDefaults() |
49
|
|
|
{ |
50
|
|
|
if (!isset($this->Date) || $this->Date === null) { |
51
|
|
|
$this->Date = DBDatetime::now()->Format('y-MM-dd'); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (!isset($this->StartTime) || $this->StartTime === null) { |
55
|
|
|
$this->StartTime = '09:00:00'; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (!isset($this->EndTime) || $this->EndTime === null) { |
59
|
|
|
$this->EndTime = '17:00:00'; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
parent::populateDefaults(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getCMSFields() |
66
|
|
|
{ |
67
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
68
|
|
|
$fields->removeByName('Date'); |
69
|
|
|
|
70
|
|
|
$dateTimeFields = array(); |
71
|
|
|
|
72
|
|
|
$dateTimeFields[] = $dateField = DateField::create('Date', 'Date'); |
|
|
|
|
73
|
|
|
$dateTimeFields[] = $startTimeField = TimeField::create( |
|
|
|
|
74
|
|
|
'StartTime', |
75
|
|
|
$this->fieldLabel('StartTime') |
76
|
|
|
); |
77
|
|
|
$dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime')); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$fields->addFieldsToTab('Root.Main', [ |
80
|
|
|
$dateTimeField = FieldGroup::create('Date and time', $dateTimeFields), |
|
|
|
|
81
|
|
|
$locationField = TextareaField::create('Location', $this->fieldLabel('Location')) |
82
|
|
|
], 'Abstract'); |
83
|
|
|
$locationField->setRows(4); |
84
|
|
|
}); |
85
|
|
|
return parent::getCMSFields(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function NiceLocation() |
89
|
|
|
{ |
90
|
|
|
return nl2br(Convert::raw2xml($this->Location), true); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|