Skip to content

Commit bc8c388

Browse files
committed
Fixed validation rules for allowed locations
Signed-off-by: smarcet@gmail.com <smarcet@gmail.com> Change-Id: Ifae013f53336d0d7c9d8cb90dd194a5f1535a479
1 parent 114cabb commit bc8c388

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

app/Services/Model/Imp/SummitProposedScheduleAllowedLocationService.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use models\exceptions\EntityNotFoundException;
2020
use models\exceptions\ValidationException;
2121
use models\summit\PresentationCategory;
22+
use models\summit\SummitVenue;
2223

2324
/**
2425
* Class SummitProposedScheduleAllowedLocationService
@@ -41,7 +42,11 @@ public function addProposedLocationToTrack(PresentationCategory $track, array $p
4142
$location_id = intval($payload['location_id']);
4243
$location = $track->getSummit()->getLocation($location_id);
4344
if(is_null($location))
44-
throw new EntityNotFoundException(sprintf("location %s not found", $location_id));
45+
throw new EntityNotFoundException(sprintf("Location %s not found.", $location_id));
46+
47+
if($location->getClassName() === SummitVenue::ClassName){
48+
throw new ValidationException("Location is a Venue, you can not add a venue to a track.");
49+
}
4550

4651
return $track->addProposedScheduleAllowedLocation($location);
4752
});
@@ -75,9 +80,13 @@ public function addAllowedDayToProposedLocation(PresentationCategory $track, int
7580
{
7681
return $this->tx_service->transaction(function() use($track, $allowed_location_id, $payload){
7782

78-
$location = $track->getAllowedLocationById($allowed_location_id);
79-
if(is_null($location))
80-
throw new EntityNotFoundException(sprintf("Allowed Location %s not found", $allowed_location_id));
83+
$alloqed_location = $track->getAllowedLocationById($allowed_location_id);
84+
if(is_null($alloqed_location))
85+
throw new EntityNotFoundException(sprintf("Allowed Location %s not found.", $allowed_location_id));
86+
87+
if($alloqed_location->getLocation()->getClassName() === SummitVenue::ClassName){
88+
throw new ValidationException("Location is a Venue, you can not add a venue to a track.");
89+
}
8190

8291
$summit = $track->getSummit();
8392
$day = intval($payload['day']);
@@ -99,7 +108,7 @@ public function addAllowedDayToProposedLocation(PresentationCategory $track, int
99108
)
100109
);
101110

102-
return $location->addAllowedTimeFrame($day, $payload['opening_hour'] ?? null, $payload['closing_hour'] ?? null);
111+
return $alloqed_location->addAllowedTimeFrame($day, $payload['opening_hour'] ?? null, $payload['closing_hour'] ?? null);
103112
});
104113
}
105114

@@ -114,11 +123,11 @@ public function addAllowedDayToProposedLocation(PresentationCategory $track, int
114123
public function updateAllowedDayToProposedLocation(PresentationCategory $track, int $allowed_location_id, int $allowed_day_id, array $payload): ?SummitProposedScheduleAllowedDay
115124
{
116125
return $this->tx_service->transaction(function() use($track, $allowed_location_id, $allowed_day_id){
117-
$location = $track->getAllowedLocationById($allowed_location_id);
118-
if(is_null($location))
126+
$alloqed_location = $track->getAllowedLocationById($allowed_location_id);
127+
if(is_null($alloqed_location))
119128
throw new EntityNotFoundException(sprintf("Allowed Location %s not found", $allowed_location_id));
120129

121-
$time_frame = $location->getAllowedTimeFrameById($allowed_day_id);
130+
$time_frame = $alloqed_location->getAllowedTimeFrameById($allowed_day_id);
122131

123132
if(is_null($time_frame))
124133
throw new EntityNotFoundException(sprintf("Allowed Day %s not found", $allowed_day_id));
@@ -136,16 +145,16 @@ public function updateAllowedDayToProposedLocation(PresentationCategory $track,
136145
public function deleteAllowedDayToProposedLocation(PresentationCategory $track, int $allowed_location_id, int $allowed_day_id): void
137146
{
138147
$this->tx_service->transaction(function() use($track, $allowed_location_id, $allowed_day_id){
139-
$location = $track->getAllowedLocationById($allowed_location_id);
140-
if(is_null($location))
148+
$alloqed_location = $track->getAllowedLocationById($allowed_location_id);
149+
if(is_null($alloqed_location))
141150
throw new EntityNotFoundException(sprintf("Allowed Location %s not found", $allowed_location_id));
142151

143-
$time_frame = $location->getAllowedTimeFrameById($allowed_day_id);
152+
$time_frame = $alloqed_location->getAllowedTimeFrameById($allowed_day_id);
144153

145154
if(is_null($time_frame))
146155
throw new EntityNotFoundException(sprintf("Allowed Day %s not found", $allowed_day_id));
147156

148-
$location->removeAllowedTimeFrame($time_frame);
157+
$alloqed_location->removeAllowedTimeFrame($time_frame);
149158

150159
});
151160
}
@@ -159,11 +168,11 @@ public function deleteAllowedDayToProposedLocation(PresentationCategory $track,
159168
public function deleteAllAllowedDayToProposedLocation(PresentationCategory $track, int $allowed_location_id): void
160169
{
161170
$this->tx_service->transaction(function() use($track, $allowed_location_id){
162-
$location = $track->getAllowedLocationById($allowed_location_id);
163-
if(is_null($location))
171+
$alloqed_location = $track->getAllowedLocationById($allowed_location_id);
172+
if(is_null($alloqed_location))
164173
throw new EntityNotFoundException(sprintf("Allowed Location %s not found", $allowed_location_id));
165174

166-
$location->clearAllowedTimeFrames();
175+
$alloqed_location->clearAllowedTimeFrames();
167176

168177
});
169178
}

0 commit comments

Comments
 (0)