1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class TrainingPage extends Page |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
private static $icon = "mysite/images/treeicons/TrainingPage"; |
|
|
|
|
6
|
|
|
|
7
|
|
|
private static $db = array( |
|
|
|
|
8
|
|
|
"Date" => "Date", |
9
|
|
|
"EndDate" => "Date", |
10
|
|
|
"Location" => "Varchar(255)", |
11
|
|
|
"Price" => "Currency", |
12
|
|
|
"IsOpenForBookings" => "Boolean", |
13
|
|
|
"PlacesAvailable" => "Int", |
14
|
|
|
"PeopleSignedUpElseWhere" => "Int", |
15
|
|
|
"MoreInformation" => "HTMLText", |
16
|
|
|
"Options" => "Text" |
17
|
|
|
); |
18
|
|
|
|
19
|
|
|
private static $has_one = array( |
|
|
|
|
20
|
|
|
"DownloadFile" => "File" |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
private static $many_many = array( |
|
|
|
|
24
|
|
|
"Attendees" => "Member" |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
private static $many_many_extraFields = array( |
|
|
|
|
28
|
|
|
"Attendees" => array( |
29
|
|
|
"SelectedOption" => "Varchar(255)", |
30
|
|
|
"BookingCode" => "Varchar(255)" |
31
|
|
|
) |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
//parents and children in sitetree |
35
|
|
|
private static $allowed_children = "none"; //can also be "none"; |
|
|
|
|
36
|
|
|
private static $default_parent = "TrainingHolder"; |
|
|
|
|
37
|
|
|
private static $can_be_root = false; //default is true |
|
|
|
|
38
|
|
|
|
39
|
|
|
public function getCMSFields() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$fields = parent::getCMSFields(); |
42
|
|
|
$fields->addFieldToTab("Root.WhoWhereWhat", new DateField("Date", "Start Date")); |
43
|
|
|
$fields->addFieldToTab("Root.WhoWhereWhat", new DateField("EndDate", "End Date - can be left blank for one day events")); |
44
|
|
|
$fields->addFieldToTab("Root.WhoWhereWhat", new TextField("Location")); |
45
|
|
|
$fields->addFieldToTab("Root.WhoWhereWhat", new CurrencyField("Price")); |
46
|
|
|
$fields->addFieldToTab("Root.MoreInformation", new UploadField("DownloadFile", "Download File")); |
47
|
|
|
$fields->addFieldToTab("Root.MoreInformation", new HtmlEditorField("MoreInformation", "More Information")); |
48
|
|
|
$fields->addFieldToTab("Root.Bookings", new CheckboxField("IsOpenForBookings", "Is Open For Bookings")); |
49
|
|
|
$fields->addFieldToTab("Root.Bookings", new HeaderField("ActualPlacesAvailableHeader", "Actual Places Available: ".$this->ActualPlacesAvailable(), 3)); |
50
|
|
|
$fields->addFieldToTab("Root.Bookings", new LiteralField("ActualPlacesAvailableData", "Calculated as: Places Available [-] Minus People Signed up elsewhere [-] Minus People Signed up through this Website)")); |
51
|
|
|
$fields->addFieldToTab("Root.Bookings", new NumericField("PlacesAvailable", "Places Available")); |
52
|
|
|
$fields->addFieldToTab("Root.Bookings", new NumericField("PeopleSignedUpElseWhere", "People Signed Up Else Where (thus excluding the ones signed up on this website)")); |
53
|
|
|
$fields->addFieldToTab("Root.Bookings", new HeaderField("FormAdditions", "Form Additions", 3)); |
54
|
|
|
$fields->addFieldToTab("Root.Bookings", new TextareaField("Options", "Options available (separate by comma) - if any (e.g. venues)")); |
55
|
|
|
$fields->addFieldToTab("Root.Bookings", new HeaderField("Current Registrations", "Current Registrations", 3)); |
56
|
|
|
$fields->addFieldToTab( |
57
|
|
|
"Root.Bookings", |
58
|
|
|
$this->MemberField() |
59
|
|
|
); |
60
|
|
|
return $fields; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function MemberField() |
64
|
|
|
{ |
65
|
|
|
$memberField = new GridField( |
66
|
|
|
$name = "Attendees", |
67
|
|
|
$sourceClass = "Attendees", |
68
|
|
|
$this->Attendees(), |
69
|
|
|
GridFieldConfig_RelationEditor::create() |
70
|
|
|
); |
71
|
|
|
return $memberField; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function addAttendee($member, $extraFields = null) |
75
|
|
|
{ |
76
|
|
|
$existingMembers = $this->Attendees(); |
77
|
|
|
$existingMembers->add($member, $extraFields); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function DifferentEndDate() |
81
|
|
|
{ |
82
|
|
|
if ($this->Date != $this->EndDate && $this->EndDate) { |
83
|
|
|
return true; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function DifferentEndMonth() |
88
|
|
|
{ |
89
|
|
|
if ($this->DifferentEndDate()) { |
90
|
|
|
if (Date("F", $this->Date) || Date("F", $this->EndDate)) { |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function ActualPlacesAvailable() |
97
|
|
|
{ |
98
|
|
|
return intval($this->PlacesAvailable - $this->PeopleSignedUpElseWhere - $this->Attendees("\"TrainingPageID\" = ".$this->ID)->count()); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
class TrainingPage_Controller extends Page_Controller |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
private static $allowed_actions = array( |
|
|
|
|
105
|
|
|
"thankyou", |
106
|
|
|
"SignUpForm" |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
public function SignUpForm() |
110
|
|
|
{ |
111
|
|
|
if ( |
112
|
|
|
!$this->IsOpenForBookings || |
113
|
|
|
"thankyou" == $this->getRequest()->param("Action") || |
114
|
|
|
$this->MemberAlreadySignedUp() || |
115
|
|
|
$this->ActualPlacesAvailable() < 1 |
116
|
|
|
) { |
117
|
|
|
return false; |
118
|
|
|
} |
119
|
|
|
$form = new TrainingSignupForm($this, "SignUpForm", "Sign-Up for ".$this->Title); |
120
|
|
|
return $form; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function thankyou() |
124
|
|
|
{ |
125
|
|
|
$this->Title = "Thank You"; |
126
|
|
|
$this->Content = "We will be in touch soon"; |
127
|
|
|
return array(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function MemberAlreadySignedUp() |
131
|
|
|
{ |
132
|
|
|
if ($id = Member::currentUserID()) { |
133
|
|
|
if ($this->Attendees("\"MemberID\" = ".$id.' AND \"TrainingPageID\" = '.$this->ID)->count()) { |
134
|
|
|
return true; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
return false; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.