eOSP2/app/Http/Controllers/userProfileController.php

127 lines
5.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\User;
use App\Rules\Pesel;
class userProfileController extends Controller
{
public function create(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$userData = DB::table('users')->where("users.id", '=', auth()->user()->id)
->leftJoin('ranks', 'users.degreeID', '=', 'ranks.id')
->leftJoin('unitFunctions', 'users.functionID', '=', 'unitFunctions.id')
->select('users.id','users.name', 'users.surname', 'users.PESEL','users.phoneNumber', 'users.email', 'ranks.rank', 'unitFunctions.unitFunction', 'users.number', 'users.secondName', 'users.fathersName', 'users.mothersName', 'users.address', 'users.apartment', 'users.placeOfBirth', 'users.driversLicense', 'users.joiningOSPDate', 'users.IDSeries', 'users.IDNumber', 'users.IDValidUntil', 'users.identityCardNumber', 'users.homePhoneNumber', 'users.education', 'users.profession')
->first();
return view("userProfile", ["userData" => $userData]);
} else{
return redirect()->to('/login');
}
}
public function editForm()
{
if(auth()->user() != null && auth()->user()->fireStationID != null )
{
$userData = DB::table('users')->where("id", '=', auth()->user()->id)
->first();
2020-02-01 01:03:57 +01:00
return view("userProfileEdit", ["userData" => $userData]);
2020-02-01 01:03:57 +01:00
}
else
return redirect()->to('/login');
2020-02-01 01:03:57 +01:00
}
public function update(){
$this->validate(request(), [
2020-02-01 03:53:59 +01:00
'name' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/',
'surname' =>'required|min:2|max:45|regex:/^[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ\040\x27-]+$/',
'PESEL' => new Pesel,
'phoneNumber' => 'required|digits:9',
'email' => 'required|email|unique:users,email,'.auth()->user()->id, //wymagaj unikalnego adresu email ale pozwól na zachowanie starego adresu
'secondName' => 'max:45',
'fathersName' => 'max:45',
'mothersName' => 'max:45',
'homePhoneNumber' => 'max:20',
'address' => 'max:45',
'apartment'=> 'max:45',
'placeOfBirth'=> 'max:45',
'IDSeries'=> 'max:3',
'IDNumber'=> 'max:6',
'identityCardNumber'=> 'max:20',
'driversLicense'=> 'max:20',
'education'=> 'max:45',
'profession'=> 'max:45',
],
[
'required' => ':attribute jest wymagany(e).',
'min' => ':attribute musi mieć przynajmniej :min znaki.',
'max' => ':attribute musi mieć nie więcej niż :max znaków.',
2020-01-31 03:13:13 +01:00
'regex' => ':attribute może zawierać tylko litery, spacje, myślniki i apostrofy',
'digits' => ':attribute musi składać się z :digits cyfr.',
'unique' =>':attribute jest już zajęty.',
'confirmed' =>':attribute się nie zgadza.',
'email' => 'Niepoprawny adres e-mail.'
]);
$request = request();
$user = User::find( $request->userID);
$user-> name = $request->name;
$user-> surname = $request->surname;
$user-> PESEL = $request->PESEL;
$user-> phoneNumber = $request->phoneNumber;
$user-> email = $request->email;
$user-> changingID = auth()->user()-> id;
$user-> secondName = $request->secondName;
$user-> fathersName = $request->fathersName;
$user-> mothersName = $request->mothersName;
$user-> homePhoneNumber = $request->homePhoneNumber;
$user-> address = $request->address;
$user-> apartment = $request->apartment;
$user-> placeOfBirth = $request->placeOfBirth;
$user-> joiningOSPDate = $request->joiningOSPDate;
$user-> IDSeries = $request->IDSeries;
$user-> IDNumber = $request->IDNumber;
$user-> IDValidUntil = $request->IDValidUntil;
$user-> identityCardNumber = $request->identityCardNumber;
$user-> driversLicense= $request->driversLicense;
$user-> education = $request->education;
$user-> profession = $request->profession;
$user->save();
return redirect()->to('/userprofile');;
}
public function userTrainings(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
2020-01-02 14:20:35 +01:00
$userTrainings = DB::table('trainingsFirefighters')->where("trainingsFirefighters.firefighterID", '=', auth()->user()->id)
->leftJoin('trainings', 'trainingsFirefighters.trainingID', '=', 'trainings.id')
2020-02-01 01:03:57 +01:00
->whereNull('deleted_at')
2020-01-02 14:20:35 +01:00
->select('trainingsFirefighters.id','trainings.trainingName','trainingsFirefighters.dateOfComplete', 'trainingsFirefighters.dateOfExpiry')
->get();
return view("userTrainings", ["userTrainings" => $userTrainings]);
}
else{
return redirect()->to('/login');;
}
}
2020-01-02 14:20:35 +01:00
public function userDecorations(){
if(auth()->user() != null && auth()->user()->fireStationID != null ){
$userDecorations = DB::table('decorationsFirefighters')->where("decorationsFirefighters.firefighterID", '=', auth()->user()->id)
->whereNull('decorationsFirefighters.deleted_at')
->leftJoin('decorations', 'decorationsFirefighters.decorationID', '=', 'decorations.id')
->get();
return view("userDecorations", ["userDecorations" => $userDecorations]);
} else{
return "Brak dostepu";
}
}
}