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
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 @@+
+Nazwa Szkolenia | +Ilość z ukończonym | +Akcje | + @foreach($trainings as $training) +||||||
+
|
+