From 213b279ec6fdd85902e259c2dfb996a12598041f Mon Sep 17 00:00:00 2001 From: czup Date: Sat, 7 Dec 2019 14:44:28 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Zamiana=20radiobox=C3=B3w=20na=20checkboxy,?= =?UTF-8?q?=20dodanie=20dzia=C5=82aj=C4=85cej=20edycji=20-=20Wyjazdy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/operationsController.php | 51 +++++++- app/operations.php | 2 +- app/operationsMembers.php | 3 +- app/operationsTrucks.php | 3 +- ...9_11_12_235707_create_operations_table.php | 1 - ...6_195559_create_operationsTrucks_table.php | 1 + ..._195646_create_operationsMembers_table.php | 1 + ...station_i_d_column_to_operations_table.php | 33 +++++ resources/views/operation.blade.php | 30 ++++- resources/views/operationAdd.blade.php | 48 +++++--- resources/views/operationEdit.blade.php | 114 +++++++++--------- routes/web.php | 2 + 12 files changed, 211 insertions(+), 78 deletions(-) create mode 100644 database/migrations/2019_11_27_113757_add_fire_station_i_d_column_to_operations_table.php diff --git a/app/Http/Controllers/operationsController.php b/app/Http/Controllers/operationsController.php index e48e898..5e80d79 100644 --- a/app/Http/Controllers/operationsController.php +++ b/app/Http/Controllers/operationsController.php @@ -8,6 +8,7 @@ use App\operations; use App\operationsMembers; use App\vehicle; use App\operationsDrivers; +use App\operationsTrucks; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -17,8 +18,12 @@ class operationsController extends Controller // public function create(){ if(auth()->user() != null && auth()->user()->fireStationID != null ){ + $operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID) + ->leftJoin('users', 'operations.commanderID', '=', 'users.id') + ->select('operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') + ->get(); - return view('operation'); + return view('operation', ["operations" => $operations]); } else{ return view('operation'); } @@ -37,8 +42,23 @@ class operationsController extends Controller - public function editForm(){ + public function editForm($id){ + if(auth()->user() != null && auth()->user()->fireStationID != null ){ + $operation = DB::table('operations')->where('operations.id', '=', $id)->first(); +// $operation = DB::table('operations')->where('operations.id', '=', $id) +// ->leftJoin('users', 'operations.commanderID', '=', 'users.id') +// ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') +// ->get(); + +// if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) { + return view('operationEdit', ["operation" => $operation]); +// } else{ +// return "Brak dostepu"; +// } + } else{ + return view('unit'); + } } public function store(){ @@ -49,7 +69,10 @@ class operationsController extends Controller 'operationDangerType' => 'required', 'operationDescription' => 'required', 'operationLeader' => 'required', - 'operationDriver' => 'required', + 'operationDriver.*' => 'required', + 'operationVehicle.*' => 'required', + 'attendance.*' => 'required', + 'transport.*' => 'required', ], [ 'required' => ':attribute jest wymagany(e)' @@ -63,8 +86,30 @@ class operationsController extends Controller 'dangerType' => $request-> operationDangerType, 'description' => $request-> operationDescription, 'commanderID' => $request-> operationLeader, + 'fireStationID' => auth()->user()->fireStationID, ]); + $operationDriver = $request ->operationDriver; + $operationVehicle = $request -> operationVehicle; + for($count = 0; $count < count($operationDriver); $count++){ + $operationsTrucks = operationsTrucks::create([ + 'operationID' => $operations->id, + 'truckID' => $operationDriver[$count], + 'driverID' => $operationVehicle[$count] + ]); + } + + $attendance = $request-> attendance; + for($count = 0; $count < count($attendance); $count++){ + if($attendance[$count] != 'false'){ + $operationsMembers = operationsMembers::create([ + 'operationID' => $operations->id, + 'memberID' => $attendance[$count], + 'privateTransport' => $request->transport[$count], + ]); + }; + } + return operationsController::create(); } diff --git a/app/operations.php b/app/operations.php index 9adafff..1deb64e 100644 --- a/app/operations.php +++ b/app/operations.php @@ -9,5 +9,5 @@ class operations extends Model // protected $primaryKey = 'id'; - protected $fillable = ['operationDate', 'location', 'target', 'dangerType', 'description', 'commanderID', 'driverID']; + protected $fillable = ['fireStationID', 'operationDate', 'location', 'target', 'dangerType', 'description', 'commanderID']; } diff --git a/app/operationsMembers.php b/app/operationsMembers.php index 9591385..908405a 100644 --- a/app/operationsMembers.php +++ b/app/operationsMembers.php @@ -8,6 +8,7 @@ class operationsMembers extends Model { // protected $primaryKey = 'id'; + protected $table = 'operationsMembers'; - protected $fillable = ['operationID', 'memberID']; + protected $fillable = ['operationID', 'memberID', 'privateTransport']; } diff --git a/app/operationsTrucks.php b/app/operationsTrucks.php index 13231c2..e5e1cd7 100644 --- a/app/operationsTrucks.php +++ b/app/operationsTrucks.php @@ -8,6 +8,7 @@ class operationsTrucks extends Model { // protected $primaryKey = 'id'; + protected $table = 'operationsTrucks'; - protected $fillable = ['operationID', 'truckID']; + protected $fillable = ['operationID', 'truckID', 'driverID']; } diff --git a/database/migrations/2019_11_12_235707_create_operations_table.php b/database/migrations/2019_11_12_235707_create_operations_table.php index 157d771..3d51b7f 100644 --- a/database/migrations/2019_11_12_235707_create_operations_table.php +++ b/database/migrations/2019_11_12_235707_create_operations_table.php @@ -21,7 +21,6 @@ class CreateOperationsTable extends Migration $table->string('dangerType', 100); $table->string('description'); $table->integer('commanderID'); - $table->integer('driverID'); $table->timestamps(); }); } diff --git a/database/migrations/2019_11_16_195559_create_operationsTrucks_table.php b/database/migrations/2019_11_16_195559_create_operationsTrucks_table.php index 3af03d6..65759b9 100644 --- a/database/migrations/2019_11_16_195559_create_operationsTrucks_table.php +++ b/database/migrations/2019_11_16_195559_create_operationsTrucks_table.php @@ -17,6 +17,7 @@ class CreateOperationsTrucksTable extends Migration $table->increments('id'); $table->integer('operationID'); $table->integer('truckID'); + $table->integer('driverID'); $table->timestamps(); }); } diff --git a/database/migrations/2019_11_16_195646_create_operationsMembers_table.php b/database/migrations/2019_11_16_195646_create_operationsMembers_table.php index a7b2ce2..7708e05 100644 --- a/database/migrations/2019_11_16_195646_create_operationsMembers_table.php +++ b/database/migrations/2019_11_16_195646_create_operationsMembers_table.php @@ -17,6 +17,7 @@ class CreateOperationsMembersTable extends Migration $table->increments('id'); $table->integer('operationID'); $table->integer('memberID'); + $table->boolean('privateTransport'); $table->timestamps(); }); } diff --git a/database/migrations/2019_11_27_113757_add_fire_station_i_d_column_to_operations_table.php b/database/migrations/2019_11_27_113757_add_fire_station_i_d_column_to_operations_table.php new file mode 100644 index 0000000..aa2c040 --- /dev/null +++ b/database/migrations/2019_11_27_113757_add_fire_station_i_d_column_to_operations_table.php @@ -0,0 +1,33 @@ +integer('fireStationID'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('operations', function (Blueprint $table) { + // + }); + } +} diff --git a/resources/views/operation.blade.php b/resources/views/operation.blade.php index e004005..e59bda0 100644 --- a/resources/views/operation.blade.php +++ b/resources/views/operation.blade.php @@ -11,6 +11,34 @@ @section('center-area') @parent - Strona w budowie + @if( auth()->check()) + @if( auth()->user()->fireStationID == NULL) + Jednostka nie istnieje + @else + + + + + + + + + + @foreach($operations as $operation) + + + + + + + + + @endforeach +
DataMiejsceCelRodzaj zagrożeniaDowódca
{{ $operation->operationDate }}{{ $operation->location }}{{ $operation->target }}{{ $operation->dangerType }}{{$operation->name}} {{$operation->surname}}
" + + @endif + @else + Brak autoryzacji + @endif @stop diff --git a/resources/views/operationAdd.blade.php b/resources/views/operationAdd.blade.php index 0eabff4..1f9580a 100644 --- a/resources/views/operationAdd.blade.php +++ b/resources/views/operationAdd.blade.php @@ -52,23 +52,43 @@
- - - - +{{-- --}} +{{-- --}} +{{-- --}} +{{-- --}}
+
+ + + + + @php + $i = 0; + @endphp + @foreach($fireFighters as $fireFighterChecklist) + + + + @php + $i++; + @endphp + @endforeach +
Imię i nazwisko: [Obecność:[][][]Transport własny:
{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }} Tak Nie Tak Nie
+
+ +
diff --git a/resources/views/operationEdit.blade.php b/resources/views/operationEdit.blade.php index 1f9580a..e2fd179 100644 --- a/resources/views/operationEdit.blade.php +++ b/resources/views/operationEdit.blade.php @@ -14,40 +14,42 @@ @parent
{{ csrf_field() }} + +
- +
- +
- +
- +
- +
-
- - -
+ {{--
--}} + {{-- --}} + {{-- --}} + {{--
--}}
@@ -69,24 +71,24 @@
-
- - - - - @php - $i = 0; - @endphp - @foreach($fireFighters as $fireFighterChecklist) - - - - @php - $i++; - @endphp - @endforeach -
Imię i nazwisko: [Obecność:[][][]Transport własny:
{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }} Tak Nie Tak Nie
-
+{{--
--}} +{{-- --}} +{{-- --}} +{{-- --}} +{{-- --}} +{{-- @php--}} +{{-- $i = 0;--}} +{{-- @endphp--}} +{{-- @foreach($fireFighters as $fireFighterChecklist)--}} +{{-- --}} +{{-- --}} +{{-- --}} +{{-- @php--}} +{{-- $i++;--}} +{{-- @endphp--}} +{{-- @endforeach--}} +{{--
Imię i nazwisko: [Obecność:[][][]Transport własny:
{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }} Tak Nie Tak Nie
--}} +{{--
--}}
@@ -107,31 +109,31 @@ function dynamic_field(number) { - html = '
'; - html += ''; - html += ''; - html += ''; + {{--html = '
';--}} + {{--html += '';--}} + {{--html += '';--}} + {{--html += '';--}} - if(number > 1) - { - html += '
'; - $('#drivers').append(html); - } - else - { - html += '
'; - $('#drivers').html(html); - } + {{--if(number > 1)--}} + {{--{--}} + {{-- html += '
';--}} + {{-- $('#drivers').append(html);--}} + {{--}--}} + {{--else--}} + {{--{--}} + {{-- html += '
';--}} + {{-- $('#drivers').html(html);--}} + {{--}--}} } $(document).on('click', '#add', function(){ diff --git a/routes/web.php b/routes/web.php index 59c56f2..e9ae103 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,6 +33,8 @@ Route::get('/pojazdy', function(){ Route::get('/wyjazdy', 'operationsController@create'); Route::get('/wyjazdy/add/', 'operationsController@addForm'); Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store'); +Route::get('/wyjazdy/edit/{id}', 'operationsController@editForm'); +Route::post('/wyjazdy/edit', 'operationsController@update'); Route::get('/register', 'RegistrationController@create'); Route::post('/register', 'RegistrationController@store'); From d505b14b09804ecfd872f2b13f4eb1b85657cba6 Mon Sep 17 00:00:00 2001 From: czup Date: Sat, 7 Dec 2019 14:50:37 +0100 Subject: [PATCH 2/2] Wyjazdy - zmiana radio boxow na checkboxy oraz dodanie edycji --- app/Http/Controllers/operationsController.php | 114 ++++++++++++++++-- resources/views/operationAdd.blade.php | 7 +- resources/views/operationEdit.blade.php | 105 ++++++++-------- routes/web.php | 2 +- 4 files changed, 163 insertions(+), 65 deletions(-) diff --git a/app/Http/Controllers/operationsController.php b/app/Http/Controllers/operationsController.php index 5e80d79..14d0a0c 100644 --- a/app/Http/Controllers/operationsController.php +++ b/app/Http/Controllers/operationsController.php @@ -10,6 +10,7 @@ use App\vehicle; use App\operationsDrivers; use App\operationsTrucks; use Illuminate\Http\Request; +use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\DB; @@ -20,7 +21,7 @@ class operationsController extends Controller if(auth()->user() != null && auth()->user()->fireStationID != null ){ $operations = DB::table('operations')->where('operations.fireStationID', "=", auth()->user()->fireStationID) ->leftJoin('users', 'operations.commanderID', '=', 'users.id') - ->select('operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') + ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.name', 'users.surname') ->get(); return view('operation', ["operations" => $operations]); @@ -31,8 +32,6 @@ class operationsController extends Controller public function addForm(){ if(auth()->user() != null && auth()->user()->fireStationID != null ){ - //$fireStationID = auth()->user()->fireStationID; - // $fireFighters = User::pluck('fireStationID', $fireStationID); $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get(); $vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID) ->get(); @@ -45,14 +44,25 @@ class operationsController extends Controller public function editForm($id){ if(auth()->user() != null && auth()->user()->fireStationID != null ){ +// $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->get(); + $vehicles = DB::table('vehicles')->where("fireStationID", '=', auth()->user()->fireStationID) + ->get(); $operation = DB::table('operations')->where('operations.id', '=', $id)->first(); + $operationMembers = DB::table('operationsMembers')->where('operationID', '=', $id)->get(); // $operation = DB::table('operations')->where('operations.id', '=', $id) // ->leftJoin('users', 'operations.commanderID', '=', 'users.id') // ->select('operations.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.id', 'users.name', 'users.surname') // ->get(); - + $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID ) + ->leftJoin('operationsMembers', function ($join) use($id){ + $join->on('users.id', '=', 'operationsMembers.memberID'); + $join->where('operationsMembers.operationID', '=', $id); + }) + ->select('users.*', 'operationsMembers.memberID', 'operationsMembers.privateTransport') + ->get(); // if($userFireStation == $fireFighterFireStation && auth()->user()->id == $fireStationCreatorId) { - return view('operationEdit', ["operation" => $operation]); +// return view('operationEdit', ["operation" => $operation], ["fireFighters" => $fireFighters], ["operationMembers" => $operationMembers] ); + return View::make('/operationEdit')->with(compact('fireFighters','operation', 'operationMembers', 'vehicles')); // } else{ // return "Brak dostepu"; // } @@ -78,6 +88,7 @@ class operationsController extends Controller 'required' => ':attribute jest wymagany(e)' ]); + // $request = request(); $operations = operations::create([ 'operationDate' => $request-> operationDate, @@ -89,6 +100,7 @@ class operationsController extends Controller 'fireStationID' => auth()->user()->fireStationID, ]); + // Add trucks $operationDriver = $request ->operationDriver; $operationVehicle = $request -> operationVehicle; for($count = 0; $count < count($operationDriver); $count++){ @@ -99,13 +111,29 @@ class operationsController extends Controller ]); } + + + // Add members $attendance = $request-> attendance; - for($count = 0; $count < count($attendance); $count++){ - if($attendance[$count] != 'false'){ + $transport = $request-> transport; + + // Count of firefighters (need for length of array) + $fireFightersCount = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->count(); + for($count = 0; $count < $fireFightersCount; $count++){ + + // Check privateTransport checklist + $privateTransport = 2; + if(isset($transport[$count])){ + $privateTransport = 1; + } else{ + $privateTransport = 0; + } + + if(isset($attendance[$count])){ $operationsMembers = operationsMembers::create([ 'operationID' => $operations->id, 'memberID' => $attendance[$count], - 'privateTransport' => $request->transport[$count], + 'privateTransport' => $privateTransport, ]); }; } @@ -114,6 +142,76 @@ class operationsController extends Controller } public function update(){ + $this->validate(request(),[ + 'operationDate' => 'required', + 'operationLocation' => 'required', + 'operationTarget' => 'required', + 'operationDangerType' => 'required', + 'operationDescription' => 'required', + 'operationLeader' => 'required', + 'operationDriver.*' => 'required', + 'operationVehicle.*' => 'required', + 'attendance.*' => 'required', + 'transport.*' => 'required', + ], + [ + 'required' => ':attribute jest wymagany(e)' + ]); + + $request = request(); + $operation = operations::where('id', $request->operationID)->update(array( + 'operationDate' => $request-> operationDate, + 'location' => $request-> operationLocation, + 'target' => $request-> operationTarget, + 'dangerType' => $request-> operationDangerType, + 'description' => $request-> operationDescription, + 'commanderID' => $request-> operationLeader, + 'fireStationID' => auth()->user()->fireStationID + )); + + + operationsTrucks::where('operationID', $request->operationID)->delete(); + + // Add trucks + $operationDriver = $request ->operationDriver; + $operationVehicle = $request -> operationVehicle; + for($count = 0; $count < count($operationDriver); $count++){ + $operationsTrucks = operationsTrucks::create([ + 'operationID' => $request->operationID, + 'truckID' => $operationDriver[$count], + 'driverID' => $operationVehicle[$count] + ]); + } + + operationsMembers::where('operationID', $request->operationID)->delete(); + + + // Add members + $attendance = $request-> attendance; + $transport = $request-> transport; + + // Count of firefighters (need for length of array) + $fireFightersCount = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID )->count(); + for($count = 0; $count < $fireFightersCount; $count++){ + + // Check privateTransport checklist + $privateTransport = 2; + if(isset($transport[$count])){ + $privateTransport = 1; + } else{ + $privateTransport = 0; + } + + if(isset($attendance[$count])){ + $operationsMembers = operationsMembers::create([ + 'operationID' => $request->operationID, + 'memberID' => $attendance[$count], + 'privateTransport' => $privateTransport, + ]); + }; + } + + return operationsController::create(); } } diff --git a/resources/views/operationAdd.blade.php b/resources/views/operationAdd.blade.php index 1f9580a..b13938a 100644 --- a/resources/views/operationAdd.blade.php +++ b/resources/views/operationAdd.blade.php @@ -16,7 +16,7 @@ {{ csrf_field() }}
- +
@@ -72,14 +72,14 @@
- + @php $i = 0; @endphp @foreach($fireFighters as $fireFighterChecklist) - + @php $i++; @@ -88,7 +88,6 @@
Imię i nazwisko: [Obecność:[][][]Transport własny:Imię i nazwisko: Obecność:Transport własny:
{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }} Tak Nie Tak Nie {{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}
-
diff --git a/resources/views/operationEdit.blade.php b/resources/views/operationEdit.blade.php index e2fd179..38fd7c2 100644 --- a/resources/views/operationEdit.blade.php +++ b/resources/views/operationEdit.blade.php @@ -12,7 +12,7 @@ @section('center-area') @parent - + {{ csrf_field() }} @@ -41,15 +41,15 @@
- {{--
--}} - {{-- --}} - {{-- --}} - {{--
--}} +
+ + +
@@ -71,24 +71,25 @@
-{{--
--}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- @php--}} -{{-- $i = 0;--}} -{{-- @endphp--}} -{{-- @foreach($fireFighters as $fireFighterChecklist)--}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- @php--}} -{{-- $i++;--}} -{{-- @endphp--}} -{{-- @endforeach--}} -{{--
Imię i nazwisko: [Obecność:[][][]Transport własny:
{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }} Tak Nie Tak Nie
--}} -{{--
--}} +
+ + + + + @php + $i = 0; + @endphp + @foreach($fireFighters as $fireFighterChecklist) + + + + @php + $i++; + @endphp + @endforeach +
Imię i nazwisko: Obecność:Transport własny:
{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}
memberID != null ? 'checked' : ''}} >
privateTransport == 1 ? 'checked' : ''}}>
+
+
@@ -109,31 +110,31 @@ function dynamic_field(number) { - {{--html = '
';--}} - {{--html += '';--}} - {{--html += '';--}} - {{--html += '';--}} + html = '
'; + html += ''; + html += ''; + html += ''; - {{--if(number > 1)--}} - {{--{--}} - {{-- html += '
';--}} - {{-- $('#drivers').append(html);--}} - {{--}--}} - {{--else--}} - {{--{--}} - {{-- html += '
';--}} - {{-- $('#drivers').html(html);--}} - {{--}--}} + if(number > 1) + { + html += '
'; + $('#drivers').append(html); + } + else + { + html += '
'; + $('#drivers').html(html); + } } $(document).on('click', '#add', function(){ diff --git a/routes/web.php b/routes/web.php index e9ae103..e431555 100644 --- a/routes/web.php +++ b/routes/web.php @@ -33,8 +33,8 @@ Route::get('/pojazdy', function(){ Route::get('/wyjazdy', 'operationsController@create'); Route::get('/wyjazdy/add/', 'operationsController@addForm'); Route::post('/wyjazdy', 'operationsController@store')->name('operationController.store'); +Route::post('/wyjazdy/edit/', 'operationsController@update')->name('operationController.update'); Route::get('/wyjazdy/edit/{id}', 'operationsController@editForm'); -Route::post('/wyjazdy/edit', 'operationsController@update'); Route::get('/register', 'RegistrationController@create'); Route::post('/register', 'RegistrationController@store');