diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a647681..2e7b9ef 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,20 @@ - - - + + + + + + + + + + + + + + - - + @@ -396,7 +400,7 @@ - + @@ -424,23 +428,9 @@ - - - - - - - - - - - - - - @@ -462,38 +452,66 @@ - + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + - + - + - - + + - + - - + + - - + + diff --git a/app/ParkingLot.php b/app/ParkingLot.php index 76fc4ce..c5ffaed 100644 --- a/app/ParkingLot.php +++ b/app/ParkingLot.php @@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Model; class ParkingLot extends Model { - protected $fillable = [ 'firebase_id', 'stall_coordinates', 'reference_image' ]; + protected $fillable = [ 'firebase_id', 'stall_coordinates', 'reference_image', 'number_of_columns', 'name' ]; public function get_coordinates(){ return json_decode( $this->stall_coordinates ); diff --git a/database/migrations/2019_02_09_200020_add_columns_to_parking_lots.php b/database/migrations/2019_02_09_200020_add_columns_to_parking_lots.php new file mode 100644 index 0000000..b2f5fd1 --- /dev/null +++ b/database/migrations/2019_02_09_200020_add_columns_to_parking_lots.php @@ -0,0 +1,32 @@ +integer('number_of_columns'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('parking_lots', function (Blueprint $table) { + // + }); + } +} diff --git a/database/migrations/2019_02_09_205355_add_name_to_parking_lots.php b/database/migrations/2019_02_09_205355_add_name_to_parking_lots.php new file mode 100644 index 0000000..fe0ada7 --- /dev/null +++ b/database/migrations/2019_02_09_205355_add_name_to_parking_lots.php @@ -0,0 +1,32 @@ +longText('name'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('parking_lots', function (Blueprint $table) { + // + }); + } +} diff --git a/public/img/references/1549731408.jpg b/public/img/references/1549731408.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549731408.jpg and /dev/null differ diff --git a/public/img/references/1549731519.jpg b/public/img/references/1549731519.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549731519.jpg and /dev/null differ diff --git a/public/img/references/1549733132.jpg b/public/img/references/1549733132.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549733132.jpg and /dev/null differ diff --git a/public/img/references/1549733192.jpg b/public/img/references/1549733192.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549733192.jpg and /dev/null differ diff --git a/public/img/references/1549733258.jpg b/public/img/references/1549733258.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549733258.jpg and /dev/null differ diff --git a/public/img/references/1549734106.jpg b/public/img/references/1549734106.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549734106.jpg and /dev/null differ diff --git a/public/img/references/1549734284.jpg b/public/img/references/1549734284.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549734284.jpg and /dev/null differ diff --git a/public/img/references/1549734518.jpg b/public/img/references/1549734518.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549734518.jpg and /dev/null differ diff --git a/public/img/references/1549734642.jpg b/public/img/references/1549734642.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549734642.jpg and /dev/null differ diff --git a/public/img/references/1549735133.jpg b/public/img/references/1549735133.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549735133.jpg and /dev/null differ diff --git a/public/img/references/1549735264.jpg b/public/img/references/1549735264.jpg deleted file mode 100644 index eaa0c63..0000000 Binary files a/public/img/references/1549735264.jpg and /dev/null differ diff --git a/public/img/references/1549748211.jpg b/public/img/references/1549748211.jpg new file mode 100644 index 0000000..9a7d815 Binary files /dev/null and b/public/img/references/1549748211.jpg differ diff --git a/public/img/references/1549750442.jpg b/public/img/references/1549750442.jpg new file mode 100644 index 0000000..9a7d815 Binary files /dev/null and b/public/img/references/1549750442.jpg differ diff --git a/public/img/references/1549750494.jpg b/public/img/references/1549750494.jpg new file mode 100644 index 0000000..9a7d815 Binary files /dev/null and b/public/img/references/1549750494.jpg differ diff --git a/public/img/references/1549750549.jpg b/public/img/references/1549750549.jpg new file mode 100644 index 0000000..9a7d815 Binary files /dev/null and b/public/img/references/1549750549.jpg differ diff --git a/resources/views/lot/add.blade.php b/resources/views/lot/add.blade.php index a3b2237..bea8bfc 100644 --- a/resources/views/lot/add.blade.php +++ b/resources/views/lot/add.blade.php @@ -31,6 +31,20 @@ +
+ + +
+ + + @if ($errors->has('numcols')) + + {{ $errors->first('numcols') }} + + @endif +
+
+
diff --git a/routes/web.php b/routes/web.php index d2cb806..b56aac1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,11 +38,15 @@ Route::post('/lot/post', function(\Illuminate\Http\Request $request) { // $this->save(); $lot_object = new ParkingLot([ - 'firebase_id' => str_replace(' ', '-', $request->get('name')), + 'firebase_id' => 'Lot', 'stall_coordinates' => '', - 'reference_image' => $name + '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 ]); @@ -54,6 +58,35 @@ Route::post('/lot/generate', function(\Illuminate\Http\Request $request){ $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); @@ -65,20 +98,22 @@ Route::post('/lot/generate', function(\Illuminate\Http\Request $request){ '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); +// $coords = json_decode($lot_object->stall_coordinates); $stall_no = 1; - foreach ($coords as $coord){ + 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, + 'locationX' => $coord['x'], + 'locationY' => $coord['y'], 'open' => true, 'passID' => 0, - 'width' => $coord->w, - 'height' => $coord->h, + 'width' => $coord['w'], + 'height' => $coord['h'], 'stall' => $stall_no, ]);