231 lines
7.3 KiB
PHP
231 lines
7.3 KiB
PHP
<?php
|
|
|
|
use App\ParkingLot;
|
|
use Google\Cloud\Firestore\FirestoreClient;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Web Routes
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Here is where you can register web routes for your application. These
|
|
| routes are loaded by the RouteServiceProvider within a group which
|
|
| contains the "web" middleware group. Now create something great!
|
|
|
|
|
*/
|
|
|
|
Route::get('/', function () {
|
|
return view('welcome');
|
|
});
|
|
|
|
Auth::routes();
|
|
|
|
Route::get('/home', 'HomeController@index')->name('home');
|
|
|
|
Route::get('/lot/selectstalls', function() { return view('selectstalls'); } );
|
|
|
|
Route::get('/lot/add', function() { return view('lot.add'); } );
|
|
Route::post('/lot/post', function(\Illuminate\Http\Request $request) {
|
|
/*$this->validate($request, [
|
|
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:4096',
|
|
]);*/
|
|
|
|
if ( $request->hasFile('image') ){
|
|
$img = $request->file('image');
|
|
$name = time() . '.' . $img->getClientOriginalExtension();
|
|
$destination_path = public_path('/img/references');
|
|
$img->move($destination_path, $name);
|
|
// $this->save();
|
|
|
|
$lot_object = new ParkingLot([
|
|
'firebase_id' => 'Lot',
|
|
'stall_coordinates' => '',
|
|
'ref_coords' => '',
|
|
'reference_image' => $name,
|
|
'number_of_columns' => $request->get('numcols'),
|
|
'name' => $request->get('name'),
|
|
]);
|
|
$lot_object->save();
|
|
|
|
$lot_object->firebase_id = 'Lot'.$lot_object->id;
|
|
$lot_object->save();
|
|
|
|
return view('selectstalls', [ 'image_name' => $name, 'lot_id' => $lot_object->id ]);
|
|
}
|
|
});
|
|
|
|
Route::post('/lot/generate', function(\Illuminate\Http\Request $request){
|
|
$lot_object = ParkingLot::find($request->get('lotid'));
|
|
$lot_object->stall_coordinates = $request->get('coords');
|
|
$lot_object->save();
|
|
|
|
$coordgroup = json_decode($request->get('coords'));
|
|
$coordarrs = [];
|
|
foreach( $coordgroup as $group ){
|
|
array_push($coordarrs, ['x'=>$group->x, 'y'=>$group->y, 'w'=>$group->w, 'h'=>$group->h]);
|
|
}
|
|
|
|
// var_dump($coordarrs);
|
|
|
|
usort($coordarrs, function($a, $b){
|
|
return $a['y'] <=> $b['y'];
|
|
});
|
|
|
|
// var_dump($coordarrs);
|
|
|
|
$coordarrs_chunks = array_chunk($coordarrs, $lot_object->number_of_columns);
|
|
|
|
foreach($coordarrs_chunks as $key=>$chunk ){
|
|
usort($chunk, function($a, $b) {
|
|
return $a['x'] <=> $b['x'];
|
|
});
|
|
$coordarrs_chunks[$key] = $chunk;
|
|
}
|
|
|
|
$stall_coords_1D = call_user_func_array('array_merge', $coordarrs_chunks);
|
|
$lot_object->stall_coordinates = json_encode($stall_coords_1D);
|
|
|
|
// dd([$coordarrs_chunks, $stall_coords_1D]);
|
|
|
|
|
|
$db = new FirestoreClient();
|
|
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id);
|
|
$doc_ref->set([]);
|
|
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id)->collection('info')->document('lotInfo');
|
|
$doc_ref->set([
|
|
'coordinates' => $lot_object->stall_coordinates,
|
|
'lotID' => $lot_object->id,
|
|
'refImage' => $lot_object->reference_image,
|
|
'tableLayout' => '',
|
|
'columns' => $lot_object->number_of_columns,
|
|
'name' => $lot_object->name
|
|
]);
|
|
|
|
// $coords = json_decode($lot_object->stall_coordinates);
|
|
$stall_no = 1;
|
|
foreach ($stall_coords_1D as $coord){
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id)->collection('stalls')->document('Stall-'.$stall_no);
|
|
$doc_ref->set([
|
|
'handicap' => false,
|
|
'locationX' => $coord['x'],
|
|
'locationY' => $coord['y'],
|
|
'open' => true,
|
|
'passID' => 0,
|
|
'width' => $coord['w'],
|
|
'height' => $coord['h'],
|
|
'stall' => $stall_no,
|
|
]);
|
|
|
|
$stall_no += 1;
|
|
}
|
|
|
|
|
|
|
|
return redirect(url('/lot/reference/'.$lot_object->id));
|
|
});
|
|
|
|
Route::get('/lot/reference/{id}', function($id){
|
|
$lot_object = ParkingLot::find($id);
|
|
return view('lot.selectrefs', ['lot'=>$lot_object]);
|
|
});
|
|
|
|
Route::post('/lot/reference/{id}', function(\Illuminate\Http\Request $request, $id){
|
|
$lot_object = ParkingLot::find($id);
|
|
$lot_object->ref_coords = $request->get('coords');
|
|
$lot_object->save();
|
|
|
|
$db = new FirestoreClient();
|
|
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id)->collection('info')->document('lotInfo');
|
|
$doc_ref_base = $doc_ref->snapshot()->data();
|
|
$doc_ref_base['reference_coords'] = $lot_object->ref_coords;
|
|
$doc_ref->set($doc_ref_base);
|
|
|
|
return redirect(url('/lot/success'));
|
|
|
|
});
|
|
|
|
Route::get('/lot/success', function(){
|
|
return view('lot.success');
|
|
});
|
|
|
|
Route::get('/lot/manage', function(\Illuminate\Http\Request $request){
|
|
// dd(ParkingLot::getFB());
|
|
return view('lot.manage', ['lots' => ParkingLot::getFB()]);
|
|
});
|
|
|
|
Route::get('/lot/manage/{id}', function(\Illuminate\Http\Request $request, $id){
|
|
$lot = ParkingLot::getFBbyID($id);
|
|
$db = new FirestoreClient();
|
|
$doc_ref = $db->collection('lots')->document($lot['id'])->collection('stalls')->documents();
|
|
|
|
|
|
$stalls = [];
|
|
foreach( $doc_ref as $stall ){
|
|
array_push($stalls, ['id' => $stall->id(), 'data' => $stall->data()]);
|
|
}
|
|
|
|
usort($stalls, function($a, $b){
|
|
return $a['data']['locationY'] <=> $b['data']['locationY'];
|
|
});
|
|
|
|
$stalls = array_chunk($stalls, (int) $lot['data']['columns']);
|
|
|
|
foreach($stalls as $key=>$stall_grp ){
|
|
usort($stall_grp, function($a, $b) {
|
|
return $a['data']['locationX'] <=> $b['data']['locationX'];
|
|
});
|
|
$stalls[$key] = $stall_grp;
|
|
}
|
|
|
|
return view('lot.manageone', ['lot' => $lot, 'stalls' => $stalls, 'thruid' => $id]);
|
|
});
|
|
|
|
Route::post('/lot/manage/{id}', function(\Illuminate\Http\Request $request, $id){
|
|
// dd($request->get('handicaps'));
|
|
$lot = ParkingLot::find($id);
|
|
$handicaps = json_decode($request->get('handicaps'));
|
|
$db = new FirestoreClient();
|
|
|
|
$stalls_docref = $db->collection('lots')->document($lot->firebase_id)->collection('stalls');
|
|
$docs = $stalls_docref->documents();
|
|
|
|
foreach( $docs as $doc ){
|
|
if ( $doc->exists()){
|
|
$data = $stalls_docref->document($doc->id())->snapshot()->data();
|
|
$data['handicap'] = (in_array($doc->id(), $handicaps));
|
|
$stalls_docref->document($doc->id())->set($data);
|
|
}
|
|
}
|
|
|
|
return redirect(url('/lot/manage/'.$id));
|
|
|
|
});
|
|
|
|
Route::get('/device/add', function(){
|
|
return view('device.add');
|
|
});
|
|
|
|
Route::post('/device/add', function(\Illuminate\Http\Request $request){
|
|
$db = new FirestoreClient();
|
|
$ref = $db->collection('configurations')->document(str_replace(' ', '-', $request->get('code')));
|
|
$ref->set([
|
|
'activation' => str_replace(' ', '-', $request->get('code')),
|
|
'e_hat' => $request->get('ehat'),
|
|
'lot_id' => $request->get('lotid'),
|
|
'stream' => $request->get('camera'),
|
|
'frequency' => $request->get('freq'),
|
|
'stop' => false,
|
|
]);
|
|
|
|
return redirect(url('/device/get/'.str_replace(' ', '-', $request->get('code'))));
|
|
});
|
|
|
|
Route::get('/device/get/{code}', function ($code) {
|
|
$db = new FirestoreClient();
|
|
$ref = $db->collection('configurations')->document($code)->snapshot();
|
|
|
|
return view('device.get', ['device' => ['id' => $ref->id(), 'data' => $ref->data()]]);
|
|
}); |