105 lines
3.6 KiB
PHP
105 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\trainings;
|
|
use App\trainingsFirefighters;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
|
|
class trainingsController extends Controller
|
|
{
|
|
public function create(){
|
|
|
|
if(auth()->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(){
|
|
|
|
}
|
|
}
|