diff --git a/app/Http/Controllers/DecorationsController.php b/app/Http/Controllers/DecorationsController.php new file mode 100644 index 0000000..fb4ece1 --- /dev/null +++ b/app/Http/Controllers/DecorationsController.php @@ -0,0 +1,72 @@ +user() != null && auth()->user()->fireStationID != null ){ + $awardedDecorations = DB::table('decorationsFirefighters')->where("decorationsFirefighters.firefighterID", '=', $id) + ->whereNull('decorationsFirefighters.deleted_at') + ->leftJoin('decorations', 'decorationsFirefighters.decorationID', '=', 'decorations.id') + ->select('decorationName', 'dateOfAward', 'firefighterID', 'decorations.id AS decorationsId', 'decorationsFirefighters.id AS decorationsFirefightersID') + ->get(); + $alreadyAwarded = $awardedDecorations->pluck('decorationsId')->toArray(); // tablica id wszystkich wyróżnień już posiadanych + $firefighter = User::find($id, ['id', 'name', 'surname']); + $decoration = DB::table('decorations') + ->whereNotIn('id', $alreadyAwarded) //ograniczenie wyboru do wyróżnień jeszcze nie posiadanych + ->pluck('decorationName', 'id'); + + return View::make("decorations") + ->with(compact('firefighter')) + ->with(compact('awardedDecorations')) + ->with(compact('decoration')); + + } else{ + return "Brak dostepu"; + } + } + + public function store() + { + $this->validate(request(),[ + 'decoration' => 'required', + 'dateOfAward' => 'required', + ], + [ + 'required' => ':attribute jest wymagany(e).', + ]); + + $request = request(); + $decoration = decorationsFirefighters::create([ + 'firefighterID' => $request-> firefighterID, + 'decorationID' => $request-> decoration, + 'dateOfAward' => formatDate($request-> dateOfAward), + ]); + + return back(); + } + + public function destroy($id) + { + decorationsFirefighters::where('id',$id)->delete(); + + return back(); + } +} diff --git a/app/decorationsFirefighters.php b/app/decorationsFirefighters.php new file mode 100644 index 0000000..e98da75 --- /dev/null +++ b/app/decorationsFirefighters.php @@ -0,0 +1,15 @@ +integer('id'); + $table->string('decorationName'); + }); + + DB::table('decorations')->insert([ 'id' => '1', 'decorationName' => 'Odznaka "Młodzieżowa Drużyna Pożarnicza" - brązowa' ]); + DB::table('decorations')->insert([ 'id' => '2', 'decorationName' => 'Odznaka "Młodzieżowa Drużyna Pożarnicza" - srebrna' ]); + DB::table('decorations')->insert([ 'id' => '3', 'decorationName' => 'Odznaka "Młodzieżowa Drużyna Pożarnicza" - złota' ]); + DB::table('decorations')->insert([ 'id' => '4', 'decorationName' => 'Odznaka "Za wysługę lat"' ]); + DB::table('decorations')->insert([ 'id' => '5', 'decorationName' => 'Odznaka "Strażak Wzorowy"' ]); + DB::table('decorations')->insert([ 'id' => '6', 'decorationName' => 'Medal "Za Zasługi dla Pożarnictwa" - brązowy' ]); + DB::table('decorations')->insert([ 'id' => '7', 'decorationName' => 'Medal "Za Zasługi dla Pożarnictwa" - srebrny' ]); + DB::table('decorations')->insert([ 'id' => '8', 'decorationName' => 'Medal "Za Zasługi dla Pożarnictwa" - złoty' ]); + DB::table('decorations')->insert([ 'id' => '9', 'decorationName' => 'Medal Honorowy im. Bolesława Chomicza' ]); + DB::table('decorations')->insert([ 'id' => '10', 'decorationName' => 'Złoty Znak Związku Ochotniczych Straży Pożarnych Rzeczypospolitej Polskiej' ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('decorations'); + } +} diff --git a/database/migrations/2019_12_31_003036_create_decorationsFirefighters_table.php b/database/migrations/2019_12_31_003036_create_decorationsFirefighters_table.php new file mode 100644 index 0000000..1ea2e5c --- /dev/null +++ b/database/migrations/2019_12_31_003036_create_decorationsFirefighters_table.php @@ -0,0 +1,35 @@ +increments('id'); + $table->integer('firefighterID'); + $table->integer('decorationID'); + $table->date('dateOfAward'); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('decorationsFirefighters'); + } +} diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 63ecebe..4315724 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -161,7 +161,9 @@ return [ 'unitName' => 'nazwa jednostki', 'longitude' => 'długość geograficzna', 'latitude' => 'szerokość geograficzna', - 'amount' => 'ilość' + 'amount' => 'ilość', + 'decoration' => 'odznaczenie', + 'dateOfAward' => 'data przyznania' ], diff --git a/resources/views/changePassword.blade.php b/resources/views/changePassword.blade.php index 474fc9c..842de51 100644 --- a/resources/views/changePassword.blade.php +++ b/resources/views/changePassword.blade.php @@ -5,7 +5,8 @@ @stop diff --git a/resources/views/decorations.blade.php b/resources/views/decorations.blade.php new file mode 100644 index 0000000..791e107 --- /dev/null +++ b/resources/views/decorations.blade.php @@ -0,0 +1,70 @@ +@extends('layout.app') + +@section('left-menu') + @parent + + @stop +@section('center-area') + @parent + + @if( auth()->check()) + @if( auth()->user()->fireStationID == NULL) + Jednostka nie istnieje + @else + @if(count($awardedDecorations) > 0) +

+ + + + + + + + @foreach($awardedDecorations as $awardedDecoration) + + + + + + + + @endforeach +
{{ $firefighter->name }} {{ $firefighter->surname }} - odznaczenia
OdznaczenieData przyznania
{{ $awardedDecoration->decorationName }}{{ $awardedDecoration->dateOfAward }} + {{ csrf_field() }} + @method('DELETE') + +
+

+ @else + {{ $firefighter->name }} {{ $firefighter->surname }} nie posiada żadnych odznaczeń. + @endif + +
+ {{ csrf_field() }} + +
+ + +
+
+ + +
+
+ +
+ @include('inc.formerrors') +
+ @endif + @else + Brak autoryzacji + @endif + +@stop \ No newline at end of file diff --git a/resources/views/fireFighters.blade.php b/resources/views/fireFighters.blade.php index a1b7975..a638fd6 100644 --- a/resources/views/fireFighters.blade.php +++ b/resources/views/fireFighters.blade.php @@ -4,7 +4,6 @@ @parent