Passed
Push — master ( b9be5f...21ff9a )
by Adam
06:24
created

ReservationController   B

Complexity

Total Complexity 49

Size/Duplication

Total Lines 594
Duplicated Lines 0 %

Test Coverage

Coverage 81.93%

Importance

Changes 0
Metric Value
dl 0
loc 594
ccs 272
cts 332
cp 0.8193
rs 8.5454
c 0
b 0
f 0
wmc 49

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B editChangeRoom() 0 28 3
B showEditForm() 0 29 2
B getFields() 0 39 4
A editChangeGuest() 0 19 2
B getActionButtons() 0 28 1
B add() 0 46 4
A future() 0 23 2
A getGuestField() 0 10 1
A current() 0 23 2
A chooseGuest() 0 20 2
A index() 0 22 2
A getRoomField() 0 10 1
B postEdit() 0 49 4
A delete() 0 15 2
B searchFreeRooms() 0 27 2
B editChooseGuest() 0 31 3
B editChooseRoom() 0 35 3
A postSearchFreeRooms() 0 15 2
B chooseFreeRoom() 0 47 4
A isReservationDataInSessionCorrect() 0 11 2

How to fix   Complexity   

Complex Class

Complex classes like ReservationController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ReservationController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Interfaces\ManageTableInterface;
6
use App\Http\Requests\ReservationAddRequest;
7
use App\Http\Requests\ReservationEditRequest;
8
use App\Models\Guest;
9
use App\Models\Reservation;
10
use App\Models\Room;
11
use App\Services\GuestTableService;
12
use App\Services\ReservationTableService;
13
use App\Services\RoomTableService;
14
use Carbon\Carbon;
15
use Illuminate\Database\Eloquent\ModelNotFoundException;
16
use Illuminate\Database\Query\Builder;
17
use Illuminate\Support\Facades\DB;
18
use Illuminate\Support\Facades\Log;
19
use Illuminate\Support\Facades\Session;
20
21
class ReservationController extends Controller implements ManageTableInterface
22
{
23
    protected $reservationTableService;
24
25 22
    public function __construct(ReservationTableService $reservationTableService)
26
    {
27 22
        $this->reservationTableService = $reservationTableService;
28 22
    }
29
30 7
    public function index()
31
    {
32 7
        $title = trans('navigation.all_reservations');
33
34 7
        $dataset = Reservation::select('id', 'room_id', 'guest_id', 'date_start', 'date_end', 'people')
35 7
            ->with('guest:id,first_name,last_name')
36 7
            ->with('room:id,number')
37 7
            ->orderBy('date_end', 'DESC')
38 7
            ->paginate($this->getItemsPerPage());
39
40 7
        if ($dataset->isEmpty()) {
41 4
            $this->addFlashMessage(trans('general.no_reservations_in_database'), 'alert-danger');
42
        }
43
44
        $viewData = [
45 7
            'columns'       => $this->reservationTableService->getColumns(),
46 7
            'dataset'       => $dataset,
47 7
            'routeName'     => $this->reservationTableService->getRouteName(),
48 7
            'title'         => $title,
49
        ];
50
51 7
        return view('list', $viewData);
52
    }
53
54 2
    public function current()
55
    {
56 2
        $title = trans('navigation.current_reservations');
57
58 2
        $dataset = Reservation::select('id', 'room_id', 'guest_id', 'date_start', 'date_end', 'people')
59 2
            ->with('guest:id,first_name,last_name')
60 2
            ->with('room:id,number')
61 2
            ->getCurrentReservations()
62 2
            ->orderBy('date_end')
63 2
            ->paginate($this->getItemsPerPage());
64
65 2
        if ($dataset->isEmpty()) {
66 1
            $this->addFlashMessage(trans('general.no_reservations_in_database'), 'alert-danger');
67
        }
68
69
        $viewData = [
70 2
            'columns'       => $this->reservationTableService->getColumns(),
71 2
            'dataset'       => $dataset,
72 2
            'routeName'     => $this->reservationTableService->getRouteName(),
73 2
            'title'         => $title,
74
        ];
75
76 2
        return view('list', $viewData);
77
    }
78
79 2
    public function future()
80
    {
81 2
        $title = trans('navigation.future_reservations');
82
83 2
        $dataset = Reservation::select('id', 'room_id', 'guest_id', 'date_start', 'date_end', 'people')
84 2
            ->with('guest:id,first_name,last_name')
85 2
            ->with('room:id,number')
86 2
            ->getFutureReservations()
87 2
            ->orderBy('date_end')
88 2
            ->paginate($this->getItemsPerPage());
89
90 2
        if ($dataset->isEmpty()) {
91 1
            $this->addFlashMessage(trans('general.no_reservations_in_database'), 'alert-danger');
92
        }
93
94
        $viewData = [
95 2
            'columns'       => $this->reservationTableService->getColumns(),
96 2
            'dataset'       => $dataset,
97 2
            'routeName'     => $this->reservationTableService->getRouteName(),
98 2
            'title'         => $title,
99
        ];
100
101 2
        return view('list', $viewData);
102
    }
103
104 3
    public function chooseGuest(GuestTableService $guestTableService)
105
    {
106 3
        $title = trans('navigation.choose_guest');
107
108 3
        $dataset = Guest::select('id', 'first_name', 'last_name', 'address', 'zip_code', 'place', 'PESEL', 'contact')
109 3
            ->paginate($this->getItemsPerPage());
110
111 3
        if ($dataset->isEmpty()) {
112 1
            $this->addFlashMessage(trans('general.no_guests_in_database'), 'alert-danger');
113
        }
114
115
        $viewData = [
116 3
            'columns'         => $guestTableService->getColumns(),
117 3
            'dataset'         => $dataset,
118 3
            'routeName'       => $guestTableService->getRouteName(),
119 3
            'title'           => $title,
120 3
            'routeChooseName' => $this->reservationTableService->getRouteName().'.search_free_rooms',
121
        ];
122
123 3
        return view('list', $viewData);
124
    }
125
126 4
    public function searchFreeRooms($guestId)
127
    {
128
        try {
129 4
            $guest = Guest::select('id', 'first_name', 'last_name')->findOrFail($guestId);
130 1
        } catch (ModelNotFoundException $e) {
131 1
            return $this->returnBack([
132 1
                'message'     => trans('general.object_not_found'),
133 1
                'alert-class' => 'alert-danger',
134
            ]);
135
        }
136
137 3
        $dataset = new Reservation();
138 3
        $dataset->guest()->associate($guest);
139 3
        $title = trans('navigation.search_free_rooms');
140 3
        $submitRoute = route($this->reservationTableService->getRouteName().'.post_search_free_rooms', $dataset->guest->id);
0 ignored issues
show
Bug introduced by
$dataset->guest->id of type integer is incompatible with the type array expected by parameter $parameters of route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

140
        $submitRoute = route($this->reservationTableService->getRouteName().'.post_search_free_rooms', /** @scrutinizer ignore-type */ $dataset->guest->id);
Loading history...
141
142 3
        $fiels = $this->getFields(true);
143 3
        array_unshift($fiels, $this->getGuestField());
144
145
        $viewData = [
146 3
            'dataset'     => $dataset,
147 3
            'fields'      => $fiels,
148 3
            'title'       => $title,
149 3
            'submitRoute' => $submitRoute,
150
        ];
151
152 3
        return view('addedit', $viewData);
153
    }
154
155 3
    public function postSearchFreeRooms(ReservationAddRequest $request, $guestId = null)
156
    {
157
        try {
158 3
            $guest = Guest::select('id')->findOrFail($guestId);
159 1
        } catch (ModelNotFoundException $e) {
160 1
            return $this->returnBack([
161 1
                'message'     => trans('general.object_not_found'),
162 1
                'alert-class' => 'alert-danger',
163
            ]);
164
        }
165
166 2
        $data = $request->only(['date_start', 'date_end', 'people']);
167
168 2
        return redirect()->route($this->reservationTableService->getRouteName().'.choose_free_room', $guest->id)
0 ignored issues
show
Bug introduced by
$guest->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

168
        return redirect()->route($this->reservationTableService->getRouteName().'.choose_free_room', /** @scrutinizer ignore-type */ $guest->id)
Loading history...
169 2
            ->with($data);
170
    }
171
172
    /**
173
     * @param RoomTableService $roomTableService
174
     * @param int              $guestId
175
     *
176
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
177
     */
178 3
    public function chooseFreeRoom(RoomTableService $roomTableService, $guestId)
179
    {
180 3
        if (!$this->isReservationDataInSessionCorrect()) {
181 1
            return $this->returnBack([
182 1
                'message'     => trans('general.object_not_found'),
183 1
                'alert-class' => 'alert-danger',
184
            ]);
185
        }
186
187
        try {
188 2
            $guest = Guest::select('id', 'first_name', 'last_name')->findOrFail($guestId);
189
        } catch (ModelNotFoundException $e) {
190
            Log::warning(__CLASS__.'::'.__FUNCTION__.' at '.__LINE__.': '.$e->getMessage());
191
192
            return $this->returnBack([
193
                'message'     => trans('general.object_not_found'),
194
                'alert-class' => 'alert-danger',
195
            ]);
196
        }
197
198 2
        $dateStart = Session::get('date_start');
199 2
        $dateEnd = Session::get('date_end');
200 2
        $people = Session::get('people');
201
202 2
        $dateStart = Carbon::parse($dateStart);
203 2
        $dateEnd = Carbon::parse($dateEnd);
204
205 2
        $title = trans('navigation.choose_room_for').' '.$guest->fullName;
0 ignored issues
show
Bug introduced by
Are you sure trans('navigation.choose_room_for') of type null|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

205
        $title = /** @scrutinizer ignore-type */ trans('navigation.choose_room_for').' '.$guest->fullName;
Loading history...
206
207 2
        $dataset = Room::select('id', 'number', 'floor', 'capacity', 'price', 'comment')
208 2
            ->freeRoomsForReservation($dateStart, $dateEnd, $people)
209 2
            ->paginate($this->getItemsPerPage());
210
211 2
        if ($dataset->isEmpty()) {
212 1
            $this->addFlashMessage(trans('general.no_rooms_in_database'), 'alert-danger');
213
        }
214
215
        $viewData = [
216 2
            'columns'               => $roomTableService->getColumns(),
217 2
            'dataset'               => $dataset,
218 2
            'routeName'             => $roomTableService->getRouteName(),
219 2
            'title'                 => $title,
220 2
            'routeChooseName'       => $this->reservationTableService->getRouteName().'.add',
221 2
            'additionalRouteParams' => $guest->id,
222
        ];
223
224 2
        return view('list', $viewData);
225
    }
226
227 1
    public function add($guestId, $roomId)
228
    {
229 1
        if (!$this->isReservationDataInSessionCorrect()) {
230
            return $this->returnBack([
231
                'message'     => trans('general.object_not_found'),
232
                'alert-class' => 'alert-danger',
233
            ]);
234
        }
235
236 1
        $dateStart = Session::get('date_start');
237 1
        $dateEnd = Session::get('date_end');
238 1
        $people = Session::get('people');
239
240
        try {
241 1
            $guest = Guest::select('id')->findOrFail($guestId);
242 1
            $room = Room::select('id', 'capacity')->findOrFail($roomId);
243
        } catch (ModelNotFoundException $e) {
244
            Log::warning(__CLASS__.'::'.__FUNCTION__.' at '.__LINE__.': '.$e->getMessage());
245
246
            return $this->returnBack([
247
                'message'     => trans('general.object_not_found'),
248
                'alert-class' => 'alert-danger',
249
            ]);
250
        }
251
252 1
        if ($room->capacity < $people) {
253
            return $this->returnBack([
254
                'message'     => trans('general.people_exceeds_room_capacity'),
255
                'alert-class' => 'alert-danger',
256
            ]);
257
        }
258
259
        // TODO: Check if room is free
260
261 1
        $reservation = new Reservation();
262 1
        $reservation->guest_id = $guest->id;
263 1
        $reservation->room_id = $room->id;
264 1
        $reservation->date_start = $dateStart;
265 1
        $reservation->date_end = $dateEnd;
266 1
        $reservation->people = $people;
267
268 1
        $reservation->save();
269
270 1
        $this->addFlashMessage(trans('general.saved'), 'alert-success');
271
272 1
        return redirect()->route($this->reservationTableService->getRouteName().'.index');
273
    }
274
275 2
    public function postEdit(ReservationEditRequest $request, $objectId)
276
    {
277
        try {
278 2
            $object = Reservation::with('room:id,capacity')
279 2
                ->findOrFail($objectId);
280 1
        } catch (ModelNotFoundException $e) {
281 1
            return $this->returnBack([
282 1
                'message'     => trans('general.object_not_found'),
283 1
                'alert-class' => 'alert-danger',
284
            ]);
285
        }
286
287
        // Check room capacity for people in reservation
288 1
        if ($object->room->capacity < $request->input('people')) {
289
            return redirect()->back()->with([
290
                'message'     => trans('general.people_exceeds_room_capacity'),
291
                'alert-class' => 'alert-danger',
292
            ]);
293
        }
294
295 1
        $dateStart = Carbon::parse($request->input('date_start'));
296 1
        $dateEnd = Carbon::parse($request->input('date_end'));
297
298
        // Check if dates can be changed
299 1
        $reservationsIdsForDates = DB::table('reservations')
300 1
            ->where('room_id', $object->room_id)
301 1
            ->where('id', '!=', $object->id)
302
            ->where(function (Builder $query) use ($dateStart, $dateEnd) {
303 1
                $query->where(function (Builder $query) use ($dateStart, $dateEnd) {
304 1
                    $query->where('date_start', '<', $dateEnd)
305 1
                        ->where('date_end', '>', $dateStart);
306 1
                });
307 1
            })
308 1
            ->count();
309
310 1
        if ($reservationsIdsForDates > 0) {
311
            return redirect()->back()->with([
312
                'message'     => trans('general.dates_coincide_different_booking'),
313
                'alert-class' => 'alert-danger',
314
            ]);
315
        }
316
317 1
        $object->fill($request->all());
318 1
        $object->save();
319
320 1
        return redirect()->route($this->reservationTableService->getRouteName().'.index')
321 1
            ->with([
322 1
                'message'     => trans('general.saved'),
323 1
                'alert-class' => 'alert-success',
324
            ]);
325
    }
326
327 2
    public function delete($objectId)
328
    {
329
        try {
330 2
            $object = Reservation::findOrFail($objectId);
331 1
        } catch (ModelNotFoundException $e) {
332 1
            $data = ['class' => 'alert-danger', 'message' => trans('general.object_not_found')];
333
334 1
            return response()->json($data);
335
        }
336
337 1
        $object->delete();
338
339 1
        $data = ['class' => 'alert-success', 'message' => trans('general.deleted')];
340
341 1
        return response()->json($data);
342
    }
343
344 5
    public function showEditForm($objectId)
345
    {
346
        try {
347 5
            $dataset = Reservation::select('id', 'room_id', 'guest_id', 'date_start', 'date_end', 'people')
348 5
            ->with('guest:id,first_name,last_name')
349 5
            ->with('room:id,number')
350 5
            ->findOrFail($objectId);
351 1
        } catch (ModelNotFoundException $e) {
352 1
            return $this->returnBack([
353 1
                'message'     => trans('general.object_not_found'),
354 1
                'alert-class' => 'alert-danger',
355
            ]);
356
        }
357
358 4
        $title = trans('navigation.edit_reservation');
359 4
        $submitRoute = route($this->reservationTableService->getRouteName().'.postedit', $objectId);
360
361 4
        $fiels = $this->getFields();
362 4
        array_unshift($fiels, $this->getGuestField(), $this->getRoomField(), $this->getActionButtons());
363
364
        $viewData = [
365 4
            'dataset'     => $dataset,
366 4
            'fields'      => $fiels,
367 4
            'title'       => $title,
368 4
            'submitRoute' => $submitRoute,
369 4
            'routeName'   => $this->reservationTableService->getRouteName(),
370
        ];
371
372 4
        return view('addedit', $viewData);
373
    }
374
375 1
    public function editChooseGuest(GuestTableService $guestTableService, $reservationId)
376
    {
377
        try {
378 1
            $reservation = Reservation::select('id', 'guest_id')->findOrFail($reservationId);
379
        } catch (ModelNotFoundException $e) {
380
            return $this->returnBack([
381
                'message'     => trans('general.object_not_found'),
382
                'alert-class' => 'alert-danger',
383
            ]);
384
        }
385
386 1
        $title = trans('navigation.change_guest_for_reservation');
387
388 1
        $dataset = Guest::select('id', 'first_name', 'last_name', 'address', 'zip_code', 'place', 'PESEL', 'contact')
389 1
            ->whereNotIn('id', [$reservation->guest_id])
390 1
            ->paginate($this->getItemsPerPage());
391
392 1
        if ($dataset->isEmpty()) {
393 1
            $this->addFlashMessage(trans('general.no_guests_in_database'), 'alert-danger');
394
        }
395
396
        $viewData = [
397 1
            'columns'               => $guestTableService->getColumns(),
398 1
            'dataset'               => $dataset,
399 1
            'routeName'             => $guestTableService->getRouteName(),
400 1
            'title'                 => $title,
401 1
            'routeChooseName'       => $this->reservationTableService->getRouteName().'.edit_change_guest',
402 1
            'additionalRouteParams' => $reservation->id,
403
        ];
404
405 1
        return view('list', $viewData);
406
    }
407
408
    public function editChangeGuest($reservationId, $guestId)
409
    {
410
        try {
411
            $reservation = Reservation::select('id')->findOrFail($reservationId);
412
            $guest = Guest::select('id')->findOrFail($guestId);
413
        } catch (ModelNotFoundException $e) {
414
            return $this->returnBack([
415
                'message'     => trans('general.object_not_found'),
416
                'alert-class' => 'alert-danger',
417
            ]);
418
        }
419
420
        $reservation->guest_id = $guest->id;
421
        $reservation->save();
422
423
        return redirect()->route($this->reservationTableService->getRouteName().'.editform', $reservation->id)
0 ignored issues
show
Bug introduced by
$reservation->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

423
        return redirect()->route($this->reservationTableService->getRouteName().'.editform', /** @scrutinizer ignore-type */ $reservation->id)
Loading history...
424
            ->with([
425
                'message'     => trans('general.saved'),
426
                'alert-class' => 'alert-success',
427
            ]);
428
    }
429
430 1
    public function editChooseRoom(RoomTableService $roomTableService, $reservationId)
431
    {
432
        try {
433 1
            $reservation = Reservation::select('id', 'guest_id', 'date_start', 'date_end', 'people')
434 1
                ->findOrFail($reservationId);
435
        } catch (ModelNotFoundException $e) {
436
            return $this->returnBack([
437
                'message'     => trans('general.object_not_found'),
438
                'alert-class' => 'alert-danger',
439
            ]);
440
        }
441
442 1
        $dateStart = Carbon::parse($reservation->date_start);
443 1
        $dateEnd = Carbon::parse($reservation->date_end);
444
445 1
        $title = trans('navigation.change_room_for_reservation');
446
447 1
        $dataset = Room::select('id', 'number', 'floor', 'capacity', 'price', 'comment')
448 1
            ->freeRoomsForReservation($dateStart, $dateEnd, $reservation->people)
449 1
            ->paginate($this->getItemsPerPage());
450
451 1
        if ($dataset->isEmpty()) {
452 1
            $this->addFlashMessage(trans('general.no_rooms_in_database'), 'alert-danger');
453
        }
454
455
        $viewData = [
456 1
            'columns'               => $roomTableService->getColumns(),
457 1
            'dataset'               => $dataset,
458 1
            'routeName'             => $roomTableService->getRouteName(),
459 1
            'title'                 => $title,
460 1
            'routeChooseName'       => $this->reservationTableService->getRouteName().'.edit_change_room',
461 1
            'additionalRouteParams' => $reservation->id,
462
        ];
463
464 1
        return view('list', $viewData);
465
    }
466
467
    public function editChangeRoom($reservationId, $roomId)
468
    {
469
        try {
470
            $reservation = Reservation::select('id', 'people')->findOrFail($reservationId);
471
            $room = Room::select('id', 'capacity')->findOrFail($roomId);
472
        } catch (ModelNotFoundException $e) {
473
            return $this->returnBack([
474
                'message'     => trans('general.object_not_found'),
475
                'alert-class' => 'alert-danger',
476
            ]);
477
        }
478
479
        if ($room->capacity < $reservation->people) {
480
            return $this->returnBack([
481
                'message'     => trans('general.people_exceeds_room_capacity'),
482
                'alert-class' => 'alert-danger',
483
            ]);
484
        }
485
486
        // TODO: Check if room is free
487
488
        $reservation->room_id = $room->id;
489
        $reservation->save();
490
491
        return redirect()->route($this->reservationTableService->getRouteName().'.editform', $reservation->id)
0 ignored issues
show
Bug introduced by
$reservation->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

491
        return redirect()->route($this->reservationTableService->getRouteName().'.editform', /** @scrutinizer ignore-type */ $reservation->id)
Loading history...
492
            ->with([
493
                'message'     => trans('general.saved'),
494
                'alert-class' => 'alert-success',
495
            ]);
496
    }
497
498 7
    public function getGuestField()
499
    {
500
        return [
501 7
            'id'    => 'guest',
502 7
            'title' => trans('general.guest'),
503 7
            'value' => function (Reservation $data) {
504 7
                return $data->guest->full_name;
505 7
            },
506
            'optional' => [
507
                'readonly' => 'readonly',
508
            ],
509
        ];
510
    }
511
512 4
    public function getRoomField()
513
    {
514
        return [
515 4
            'id'    => 'room',
516 4
            'title' => trans('general.room'),
517 4
            'value' => function (Reservation $data) {
518 4
                return $data->room->number;
519 4
            },
520
            'optional' => [
521
                'readonly' => 'readonly',
522
            ],
523
        ];
524
    }
525
526 4
    public function getActionButtons()
527
    {
528
        return [
529 4
            'id'         => 'action_buttons',
530 4
            'type'       => 'buttons',
531
            'buttons'    => [
532
                [
533 4
                    'value' => function () {
534 4
                        return 'Zmień gościa';
535 4
                    },
536 4
                    'route_name'  => 'reservation.edit_choose_guest',
537 4
                    'route_param' => function (Reservation $data) {
538 4
                        return $data->id;
539 4
                    },
540
                    'optional' => [
541
                        'class' => 'btn btn-primary',
542
                    ],
543
                ],
544
                [
545 4
                    'value' => function () {
546 4
                        return 'Zmień pokój';
547 4
                    },
548 4
                    'route_name'  => 'reservation.edit_choose_room',
549 4
                    'route_param' => function (Reservation $data) {
550 4
                        return $data->id;
551 4
                    },
552
                    'optional' => [
553
                        'class' => 'btn btn-primary',
554
                    ],
555
                ],
556
            ],
557
        ];
558
    }
559
560 7
    public function getFields($forAdd = false)
561
    {
562
        return [
563
            [
564 7
                'id'    => 'date_start',
565 7
                'title' => trans('general.date_start'),
566 7
                'value' => function (Reservation $data) {
567 7
                    return $data->date_start;
568 7
                },
569 7
                'type'     => 'text',
570
                'optional' => [
571 7
                    'required'    => 'required',
572 7
                    'class'       => 'datepicker'.($forAdd ? ' start-date' : null),
573 7
                    'placeholder' => 'dd.mm.rrrr',
574
                ],
575
            ],
576
            [
577 7
                'id'    => 'date_end',
578 7
                'title' => trans('general.date_end'),
579 7
                'value' => function (Reservation $data) {
580 7
                    return $data->date_end;
581 7
                },
582 7
                'type'     => 'text',
583
                'optional' => [
584 7
                    'required'    => 'required',
585 7
                    'class'       => 'datepicker'.($forAdd ? ' end-date' : null),
586 7
                    'placeholder' => 'dd.mm.rrrr',
587
                ],
588
            ],
589
            [
590 7
                'id'    => 'people',
591 7
                'title' => trans('general.number_of_people'),
592 7
                'value' => function (Reservation $data) {
593 7
                    return $data->people ?: 1;
594 7
                },
595 7
                'type'     => 'number',
596
                'optional' => [
597
                    'required' => 'required',
598
                    'min'      => '1',
599
                ],
600
            ],
601
        ];
602
    }
603
604 3
    private function isReservationDataInSessionCorrect()
605
    {
606 3
        if (!Session::has(['date_start', 'date_end', 'people'])) {
607 1
            Log::error('Missing one of Session keys: date_start, date_end, people');
608
609 1
            return false;
610
        }
611
612 2
        Session::reflash();
613
614 2
        return true;
615
    }
616
}
617