From f09c4ba2d41f7cd4ff0e3a09ff4486d4e65b2107 Mon Sep 17 00:00:00 2001 From: czup Date: Wed, 25 Dec 2019 22:35:20 +0100 Subject: [PATCH] Szkolenia ciag dalszy --- app/Http/Controllers/trainingsController.php | 104 ++++++++++ app/trainings.php | 12 ++ app/trainingsFirefighters.php | 13 ++ ...19_12_11_214115_create_trainings_table.php | 34 ++++ ...445_create_trainingsFirefighters_table.php | 36 ++++ ...d_softdelete_column_to_trainings_table.php | 32 +++ resources/views/depot.blade.php | 5 +- resources/views/layout/app.blade.php | 13 +- resources/views/operation.blade.php | 1 - resources/views/trainings.blade.php | 98 ++++++++++ .../views/trainingsAddFireFighters.blade.php | 182 ++++++++++++------ routes/web.php | 5 + 12 files changed, 472 insertions(+), 63 deletions(-) create mode 100644 app/Http/Controllers/trainingsController.php create mode 100644 app/trainings.php create mode 100644 app/trainingsFirefighters.php create mode 100644 database/migrations/2019_12_11_214115_create_trainings_table.php create mode 100644 database/migrations/2019_12_11_214445_create_trainingsFirefighters_table.php create mode 100644 database/migrations/2019_12_12_042400_add_softdelete_column_to_trainings_table.php diff --git a/app/Http/Controllers/trainingsController.php b/app/Http/Controllers/trainingsController.php new file mode 100644 index 0000000..4ab312b --- /dev/null +++ b/app/Http/Controllers/trainingsController.php @@ -0,0 +1,104 @@ +user() != null && auth()->user()->fireStationID != null ){ + $trainings = DB::table('trainings')->where("fireStationID", '=', auth()->user()->fireStationID) + ->whereNull('deleted_at')->get(); + foreach($trainings as $training) { + $id = $training->id; + $fireFighters[$id] = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID) + ->leftJoin('trainingsFirefighters', function ($join) use ($id) { + $join->on('users.id', '=', 'trainingsFirefighters.firefighterID'); + $join->where('trainingsFirefighters.trainingID', '=', $id); + }) + ->select('trainingsFirefighters.*', 'users.name', 'users.surname', 'users.id as userID') + ->get(); + } + return View::make("trainings")->with(compact( "trainings", "fireFighters")); + } else{ + return view('trainings'); + } + } + + public function addForm(){ + + } + + public function addTrainingsFireFighters($id){ + + if(auth()->user() != null && auth()->user()->fireStationID != null ){ + $fireFighters = DB::table('users')->where("fireStationID", "=", auth()->user()->fireStationID ) + ->leftJoin('trainingsFirefighters', function ($join) use($id){ + $join->on('users.id', '=', 'trainingsFirefighters.firefighterID'); + $join->where('trainingsFirefighters.trainingID', '=', $id); + }) + ->select('trainingsFirefighters.*', 'users.name', 'users.surname', 'users.id as userID') + ->get(); + + $training = DB::table('trainings')->where("id", '=', $id) + ->whereNull('deleted_at')->first(); + return View::make("trainingsAddFireFighters")->with(compact( "training", "fireFighters")); + } else{ + return view('trainings'); + } + } + + public function ajaxRequest(){ + $this->validate(request(), [ + 'firefighterID' => 'required', + 'trainingID' => 'required', + 'dateOfComplete' => 'required', + 'dateOfExpiry' => 'required', + ], + [ + 'required' => ':attribute jest wymagany(a).', + ]); + + $request = request(); + + $trainingFirefighter = trainingsFirefighters::where([ + ['firefighterID', '=', $request->firefighterID], + ['trainingID', '=', $request-> trainingID] + ])->first(); + + if($trainingFirefighter == null){ + // CREATE + $trainings = trainingsFirefighters::create([ + 'firefighterID' => $request-> firefighterID, + 'trainingID' => $request-> trainingID, + 'dateOfComplete' => $request-> dateOfComplete, + 'dateOfExpiry' => $request-> dateOfExpiry, + 'lifetime' => 1, + ]); + }else{ + // UPDATE + $trainingFirefighter->update([ + 'dateOfComplete' => $request-> dateOfComplete, + 'dateOfExpiry' => $request-> dateOfExpiry, + ]); + } + + +// $input = $request->all(); +// +// return response()->json(['success'=>'Got Simple Ajax Request.']); + + + } + + public function update(){ + + } +} diff --git a/app/trainings.php b/app/trainings.php new file mode 100644 index 0000000..3ed7ae7 --- /dev/null +++ b/app/trainings.php @@ -0,0 +1,12 @@ +increments('id'); + $table->integer('fireStationID'); + $table->string('trainingName'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('trainings'); + } +} + diff --git a/database/migrations/2019_12_11_214445_create_trainingsFirefighters_table.php b/database/migrations/2019_12_11_214445_create_trainingsFirefighters_table.php new file mode 100644 index 0000000..3573e55 --- /dev/null +++ b/database/migrations/2019_12_11_214445_create_trainingsFirefighters_table.php @@ -0,0 +1,36 @@ +increments('id'); + $table->integer('firefighterID'); + $table->integer('trainingID'); + $table->date('dateOfComplete'); + $table->date('dateOfExpiry'); + $table->boolean('lifetime'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('trainingsFirefighters'); + } +} diff --git a/database/migrations/2019_12_12_042400_add_softdelete_column_to_trainings_table.php b/database/migrations/2019_12_12_042400_add_softdelete_column_to_trainings_table.php new file mode 100644 index 0000000..ae65358 --- /dev/null +++ b/database/migrations/2019_12_12_042400_add_softdelete_column_to_trainings_table.php @@ -0,0 +1,32 @@ +softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('trainings', function (Blueprint $table) { + // + }); + } +} diff --git a/resources/views/depot.blade.php b/resources/views/depot.blade.php index 2b675af..7b28e75 100644 --- a/resources/views/depot.blade.php +++ b/resources/views/depot.blade.php @@ -4,6 +4,7 @@ @parent @@ -14,5 +15,5 @@ Strona w budowie

Zawarte będą tutaj informacje o umundurowaniu oraz sprzęcie jaki jest na wyposażeniu strażnicy oraz informacje gdzie umundurowanie się znajduje(druhowie mundury koszarowe oraz galowe mają w w domach, informacja ta pozwoli na sprawdzenie np jakie są braki w umundurowaniu).

- -@stop \ No newline at end of file + +@stop diff --git a/resources/views/layout/app.blade.php b/resources/views/layout/app.blade.php index c9ceed6..7b13b2b 100644 --- a/resources/views/layout/app.blade.php +++ b/resources/views/layout/app.blade.php @@ -5,11 +5,14 @@ E-OSP - - - - - +{{-- --}} + + + + + + + @if( auth()->check() ) diff --git a/resources/views/operation.blade.php b/resources/views/operation.blade.php index 564dee3..869a659 100644 --- a/resources/views/operation.blade.php +++ b/resources/views/operation.blade.php @@ -93,7 +93,6 @@ +@section('left-menu') + @parent + +@stop + +@section('center-area') + @parent + + @if( auth()->check()) + @if( auth()->user()->fireStationID == NULL) + Jednostka nie istnieje + @else +

+

+ {{ csrf_field() }} +
+ + +
+ +
+ +
+ @include('inc.formerrors') +
+ + + + + + @foreach($trainings as $training) + + + + + + + + + + + @endforeach +
Nazwa SzkoleniaIlość z ukończonymAkcje
{{ $training->trainingName }}5 + + + {{ csrf_field() }} + @method('DELETE') + +
+ + + + + + + + + + @foreach($fireFighters[$training->id] as $fireFighter) + @if($fireFighter->dateOfComplete != null and $fireFighter->dateOfExpiry != null) + + + + + + @endif + @endforeach + +
Imię i NazwiskoWażne od:Ważne do:
{{$fireFighter->name}} {{$fireFighter->surname}}{{$fireFighter->dateOfComplete}}{{$fireFighter->dateOfExpiry}}
+
+

+ + @endif + @else + Brak autoryzacji + @endif + +@stop + + diff --git a/resources/views/trainingsAddFireFighters.blade.php b/resources/views/trainingsAddFireFighters.blade.php index 076fa58..515cfe1 100644 --- a/resources/views/trainingsAddFireFighters.blade.php +++ b/resources/views/trainingsAddFireFighters.blade.php @@ -1,7 +1,11 @@ @extends('layout.app') - +Add Edit Delete Table Row Example using JQuery - ItSolutionStuff.com + + + + @section('left-menu') @parent @stop + @section('center-area') @parent @@ -18,21 +23,29 @@ @if( auth()->user()->fireStationID == NULL) Jednostka nie istnieje @else -
- {{ csrf_field() }} +

{{$training->trainingName}}

+ -
-
+
+ + + + + - - + + @foreach($fireFighters as $fireFighter) + + + + + + + @endforeach + +
Imię i NazwiskoWażne od:Ważne do:Akcje
{{$fireFighter->name}} {{$fireFighter->surname}}{{$fireFighter->dateOfComplete}}{{$fireFighter->dateOfExpiry}}
-
- -
- @include('inc.formerrors') -
@endif @else Brak autoryzacji @@ -40,59 +53,118 @@ @stop + + + + + + diff --git a/routes/web.php b/routes/web.php index fcc0fab..e991fb4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -74,6 +74,11 @@ Route::get('/sprzet/edit/{id}', 'EquipmentController@editForm'); Route::post('/sprzet/edit', 'EquipmentController@update'); Route::resource('equipment', 'EquipmentController'); +Route::get('/szkolenia', 'trainingsController@create'); +Route::post('/szkolenia', 'trainingsController@store'); +Route::get('/szkolenia/addTrainingsFireFighters/{id}', 'trainingsController@addTrainingsFireFighters'); +Route::post('/szkolenia/addTrainingsFireFighters/', 'trainingsController@ajaxRequest'); + Route::get('register/verify/{confirmationCode}', [ 'as' => 'confirmation_path', 'uses' => 'RegistrationController@confirm'