|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use App\Http\Requests\Admin\CreateUpdateSeatMap; |
|
7
|
|
|
use App\Location; |
|
8
|
|
|
use App\PriceCategory; |
|
9
|
|
|
use App\PriceList; |
|
10
|
|
|
use App\SeatMap; |
|
11
|
|
|
use Illuminate\Support\Facades\Log; |
|
12
|
|
|
|
|
13
|
|
|
class SeatMapController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
public function index() |
|
16
|
|
|
{ |
|
17
|
|
|
return view('admin.dependencies.index', [ |
|
18
|
|
|
'seatmaps' => SeatMap::all(), |
|
19
|
|
|
'locations' => Location::all(), |
|
20
|
|
|
'pricecategories' => PriceCategory::all(), |
|
21
|
|
|
'pricelists' => PriceList::all() |
|
22
|
|
|
]); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function create(CreateUpdateSeatMap $request) |
|
26
|
|
|
{ |
|
27
|
|
|
// Creation is always without a layout |
|
28
|
|
|
$validated = $request->validated(); |
|
29
|
|
|
$seatMap = SeatMap::create([ |
|
30
|
|
|
'name' => $validated['name'], |
|
31
|
|
|
'description' => $validated['description'], |
|
32
|
|
|
'seats' => $validated['seats'] |
|
33
|
|
|
]); |
|
34
|
|
|
// On successfull creation redirect the browser to the overview |
|
35
|
|
|
return redirect() |
|
36
|
|
|
->route('admin.dependencies.seatmap.get', $seatMap) |
|
37
|
|
|
->with('status', 'Created ' . $seatMap->name . '!'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function get(SeatMap $seatMap) |
|
41
|
|
|
{ |
|
42
|
|
|
return view('admin.dependencies.manage-seatmap', ['seatmap' => $seatMap]); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function update(SeatMap $seatMap, CreateUpdateSeatMap $request) |
|
46
|
|
|
{ |
|
47
|
|
|
$validated = $request->validated(); |
|
48
|
|
|
|
|
49
|
|
|
$seatMap->name = $validated['name']; |
|
50
|
|
|
$seatMap->description = $validated['description']; |
|
51
|
|
|
$seatMap->seats = $validated['seats']; |
|
52
|
|
|
|
|
53
|
|
|
if( !empty(json_decode($validated['layout'])) ) |
|
54
|
|
|
{ |
|
55
|
|
|
$numberOfSeatsInLayout = preg_match_all('/a/', $validated['layout']); |
|
56
|
|
|
if($numberOfSeatsInLayout != $validated['seats']) { |
|
57
|
|
|
return redirect() |
|
58
|
|
|
->route('admin.dependencies.seatmap.get', $seatMap) |
|
59
|
|
|
->with('status', 'Counted seats of layout (' . $numberOfSeatsInLayout . ') does not match the given seats (' . $validated['seats'] . ')!'); |
|
60
|
|
|
} |
|
61
|
|
|
$seatMap->layout = $validated['layout']; |
|
62
|
|
|
} else { |
|
63
|
|
|
$seatMap->layout = null; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$seatMap->save(); |
|
67
|
|
|
|
|
68
|
|
|
// On successfull update redirect the browser to the overview |
|
69
|
|
|
return redirect() |
|
70
|
|
|
->route('admin.dependencies.seatmap.get', $seatMap) |
|
71
|
|
|
->with('status', 'Updated ' . $seatMap->name . '!'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function delete(SeatMap $seatMap) |
|
75
|
|
|
{ |
|
76
|
|
|
Log::info('Deleting seatmap#' . $seatMap->id . ' (' . $seatMap->name . ')'); |
|
77
|
|
|
|
|
78
|
|
|
$seatMap->delete(); |
|
79
|
|
|
|
|
80
|
|
|
// On successfull deletion redirect the browser to the overview |
|
81
|
|
|
return redirect() |
|
82
|
|
|
->route('admin.dependencies.dashboard') |
|
83
|
|
|
->with('status', 'Deleted seatmap successfull!'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|