1616use App \Models \Foundation \Summit \ProposedSchedule \SummitProposedScheduleAllowedLocation ;
1717use App \Services \Model \AbstractService ;
1818use App \Services \Model \ISummitProposedScheduleAllowedLocationService ;
19+ use App \Utils \Time ;
20+ use Illuminate \Support \Facades \Log ;
1921use models \exceptions \EntityNotFoundException ;
2022use models \exceptions \ValidationException ;
2123use models \summit \PresentationCategory ;
@@ -61,11 +63,11 @@ public function addProposedLocationToTrack(PresentationCategory $track, array $p
6163 public function deleteProposedLocationFromTrack (PresentationCategory $ track , int $ allowed_location_id ): void
6264 {
6365 $ this ->tx_service ->transaction (function () use ($ track , $ allowed_location_id ){
64- $ location = $ track ->getAllowedLocationById ($ allowed_location_id );
65- if (is_null ($ location ))
66+ $ allowed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
67+ if (is_null ($ allowed_location ))
6668 throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
6769
68- $ track ->removeProposedScheduleAllowedLocation ($ location );
70+ $ track ->removeProposedScheduleAllowedLocation ($ allowed_location );
6971 });
7072 }
7173
@@ -80,35 +82,87 @@ public function addAllowedDayToProposedLocation(PresentationCategory $track, int
8082 {
8183 return $ this ->tx_service ->transaction (function () use ($ track , $ allowed_location_id , $ payload ){
8284
83- $ alloqed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
84- if (is_null ($ alloqed_location ))
85+ $ allowed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
86+ if (is_null ($ allowed_location ))
8587 throw new EntityNotFoundException (sprintf ("Allowed Location %s not found. " , $ allowed_location_id ));
8688
87- if ($ alloqed_location ->getLocation ()->getClassName () === SummitVenue::ClassName){
89+ if ($ allowed_location ->getLocation ()->getClassName () === SummitVenue::ClassName){
8890 throw new ValidationException ("Location is a Venue, you can not add a venue to a track. " );
8991 }
9092
9193 $ summit = $ track ->getSummit ();
9294 $ day = intval ($ payload ['day ' ]);
95+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation day epoch %s " , $ day ));
9396 $ day = new \DateTime ("@ $ day " , new \DateTimeZone ("UTC " ));
97+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation day %s " , $ day ->format ("Y-m-d H:i:s " )));
9498 $ localDay = $ summit ->convertDateFromUTC2TimeZone ($ day );
99+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation localDay %s " , $ localDay ->format ("Y-m-d H:i:s " )));
95100 // reset time on local day
96- $ localDay ->setTime (0 ,0 ,0 );
101+ $ localDay = $ localDay ->setTime (0 ,0 ,0 , 0 );
97102 $ day = $ summit ->convertDateFromTimeZone2UTC ($ localDay );
98103
99- if (!$ summit ->dayIsOnSummitPeriod ($ day , false ))
104+ if (!$ summit ->dayIsOnSummitPeriod ($ day , true ))
100105 throw new ValidationException
101106 (
102107 sprintf
103108 (
104109 "Day %s is not on summit period( %s - %s). " ,
105- $ day ->format ("Y-m-d " ),
106- $ summit ->getLocalBeginDate ()->format ("Y-m-d " ),
107- $ summit ->getLocalEndDate ()->format ("Y-m-d " ),
110+ $ day ->format ("Y-m-d h:i:s " ),
111+ $ summit ->getLocalBeginDate ()->format ("Y-m-d h:i:s " ),
112+ $ summit ->getLocalEndDate ()->format ("Y-m-d h:i:s " ),
108113 )
109114 );
110115
111- return $ alloqed_location ->addAllowedTimeFrame ($ day , $ payload ['opening_hour ' ] ?? null , $ payload ['closing_hour ' ] ?? null );
116+ // check opening / closing hours
117+ $ opening_hour = $ payload ['opening_hour ' ] ?? null ;
118+ $ closing_hour = $ payload ['closing_hour ' ] ?? null ;
119+
120+ if (!is_null ($ opening_hour )){
121+ list ($ hour , $ minute ) =Time::getHourAndMinutesFromInt ($ opening_hour );
122+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation opening_hour %s %s " , $ hour , $ minute ));
123+ $ start_local_date = clone $ localDay ;
124+ $ start_local_date = $ start_local_date ->setTime ($ hour , $ minute , 0 , 0 );
125+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation start_local_date %s " , $ start_local_date ->format ("Y-m-d H:i:s " )));
126+
127+ if (!$ summit ->dayIsOnSummitPeriod ($ summit ->convertDateFromTimeZone2UTC ($ start_local_date ), false ))
128+ throw new ValidationException
129+ (
130+ sprintf
131+ (
132+ "Start Day %s is not on summit period( %s - %s). " ,
133+ $ start_local_date ->format ("Y-m-d h:i:s " ),
134+ $ summit ->getLocalBeginDate ()->format ("Y-m-d h:i:s " ),
135+ $ summit ->getLocalEndDate ()->format ("Y-m-d h:i:s " ),
136+ )
137+ );
138+ }
139+
140+ if (!is_null ($ closing_hour )){
141+ list ($ hour , $ minute ) =Time::getHourAndMinutesFromInt ($ closing_hour );
142+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation closing_hour %s %s " , $ hour , $ minute ));
143+ $ end_local_date = clone $ localDay ;
144+ $ end_local_date = $ end_local_date ->setTime ($ hour , $ minute , 0 , 0 );
145+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation end_local_date %s " , $ end_local_date ->format ("Y-m-d H:i:s " )));
146+
147+ if (!$ summit ->dayIsOnSummitPeriod ($ summit ->convertDateFromTimeZone2UTC ($ end_local_date ), false ))
148+ throw new ValidationException
149+ (
150+ sprintf
151+ (
152+ "End Day %s is not on summit period( %s - %s). " ,
153+ $ end_local_date ->format ("Y-m-d h:i:s " ),
154+ $ summit ->getLocalBeginDate ()->format ("Y-m-d h:i:s " ),
155+ $ summit ->getLocalEndDate ()->format ("Y-m-d h:i:s " ),
156+ )
157+ );
158+ }
159+
160+ return $ allowed_location ->addAllowedTimeFrame
161+ (
162+ $ day ,
163+ $ opening_hour ,
164+ $ closing_hour ,
165+ );
112166 });
113167 }
114168
@@ -123,11 +177,11 @@ public function addAllowedDayToProposedLocation(PresentationCategory $track, int
123177 public function updateAllowedDayToProposedLocation (PresentationCategory $ track , int $ allowed_location_id , int $ allowed_day_id , array $ payload ): ?SummitProposedScheduleAllowedDay
124178 {
125179 return $ this ->tx_service ->transaction (function () use ($ track , $ allowed_location_id , $ allowed_day_id ){
126- $ alloqed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
127- if (is_null ($ alloqed_location ))
180+ $ allowed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
181+ if (is_null ($ allowed_location ))
128182 throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
129183
130- $ time_frame = $ alloqed_location ->getAllowedTimeFrameById ($ allowed_day_id );
184+ $ time_frame = $ allowed_location ->getAllowedTimeFrameById ($ allowed_day_id );
131185
132186 if (is_null ($ time_frame ))
133187 throw new EntityNotFoundException (sprintf ("Allowed Day %s not found " , $ allowed_day_id ));
@@ -145,16 +199,16 @@ public function updateAllowedDayToProposedLocation(PresentationCategory $track,
145199 public function deleteAllowedDayToProposedLocation (PresentationCategory $ track , int $ allowed_location_id , int $ allowed_day_id ): void
146200 {
147201 $ this ->tx_service ->transaction (function () use ($ track , $ allowed_location_id , $ allowed_day_id ){
148- $ alloqed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
149- if (is_null ($ alloqed_location ))
202+ $ allowed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
203+ if (is_null ($ allowed_location ))
150204 throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
151205
152- $ time_frame = $ alloqed_location ->getAllowedTimeFrameById ($ allowed_day_id );
206+ $ time_frame = $ allowed_location ->getAllowedTimeFrameById ($ allowed_day_id );
153207
154208 if (is_null ($ time_frame ))
155209 throw new EntityNotFoundException (sprintf ("Allowed Day %s not found " , $ allowed_day_id ));
156210
157- $ alloqed_location ->removeAllowedTimeFrame ($ time_frame );
211+ $ allowed_location ->removeAllowedTimeFrame ($ time_frame );
158212
159213 });
160214 }
@@ -168,11 +222,11 @@ public function deleteAllowedDayToProposedLocation(PresentationCategory $track,
168222 public function deleteAllAllowedDayToProposedLocation (PresentationCategory $ track , int $ allowed_location_id ): void
169223 {
170224 $ this ->tx_service ->transaction (function () use ($ track , $ allowed_location_id ){
171- $ alloqed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
172- if (is_null ($ alloqed_location ))
225+ $ allowed_location = $ track ->getAllowedLocationById ($ allowed_location_id );
226+ if (is_null ($ allowed_location ))
173227 throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
174228
175- $ alloqed_location ->clearAllowedTimeFrames ();
229+ $ allowed_location ->clearAllowedTimeFrames ();
176230
177231 });
178232 }
0 commit comments