2019-02-09 09:55:01 +00:00
|
|
|
<?php
|
|
|
|
|
2019-02-09 18:06:52 +00:00
|
|
|
use App\ParkingLot;
|
|
|
|
use Google\Cloud\Firestore\FirestoreClient;
|
|
|
|
|
2019-02-09 09:55:01 +00:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| 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');
|
|
|
|
});
|
2019-02-09 18:06:52 +00:00
|
|
|
|
|
|
|
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([
|
2019-02-09 22:35:50 +00:00
|
|
|
'firebase_id' => 'Lot',
|
2019-02-09 18:06:52 +00:00
|
|
|
'stall_coordinates' => '',
|
2019-02-09 22:35:50 +00:00
|
|
|
'reference_image' => $name,
|
|
|
|
'number_of_columns' => $request->get('numcols'),
|
|
|
|
'name' => $request->get('name')
|
2019-02-09 18:06:52 +00:00
|
|
|
]);
|
2019-02-09 22:35:50 +00:00
|
|
|
$lot_object->save();
|
2019-02-09 18:06:52 +00:00
|
|
|
|
2019-02-09 22:35:50 +00:00
|
|
|
$lot_object->firebase_id = 'Lot'.$lot_object->id;
|
2019-02-09 18:06:52 +00:00
|
|
|
$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();
|
|
|
|
|
2019-02-09 22:35:50 +00:00
|
|
|
$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]);
|
|
|
|
|
|
|
|
|
2019-02-09 18:06:52 +00:00
|
|
|
$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' => '',
|
2019-02-09 22:35:50 +00:00
|
|
|
'columns' => $lot_object->number_of_columns,
|
|
|
|
'name' => $lot_object->name
|
2019-02-09 18:06:52 +00:00
|
|
|
]);
|
|
|
|
|
2019-02-09 22:35:50 +00:00
|
|
|
// $coords = json_decode($lot_object->stall_coordinates);
|
2019-02-09 18:06:52 +00:00
|
|
|
$stall_no = 1;
|
2019-02-09 22:35:50 +00:00
|
|
|
foreach ($stall_coords_1D as $coord){
|
2019-02-09 18:06:52 +00:00
|
|
|
$doc_ref = $db->collection('lots')->document($lot_object->firebase_id)->collection('stalls')->document('Stall-'.$stall_no);
|
|
|
|
$doc_ref->set([
|
|
|
|
'handicap' => false,
|
2019-02-09 22:35:50 +00:00
|
|
|
'locationX' => $coord['x'],
|
|
|
|
'locationY' => $coord['y'],
|
2019-02-09 18:06:52 +00:00
|
|
|
'open' => true,
|
|
|
|
'passID' => 0,
|
2019-02-09 22:35:50 +00:00
|
|
|
'width' => $coord['w'],
|
|
|
|
'height' => $coord['h'],
|
2019-02-09 18:06:52 +00:00
|
|
|
'stall' => $stall_no,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$stall_no += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo $request->get('coords');
|
|
|
|
});
|