forked from s421507/eOSP2
Merge branch 'master' of https://git.wmi.amu.edu.pl/s421507/eOSP2
This commit is contained in:
commit
98196dae50
@ -8,7 +8,9 @@ use App\operations;
|
||||
use App\operationsMembers;
|
||||
use App\vehicle;
|
||||
use App\operationsDrivers;
|
||||
use App\operationsTrucks;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
@ -17,8 +19,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.id', 'operations.operationDate', 'operations.location', 'operations.target', 'operations.dangerType', 'operations.description', 'operations.commanderID', 'operations.fireStationID', 'users.name', 'users.surname')
|
||||
->get();
|
||||
|
||||
return view('operation');
|
||||
return view('operation', ["operations" => $operations]);
|
||||
} else{
|
||||
return view('operation');
|
||||
}
|
||||
@ -26,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();
|
||||
@ -37,8 +41,34 @@ class operationsController extends Controller
|
||||
|
||||
|
||||
|
||||
public function editForm(){
|
||||
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], ["fireFighters" => $fireFighters], ["operationMembers" => $operationMembers] );
|
||||
return View::make('/operationEdit')->with(compact('fireFighters','operation', 'operationMembers', 'vehicles'));
|
||||
// } else{
|
||||
// return "Brak dostepu";
|
||||
// }
|
||||
} else{
|
||||
return view('unit');
|
||||
}
|
||||
}
|
||||
|
||||
public function store(){
|
||||
@ -49,12 +79,16 @@ 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)'
|
||||
]);
|
||||
|
||||
//
|
||||
$request = request();
|
||||
$operations = operations::create([
|
||||
'operationDate' => $request-> operationDate,
|
||||
@ -63,12 +97,121 @@ class operationsController extends Controller
|
||||
'dangerType' => $request-> operationDangerType,
|
||||
'description' => $request-> operationDescription,
|
||||
'commanderID' => $request-> operationLeader,
|
||||
'fireStationID' => auth()->user()->fireStationID,
|
||||
]);
|
||||
|
||||
// Add trucks
|
||||
$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]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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' => $operations->id,
|
||||
'memberID' => $attendance[$count],
|
||||
'privateTransport' => $privateTransport,
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
||||
return operationsController::create();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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'];
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ class operationsMembers extends Model
|
||||
{
|
||||
//
|
||||
protected $primaryKey = 'id';
|
||||
protected $table = 'operationsMembers';
|
||||
|
||||
protected $fillable = ['operationID', 'memberID'];
|
||||
protected $fillable = ['operationID', 'memberID', 'privateTransport'];
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ class operationsTrucks extends Model
|
||||
{
|
||||
//
|
||||
protected $primaryKey = 'id';
|
||||
protected $table = 'operationsTrucks';
|
||||
|
||||
protected $fillable = ['operationID', 'truckID'];
|
||||
protected $fillable = ['operationID', 'truckID', 'driverID'];
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ class CreateOperationsTable extends Migration
|
||||
$table->string('dangerType', 100);
|
||||
$table->string('description');
|
||||
$table->integer('commanderID');
|
||||
$table->integer('driverID');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ class CreateOperationsTrucksTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->integer('operationID');
|
||||
$table->integer('truckID');
|
||||
$table->integer('driverID');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ class CreateOperationsMembersTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->integer('operationID');
|
||||
$table->integer('memberID');
|
||||
$table->boolean('privateTransport');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddFireStationIDColumnToOperationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('operations', function (Blueprint $table) {
|
||||
//
|
||||
$table->integer('fireStationID');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('operations', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
@ -11,6 +11,34 @@
|
||||
|
||||
@section('center-area')
|
||||
@parent
|
||||
Strona w budowie
|
||||
@if( auth()->check())
|
||||
@if( auth()->user()->fireStationID == NULL)
|
||||
Jednostka nie istnieje
|
||||
@else
|
||||
<table class='firefighterViewTable'>
|
||||
<tr class='table-header'>
|
||||
<td>Data</td>
|
||||
<td>Miejsce</td>
|
||||
<td>Cel</td>
|
||||
<td>Rodzaj zagrożenia</td>
|
||||
<td>Dowódca</td>
|
||||
</tr>
|
||||
|
||||
@foreach($operations as $operation)
|
||||
<tr>
|
||||
<td id="operationDate{{ $operation->id }}">{{ $operation->operationDate }}</td>
|
||||
<td id="operationLocation{{ $operation->id }}">{{ $operation->location }}</td>
|
||||
<td id="operationTarget{{ $operation->id }}">{{ $operation->target }}</td>
|
||||
<td id="operationDangerType{{ $operation->id }}">{{ $operation->dangerType }}</td>
|
||||
<td id="operationCommander{{ $operation->id }}">{{$operation->name}} {{$operation->surname}}</td>
|
||||
<td><a href="{{ URL::asset('wyjazdy/edit/'.$operation->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>"
|
||||
|
||||
@endif
|
||||
@else
|
||||
Brak autoryzacji
|
||||
@endif
|
||||
|
||||
@stop
|
||||
|
@ -16,7 +16,7 @@
|
||||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
<label for="date">Data wyjazdu: </label>
|
||||
<input type="datetime-local" id="operationDate" name="operationDate">
|
||||
<input type="datetime-local" id="operationDate" name="operationDate" value="2017-06-01 08:30">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@ -52,23 +52,42 @@
|
||||
|
||||
<div class=form-group">
|
||||
<div id="drivers">
|
||||
<label for="location">Kierowca:</label>
|
||||
<select name="operationDriver" class="form-control">
|
||||
<option value="">--- Wybierz kierowcę ---</option>
|
||||
@foreach ($fireFighters as $fireFighter)
|
||||
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<label for="location">Pojazd:</label>
|
||||
<select name="operationVehicle" class="form-control">
|
||||
<option value="">--- Wybierz pojazd ---</option>
|
||||
@foreach ($vehicles as $vehicle)
|
||||
<option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
{{-- <label for="location">Kierowca:</label>--}}
|
||||
{{-- <select name="operationDriver" class="form-control">--}}
|
||||
{{-- <option value="">--- Wybierz kierowcę ---</option>--}}
|
||||
{{-- @foreach ($fireFighters as $fireFighter)--}}
|
||||
{{-- <option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>--}}
|
||||
{{-- @endforeach--}}
|
||||
{{-- </select>--}}
|
||||
{{-- <label for="location">Pojazd:</label>--}}
|
||||
{{-- <select name="operationVehicle" class="form-control">--}}
|
||||
{{-- <option value="">--- Wybierz pojazd ---</option>--}}
|
||||
{{-- @foreach ($vehicles as $vehicle)--}}
|
||||
{{-- <option value="{{$vehicle->id}}">{{ $vehicle->name }} {{$vehicle->codename }} {{$vehicle->registrationNumber }}</option>--}}
|
||||
{{-- @endforeach--}}
|
||||
{{-- </select>--}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Imię i nazwisko: </td><td></td><td>Obecność:</td><td></td><td>Transport własny:</td>
|
||||
</tr>
|
||||
@php
|
||||
$i = 0;
|
||||
@endphp
|
||||
@foreach($fireFighters as $fireFighterChecklist)
|
||||
<tr>
|
||||
<td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td></td><td><center><input type="checkbox" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}"></center></td> <td></td> <td><center><input type="checkbox" name="transport[{{$i}}]" value="{{$i}}"></center></td>
|
||||
</tr>
|
||||
@php
|
||||
$i++;
|
||||
@endphp
|
||||
@endforeach
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button>
|
||||
</div>
|
||||
|
@ -12,31 +12,33 @@
|
||||
|
||||
@section('center-area')
|
||||
@parent
|
||||
<form method="POST" action="/wyjazdy" id="dynamic_form">
|
||||
<form method="POST" action="/wyjazdy/edit" id="dynamic_form">
|
||||
{{ csrf_field() }}
|
||||
|
||||
<input type="hidden" class="form-control" name="operationID" value="{{ $operation->id }}">
|
||||
<div class="form-group">
|
||||
<label for="date">Data wyjazdu: </label>
|
||||
<input type="datetime-local" id="operationDate" name="operationDate">
|
||||
<input type="datetime-local" id="operationDate" name="operationDate" value="{{$operation->operationDate}}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="location">Miejsce akcji:</label>
|
||||
<input type="text" class="form-control" id="operationLocation" name="operationLocation">
|
||||
<input type="text" class="form-control" id="operationLocation" name="operationLocation" value="{{ $operation->location }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="location">Cel wyjazdu:</label>
|
||||
<input type="text" class="form-control" id="operationTarget" name="operationTarget">
|
||||
<input type="text" class="form-control" id="operationTarget" name="operationTarget" value="{{ $operation->target }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="location">Rodzaj zagrożenia:</label>
|
||||
<input type="text" class="form-control" id="operationDangerType" name="operationDangerType">
|
||||
<input type="text" class="form-control" id="operationDangerType" name="operationDangerType" value="{{ $operation->dangerType }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="location">Opis akcji:</label>
|
||||
<textarea class="form-control" id="'operationDescription" name="operationDescription">Enter text here...</textarea>
|
||||
<textarea class="form-control" id="'operationDescription" name="operationDescription">{{ $operation->description }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class=form-group">
|
||||
@ -44,7 +46,7 @@
|
||||
<select name="operationLeader" class="form-control">
|
||||
<option value="">--- Wybierz dowódcę ---</option>
|
||||
@foreach ($fireFighters as $fireFighter)
|
||||
<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
|
||||
<option value="{{$fireFighter->id}}" {{$fireFighter->id == $operation->commanderID ? 'selected' : ''}}>{{ $fireFighter->name }} {{$fireFighter->surname }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@ -72,14 +74,14 @@
|
||||
<div class="form-group">
|
||||
<table>
|
||||
<tr>
|
||||
<td>Imię i nazwisko: [</td><td></td><td>Obecność:</td><td>[][][]</td><td>Transport własny:</td>
|
||||
<td>Imię i nazwisko: </td><td></td><td>Obecność:</td><td></td><td>Transport własny:</td>
|
||||
</tr>
|
||||
@php
|
||||
$i = 0;
|
||||
@endphp
|
||||
@foreach($fireFighters as $fireFighterChecklist)
|
||||
<tr>
|
||||
<td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td> </td><td>Tak <input type="radio" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}">Nie<input type="radio" name="attendance[{{$i}}]" value="false" checked></td><td> </td><td>Tak <input type="radio" name="transport[{{$i}}]" value="1">Nie <input type="radio" name="transport[{{$i}}]" value="0" checked></td>
|
||||
<td>{{ $fireFighterChecklist->name }} {{$fireFighterChecklist->surname }}</td><td></td><td><center><input type="checkbox" name="attendance[{{$i}}]" value="{{$fireFighterChecklist->id}}" {{$fireFighterChecklist->memberID != null ? 'checked' : ''}} ></center></td> <td></td> <td><center><input type="checkbox" name="transport[{{$i}}]" value="{{$i}}" {{$fireFighterChecklist->privateTransport == 1 ? 'checked' : ''}}></center></td>
|
||||
</tr>
|
||||
@php
|
||||
$i++;
|
||||
@ -89,6 +91,7 @@
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz</button>
|
||||
</div>
|
||||
|
@ -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::post('/wyjazdy/edit/', 'operationsController@update')->name('operationController.update');
|
||||
Route::get('/wyjazdy/edit/{id}', 'operationsController@editForm');
|
||||
|
||||
Route::get('/register', 'RegistrationController@create');
|
||||
Route::post('/register', 'RegistrationController@store');
|
||||
|
Loading…
Reference in New Issue
Block a user