16
16
use App \Models \Foundation \Summit \ProposedSchedule \SummitProposedScheduleAllowedLocation ;
17
17
use App \Services \Model \AbstractService ;
18
18
use App \Services \Model \ISummitProposedScheduleAllowedLocationService ;
19
+ use App \Utils \Time ;
20
+ use Illuminate \Support \Facades \Log ;
19
21
use models \exceptions \EntityNotFoundException ;
20
22
use models \exceptions \ValidationException ;
21
23
use models \summit \PresentationCategory ;
@@ -61,11 +63,11 @@ public function addProposedLocationToTrack(PresentationCategory $track, array $p
61
63
public function deleteProposedLocationFromTrack (PresentationCategory $ track , int $ allowed_location_id ): void
62
64
{
63
65
$ 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 ))
66
68
throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
67
69
68
- $ track ->removeProposedScheduleAllowedLocation ($ location );
70
+ $ track ->removeProposedScheduleAllowedLocation ($ allowed_location );
69
71
});
70
72
}
71
73
@@ -80,35 +82,87 @@ public function addAllowedDayToProposedLocation(PresentationCategory $track, int
80
82
{
81
83
return $ this ->tx_service ->transaction (function () use ($ track , $ allowed_location_id , $ payload ){
82
84
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 ))
85
87
throw new EntityNotFoundException (sprintf ("Allowed Location %s not found. " , $ allowed_location_id ));
86
88
87
- if ($ alloqed_location ->getLocation ()->getClassName () === SummitVenue::ClassName){
89
+ if ($ allowed_location ->getLocation ()->getClassName () === SummitVenue::ClassName){
88
90
throw new ValidationException ("Location is a Venue, you can not add a venue to a track. " );
89
91
}
90
92
91
93
$ summit = $ track ->getSummit ();
92
94
$ day = intval ($ payload ['day ' ]);
95
+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation day epoch %s " , $ day ));
93
96
$ day = new \DateTime ("@ $ day " , new \DateTimeZone ("UTC " ));
97
+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation day %s " , $ day ->format ("Y-m-d H:i:s " )));
94
98
$ localDay = $ summit ->convertDateFromUTC2TimeZone ($ day );
99
+ Log::debug (sprintf ("SummitProposedScheduleAllowedLocationService::addAllowedDayToProposedLocation localDay %s " , $ localDay ->format ("Y-m-d H:i:s " )));
95
100
// reset time on local day
96
- $ localDay ->setTime (0 ,0 ,0 );
101
+ $ localDay = $ localDay ->setTime (0 ,0 ,0 , 0 );
97
102
$ day = $ summit ->convertDateFromTimeZone2UTC ($ localDay );
98
103
99
- if (!$ summit ->dayIsOnSummitPeriod ($ day , false ))
104
+ if (!$ summit ->dayIsOnSummitPeriod ($ day , true ))
100
105
throw new ValidationException
101
106
(
102
107
sprintf
103
108
(
104
109
"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 " ),
108
113
)
109
114
);
110
115
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
+ );
112
166
});
113
167
}
114
168
@@ -123,11 +177,11 @@ public function addAllowedDayToProposedLocation(PresentationCategory $track, int
123
177
public function updateAllowedDayToProposedLocation (PresentationCategory $ track , int $ allowed_location_id , int $ allowed_day_id , array $ payload ): ?SummitProposedScheduleAllowedDay
124
178
{
125
179
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 ))
128
182
throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
129
183
130
- $ time_frame = $ alloqed_location ->getAllowedTimeFrameById ($ allowed_day_id );
184
+ $ time_frame = $ allowed_location ->getAllowedTimeFrameById ($ allowed_day_id );
131
185
132
186
if (is_null ($ time_frame ))
133
187
throw new EntityNotFoundException (sprintf ("Allowed Day %s not found " , $ allowed_day_id ));
@@ -145,16 +199,16 @@ public function updateAllowedDayToProposedLocation(PresentationCategory $track,
145
199
public function deleteAllowedDayToProposedLocation (PresentationCategory $ track , int $ allowed_location_id , int $ allowed_day_id ): void
146
200
{
147
201
$ 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 ))
150
204
throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
151
205
152
- $ time_frame = $ alloqed_location ->getAllowedTimeFrameById ($ allowed_day_id );
206
+ $ time_frame = $ allowed_location ->getAllowedTimeFrameById ($ allowed_day_id );
153
207
154
208
if (is_null ($ time_frame ))
155
209
throw new EntityNotFoundException (sprintf ("Allowed Day %s not found " , $ allowed_day_id ));
156
210
157
- $ alloqed_location ->removeAllowedTimeFrame ($ time_frame );
211
+ $ allowed_location ->removeAllowedTimeFrame ($ time_frame );
158
212
159
213
});
160
214
}
@@ -168,11 +222,11 @@ public function deleteAllowedDayToProposedLocation(PresentationCategory $track,
168
222
public function deleteAllAllowedDayToProposedLocation (PresentationCategory $ track , int $ allowed_location_id ): void
169
223
{
170
224
$ 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 ))
173
227
throw new EntityNotFoundException (sprintf ("Allowed Location %s not found " , $ allowed_location_id ));
174
228
175
- $ alloqed_location ->clearAllowedTimeFrames ();
229
+ $ allowed_location ->clearAllowedTimeFrames ();
176
230
177
231
});
178
232
}
0 commit comments