35 lines
697 B
PHP
35 lines
697 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
final class ReservationService
|
||
|
|
{
|
||
|
|
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getReservation($id)
|
||
|
|
{
|
||
|
|
$model = Reservation::findOne($id);
|
||
|
|
|
||
|
|
if (!$model) {
|
||
|
|
throw new \Exception('Not found');
|
||
|
|
}
|
||
|
|
|
||
|
|
return $model;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function saveImage(Reservation $reservation, $name, $path)
|
||
|
|
{
|
||
|
|
ReservationImage::createImage($reservation, $name, $path);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function reservate(Reservation $reservation, array $images)
|
||
|
|
{
|
||
|
|
if ($reservation->save()) {
|
||
|
|
foreach ($images as $name => $path) {
|
||
|
|
$this->saveImage($reservation, $name, $path);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|