1
0
forked from s421507/eOSP2

Dodanie odznaczeń do bazy. Przyznawanie, wyświetlanie i usuwanie odznaczeń poszczególnych strażaków. Wyświetlanie odznaczeń w profilu użytkownika.

This commit is contained in:
Krzysztof Strzelecki 2020-01-01 03:18:06 +01:00
parent 30b0880f93
commit 0943faf263
13 changed files with 293 additions and 6 deletions

View File

@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers;
use App\User;
use App\decorationsFirefighters;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
use Carbon\Carbon; // formatowanie daty
function formatDate($date)
{
if ($date == null)
return $date;
else
$fdate = Carbon::parse($date);
return $fdate;
}
class DecorationsController extends Controller
{
public function create($id){
if(auth()->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();
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class decorationsFirefighters extends Model
{
use SoftDeletes;
protected $primaryKey = 'id';
protected $table = 'decorationsFirefighters';
protected $fillable = ['decorationID', 'firefighterID', 'dateOfAward'];
}

View File

@ -0,0 +1,42 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDecorationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('decorations', function (Blueprint $table) {
$table->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');
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDecorationsFirefightersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('decorationsFirefighters', function (Blueprint $table) {
$table->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');
}
}

View File

@ -161,7 +161,9 @@ return [
'unitName' => 'nazwa jednostki', 'unitName' => 'nazwa jednostki',
'longitude' => 'długość geograficzna', 'longitude' => 'długość geograficzna',
'latitude' => 'szerokość geograficzna', 'latitude' => 'szerokość geograficzna',
'amount' => 'ilość' 'amount' => 'ilość',
'decoration' => 'odznaczenie',
'dateOfAward' => 'data przyznania'
], ],

View File

@ -5,7 +5,8 @@
<ul> <ul>
<a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/szkolenia"><li>Moje szkolenia<img src="../img/left_menu_icon/more.png"></li></a> <a href="/userprofile/szkolenia"><li>Szkolenia<img src="../img/left_menu_icon/more.png"></li></a>
<a href="/userprofile/odznaczenia"><li>Odznaczenia<img src="../img/left_menu_icon/more.png"></li></a>
</ul> </ul>
@stop @stop

View File

@ -0,0 +1,70 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/strazacy"><li>Powrót<img src="/./img/left_menu_icon/edit.png"></li></a>
</ul>
@stop
@section('center-area')
@parent
@if( auth()->check())
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
@if(count($awardedDecorations) > 0)
<p align='center'>
<table class='firefighterViewTable'>
<tr class='table-header'>
<th colspan="2" scope="colgroup" style="text-align:center">{{ $firefighter->name }} {{ $firefighter->surname }} - odznaczenia</th>
</tr>
<tr class='table-header'>
<td>Odznaczenie</td>
<td>Data przyznania</td>
@foreach($awardedDecorations as $awardedDecoration)
<tr>
<form action="{{ route('decorations.destroy', $awardedDecoration->decorationsFirefightersID)}}" method="post">
<td id="decorationName{{ $awardedDecoration->decorationsFirefightersID }}">{{ $awardedDecoration->decorationName }}</td>
<td id="dateOfAward{{ $awardedDecoration->decorationsFirefightersID }}">{{ $awardedDecoration->dateOfAward }}</td>
<td>
{{ csrf_field() }}
@method('DELETE')
<button class="btn btn-danger" type="submit">Usuń</button>
</td>
</form>
</tr>
@endforeach
</table>
</p>
@else
{{ $firefighter->name }} {{ $firefighter->surname }} nie posiada żadnych odznaczeń.
@endif
<form method="POST" action="/strazacy/odznaczenia/.$firefighter->id">
{{ csrf_field() }}
<input type="hidden" class="form-control" name="firefighterID" value="{{ $firefighter->id }}">
<div class="form-group">
<label for="decoration">Wybierz odznaczenie:</label>
<select name="decoration" class="form-control" style="width:300px">
<option value="">--- Wybierz odznaczenie ---</option>
@foreach ($decoration as $key => $value)
<option value="{{ $key }}">{{ $value }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="dateOfAward">Data przyznania:</label>
<input type="date" class="form-control" style="width:300px" id="dateOfAward" name="dateOfAward" value="{{ old('dateOfAward') }}">
</div>
<div class="form-group">
<button style="cursor:pointer" type="submit" class="btn btn-primary">Przyznaj odznaczenie</button>
</div>
@include('inc.formerrors')
</form>
@endif
@else
Brak autoryzacji
@endif
@stop

View File

@ -4,7 +4,6 @@
@parent @parent
<ul> <ul>
<a href="/strazacy/add"><li>Dodaj<img src="img/left_menu_icon/add.png"></li></a> <a href="/strazacy/add"><li>Dodaj<img src="img/left_menu_icon/add.png"></li></a>
<li>Edytuj<img src="img/left_menu_icon/edit.png"></li>
<li>Wyklucz<img src="img/left_menu_icon/delete.png"></li> <li>Wyklucz<img src="img/left_menu_icon/delete.png"></li>
<li>Zawieś<img src="img/left_menu_icon/suspended.png"></li> <li>Zawieś<img src="img/left_menu_icon/suspended.png"></li>
<li>Więcej<img src="img/left_menu_icon/more.png"></li> <li>Więcej<img src="img/left_menu_icon/more.png"></li>
@ -88,6 +87,8 @@
<td id="userDegree{{ $user->id }}"> {{$user->rank}}</td> <td id="userDegree{{ $user->id }}"> {{$user->rank}}</td>
<td id="userStatus{{ $user->id }}">@if( $user->statusID == 0) Czynny @else Wyłączony @endif</td> <td id="userStatus{{ $user->id }}">@if( $user->statusID == 0) Czynny @else Wyłączony @endif</td>
<td><a href="{{ URL::asset('strazacy/edit/'.$user->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td> <td><a href="{{ URL::asset('strazacy/edit/'.$user->id) }}"><input type="button" onclick="" value="Edytuj"> </a></td>
<td><a href="{{ URL::asset('strazacy/odznaczenia/'.$user->id) }}"><input type="button" onclick="" value="Odznaczenia"> </a></td>
</tr> </tr>
{{-- <tr>--}} {{-- <tr>--}}
{{-- <form id="editForm{{$user->id}}" method="POST" action="/strazacy">--}} {{-- <form id="editForm{{$user->id}}" method="POST" action="/strazacy">--}}

View File

@ -0,0 +1,41 @@
@extends('layout.app')
@section('left-menu')
@parent
<ul>
<a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/szkolenia"><li>Szkolenia<img src="../img/left_menu_icon/more.png"></li></a>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a>
</ul>
@stop
@section('center-area')
@parent
@if( auth()->check())
@if( auth()->user()->fireStationID == NULL)
Jednostka nie istnieje
@else
@if(count($userDecorations) > 0)
<p align='center'>
<table class='firefighterViewTable'>
<tr class='table-header'>
<td>Odznaczenie</td>
<td>Data przyznania</td>
@foreach($userDecorations as $userDecoration)
<tr>
<td id="decorationName{{ $userDecoration->id }}">{{ $userDecoration->decorationName }}</td>
<td id="amount{{ $userDecoration->id }}">{{ $userDecoration->dateOfAward }}</td>
</tr>
@endforeach
</table>
</p>
@else
Nie posiadasz jeszcze żadnych odznaczeń.
@endif
@endif
@else
Brak autoryzacji
@endif
@stop

View File

@ -4,8 +4,9 @@
@parent @parent
<ul> <ul>
<a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/szkolenia"><li>Moje szkolenia<img src="../img/left_menu_icon/more.png"></li></a> <a href="/userprofile/szkolenia"><li>Szkolenia<img src="../img/left_menu_icon/more.png"></li></a>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile/odznaczenia"><li>Odznaczenia<img src="../img/left_menu_icon/more.png"></li></a>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a>
</ul> </ul>
@stop @stop

View File

@ -4,7 +4,8 @@
@parent @parent
<ul> <ul>
<a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/szkolenia"><li>Moje szkolenia<img src="../img/left_menu_icon/more.png"></li></a> <a href="/userprofile/szkolenia"><li>Szkolenia<img src="../img/left_menu_icon/more.png"></li></a>
<a href="/userprofile/odznaczenia"><li>Odznaczenia<img src="../img/left_menu_icon/more.png"></li></a>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a>
</ul> </ul>
@stop @stop

View File

@ -5,6 +5,7 @@
<ul> <ul>
<a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile"><li>Mój profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile/edit"><li>Edytuj profil<img src="../img/left_menu_icon/edit.png"></li></a>
<a href="/userprofile/odznaczenia"><li>Odznaczenia<img src="../img/left_menu_icon/more.png"></li></a>
<a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a> <a href="/userprofile/passwordchange"><li>Zmiana hasła<img src="../img/left_menu_icon/edit.png"></li></a>
</ul> </ul>
@stop @stop

View File

@ -52,6 +52,10 @@ Route::post('/strazacy', 'fireFightersController@store');
Route::get('/strazacy/edit/{id}', 'fireFightersController@editForm'); Route::get('/strazacy/edit/{id}', 'fireFightersController@editForm');
Route::post('/strazacy/edit', 'fireFightersController@update'); Route::post('/strazacy/edit', 'fireFightersController@update');
Route::get('/strazacy/odznaczenia/{id}', 'decorationsController@create');
Route::post('/strazacy/odznaczenia/{id}', 'decorationsController@store');
Route::resource('decorations', 'DecorationsController');
Route::get('/jednostka', 'fireStationController@create'); Route::get('/jednostka', 'fireStationController@create');
Route::post('/jednostka', 'fireStationController@store'); Route::post('/jednostka', 'fireStationController@store');
Route::get('/jednostka/edit', 'fireStationController@editForm'); Route::get('/jednostka/edit', 'fireStationController@editForm');
@ -88,6 +92,7 @@ Route::post('/userprofile/edit', 'userProfileController@update');
Route::get('/userprofile/passwordchange', 'ChangePasswordController@create'); Route::get('/userprofile/passwordchange', 'ChangePasswordController@create');
Route::post('/userprofile/passwordchange', 'ChangePasswordController@update'); Route::post('/userprofile/passwordchange', 'ChangePasswordController@update');
Route::get('/userprofile/szkolenia', 'userProfileController@userTrainings'); Route::get('/userprofile/szkolenia', 'userProfileController@userTrainings');
Route::get('/userprofile/odznaczenia', 'userProfileController@userDecorations');
Route::get('register/verify/{confirmationCode}', [ Route::get('register/verify/{confirmationCode}', [