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