Skip to content

Commit d2e73ab

Browse files
committed
[smarcet] - #13800
* updated summit model to include banners per location
1 parent 697e262 commit d2e73ab

3 files changed

Lines changed: 213 additions & 9 deletions

File tree

summit/code/infrastructure/active_records/locations/SummitAbstractLocation.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@
1414
**/
1515
class SummitAbstractLocation extends DataObject implements ISummitLocation
1616
{
17-
private static $db = array
18-
(
17+
private static $db = [
18+
1919
'Name' => 'Varchar(255)',
2020
'Description' => 'HTMLText',
2121
'Order' => 'Int',
2222
'LocationType' => 'Enum(array("External","Internal", "None"), "None")',
23-
);
23+
];
2424

25-
private static $has_many = array
26-
(
27-
);
25+
private static $has_many = [
26+
'Banners' => 'LocationBanner'
27+
];
2828

2929
public function getFullName()
3030
{
3131
return $this->Name;
3232
}
3333

3434

35-
private static $has_one = array
36-
(
35+
private static $has_one = [
36+
3737
'Summit' => 'Summit'
38-
);
38+
];
3939

4040
private static $summary_fields = array
4141
(
@@ -108,6 +108,22 @@ public function getCMSFields()
108108
$_REQUEST['RoomID'] = $this->ID;
109109
else
110110
$_REQUEST['LocationID'] = $this->ID;
111+
112+
$config = GridFieldConfig_RecordEditor::create();
113+
$gridField = new GridField('Banners', 'Banners', $this->Banners(), $config);
114+
115+
$config->removeComponentsByType('GridFieldAddNewButton');
116+
$multi_class_selector = new GridFieldAddNewMultiClass();
117+
$multi_class_selector->setClasses
118+
(
119+
[
120+
'LocationBanner' => 'Banner',
121+
'ScheduledLocationBanner' => 'Scheduled Banner',
122+
]
123+
);
124+
$config->addComponent($multi_class_selector);
125+
126+
$f->addFieldToTab('Root.Banners', $gridField);
111127
}
112128
return $f;
113129
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright 2018 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
/**
16+
* Class LocationBanner
17+
*/
18+
class LocationBanner extends DataObject
19+
{
20+
private static $db = [
21+
'Title' => 'Text',
22+
'Content' => 'HTMLText',
23+
'Enabled' => 'Boolean',
24+
];
25+
26+
private static $has_one = [
27+
'Location' => 'SummitAbstractLocation',
28+
];
29+
30+
private static $summary_fields = [
31+
'Title',
32+
'Enabled'
33+
];
34+
35+
protected function validate()
36+
{
37+
$valid = parent::validate();
38+
39+
if(!$valid->valid()) return $valid;
40+
41+
if(empty($this->Title)){
42+
return $valid->error('Title is mandatory!');
43+
}
44+
45+
if(empty($this->Content)){
46+
return $valid->error('Content is mandatory!');
47+
}
48+
49+
return $valid;
50+
}
51+
52+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
/**
3+
* Copyright 2018 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
/**
16+
* Class ScheduledLocationBanner
17+
*/
18+
final class ScheduledLocationBanner extends LocationBanner
19+
{
20+
private static $db = [
21+
'StartDate' => 'SS_Datetime',
22+
'EndDate' => 'SS_Datetime',
23+
];
24+
25+
protected function validate()
26+
{
27+
$valid = parent::validate();
28+
29+
if(!$valid->valid()) return $valid;
30+
31+
$start_date = $this->getStartDate();
32+
$end_date = $this->getEndDate();
33+
34+
if((empty($start_date) || empty($end_date)) && $this->Enabled)
35+
return $valid->error('To Enabled this Banner you must define a start/end datetime!');
36+
37+
if(!empty($start_date) && !empty($end_date)) {
38+
$summit = $this->Location()->Summit();
39+
$timezone = $summit->TimeZone;
40+
41+
if (empty($timezone)) {
42+
return $valid->error('Invalid Summit TimeZone!');
43+
}
44+
45+
$start_date = new DateTime($start_date);
46+
$end_date = new DateTime($end_date);
47+
48+
if ($end_date <= $start_date)
49+
return $valid->error('start datetime must be greather than end datetime!');
50+
}
51+
52+
return $valid;
53+
}
54+
55+
/**
56+
* @return string
57+
*/
58+
public function getStartDate()
59+
{
60+
$location_id = $this->LocationID > 0 ? $this->LocationID : $_REQUEST['LocationID'];
61+
$location = SummitAbstractLocation::get()->byID($location_id);
62+
$summit = $location->Summit();
63+
$value = $this->getField('StartDate');
64+
return $summit->convertDateFromUTC2TimeZone($value);
65+
}
66+
67+
/**
68+
* @return string
69+
*/
70+
public function getEndDate()
71+
{
72+
$location_id = $this->LocationID > 0 ? $this->LocationID : $_REQUEST['LocationID'];
73+
$location = SummitAbstractLocation::get()->byID($location_id);
74+
$summit = $location->Summit();
75+
$value = $this->getField('EndDate');
76+
return $summit->convertDateFromUTC2TimeZone($value);
77+
}
78+
79+
public function setStartDate($value)
80+
{
81+
$location_id = $this->LocationID > 0 ? $this->LocationID : $_REQUEST['LocationID'];
82+
$location = SummitAbstractLocation::get()->byID($location_id);
83+
$summit = $location->Summit();
84+
if(is_null($summit)) throw new InvalidArgumentException('summit not found!');
85+
if(!empty($value))
86+
{
87+
$value = $summit->convertDateFromTimeZone2UTC($value);
88+
$this->setField('StartDate', $value);
89+
}
90+
}
91+
92+
public function setEndDate($value)
93+
{
94+
$location_id = $this->LocationID > 0 ? $this->LocationID : $_REQUEST['LocationID'];
95+
$location = SummitAbstractLocation::get()->byID($location_id);
96+
$summit = $location->Summit();
97+
if(is_null($summit)) throw new InvalidArgumentException('summit not found!');
98+
if(!empty($value))
99+
{
100+
$value = $summit->convertDateFromTimeZone2UTC($value);
101+
$this->setField('EndDate', $value);
102+
}
103+
}
104+
105+
public function getCMSFields()
106+
{
107+
$fields = parent::getCMSFields();
108+
109+
$summit_time_zone = null;
110+
$location_id = $this->LocationID > 0 ? $this->LocationID : $_REQUEST['LocationID'];
111+
$location = SummitAbstractLocation::get()->byID($location_id);
112+
$summit = $location->Summit();
113+
if($summit->TimeZone) {
114+
$time_zone_list = timezone_identifiers_list();
115+
$summit_time_zone = $time_zone_list[$summit->TimeZone];
116+
}
117+
118+
if($summit_time_zone) {
119+
$fields->addFieldToTab('Root.Dates', new HeaderField("All dates below are in <span style='color:red;'>$summit_time_zone</span> time."));
120+
}
121+
else {
122+
$fields->addFieldToTab('Root.Dates', new HeaderField("All dates below in the timezone of the summit's venue."));
123+
}
124+
125+
$fields->addFieldToTab('Root.Dates', $date = new DatetimeField('StartDate', "When does this banner start to be show?"));
126+
$date->getDateField()->setConfig('showcalendar', true);
127+
$date->getDateField()->setConfig('dateformat', 'dd/MM/yyyy');
128+
$fields->addFieldToTab('Root.Dates', $date = new DatetimeField('EndDate', "When does this Banner should stop to be shown?"));
129+
$date->getDateField()->setConfig('showcalendar', true);
130+
$date->getDateField()->setConfig('dateformat', 'dd/MM/yyyy');
131+
132+
133+
return $fields;
134+
}
135+
136+
}

0 commit comments

Comments
 (0)