Skip to content

Commit c842b09

Browse files
committed
Proposed Allowed location Fixes
* added login info * fixed validation issues Signed-off-by: [email protected] <[email protected]> Change-Id: I960134a985c998364a44c513b8dc1506828b487b
1 parent ea76e95 commit c842b09

File tree

5 files changed

+134
-26
lines changed

5 files changed

+134
-26
lines changed

app/Models/Foundation/Summit/ProposedSchedule/SummitProposedScheduleAllowedLocation.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,31 @@ public function clearLocation():void{
138138
*/
139139
public function addAllowedTimeFrame(\DateTime $day, ?int $opening_hour = null, ?int $closing_hour = null):?SummitProposedScheduleAllowedDay{
140140

141+
Log::debug
142+
(
143+
sprintf
144+
(
145+
"SummitProposedScheduleAllowedLocation::addAllowedTimeFrame location %s day %s opening_hour %s closing_hour %s",
146+
$this->location->getId(),
147+
$day->format("Y-m-d H:i:s"),
148+
$opening_hour,
149+
$closing_hour
150+
)
151+
);
152+
141153
$criteria = Criteria::create();
142154
$criteria->where(Criteria::expr()->eq('day', $day));
143155

144156
if($this->allowed_timeframes->matching($criteria)->count() > 0 ){
145-
throw new ValidationException(sprintf("Day %s already exists for location %s.", $day->format("Y-m-d"), $this->location->getId()));
157+
throw new ValidationException
158+
(
159+
sprintf
160+
(
161+
"Day %s already exists for location %s.",
162+
$day->format("Y-m-d"),
163+
$this->location->getId()
164+
)
165+
);
146166
}
147167

148168
$time_frame = new SummitProposedScheduleAllowedDay($this, $day, $opening_hour, $closing_hour);
@@ -192,7 +212,7 @@ public function getAllowedTimeFrameForDates(\DateTime $from, \DateTime $to):?Sum
192212
$day = clone $from;
193213
$localDay = $summit->convertDateFromUTC2TimeZone($day);
194214
// clear time on local day
195-
$localDay = $localDay->setTime(0,0,0);
215+
$localDay = $localDay->setTime(0,0,0,0);
196216

197217
Log::debug
198218
(

app/Models/Foundation/Summit/Summit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4358,7 +4358,7 @@ public function dayIsOnSummitPeriod(\DateTime $day, $omit_time_check = true): bo
43584358
$dt = $dt->setTimezone(new \DateTimeZone('UTC'));
43594359

43604360
if ($omit_time_check)
4361-
$dt = $dt->setTime(0, 0, 0);
4361+
$dt = $dt->setTime(0, 0, 0,0);
43624362

43634363
$dt = $dt->getTimestamp();
43644364

@@ -4376,6 +4376,7 @@ public function dayIsOnSummitPeriod(\DateTime $day, $omit_time_check = true): bo
43764376

43774377
$ed = $ed->getTimestamp();
43784378

4379+
Log::debug(sprintf("Summit::dayIsOnSummitPeriod bd %s ed %s dt %s", $bd, $ed, $dt));
43794380
return $bd <= $dt && $dt <= $ed;
43804381
}
43814382

app/Services/Model/Imp/ScheduleService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected function validateBlackOutTimesAndTimes(IPublishableEvent $publishable_
212212
(
213213
"ScheduleService::validateBlackOutTimesAndTimes location %s has custom restriction for date %s opening_hour %s closing_hour %s",
214214
$location->getId(),
215-
$publishable_event->getStartDate()->format("Y-m-d"),
215+
$publishable_event->getStartDate()->format("Y-m-d H:i:s"),
216216
$opening_hour,
217217
$closing_hour
218218
)

app/Services/Model/Imp/SummitProposedScheduleAllowedLocationService.php

Lines changed: 76 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use App\Models\Foundation\Summit\ProposedSchedule\SummitProposedScheduleAllowedLocation;
1717
use App\Services\Model\AbstractService;
1818
use App\Services\Model\ISummitProposedScheduleAllowedLocationService;
19+
use App\Utils\Time;
20+
use Illuminate\Support\Facades\Log;
1921
use models\exceptions\EntityNotFoundException;
2022
use models\exceptions\ValidationException;
2123
use 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
}

app/Utils/Time.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace App\Utils;
2+
/*
3+
* Copyright 2023 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+
/**
17+
* Class Time
18+
* @package App\Utils
19+
*/
20+
final class Time
21+
{
22+
/**
23+
* @param int $time
24+
* @return array
25+
*/
26+
public static function getHourAndMinutesFromInt(int $time):array
27+
{
28+
$time = sprintf("%04d", $time);
29+
$hours = intval(substr($time,0,2));
30+
$minutes = intval(substr($time,2,2));
31+
return [$hours, $minutes];
32+
}
33+
}

0 commit comments

Comments
 (0)