Initial Commit
This commit is contained in:
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Rooms;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Building;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BuildingController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
$buildings = Building::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$buildings = Building::orderBy('name', 'asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('buildings.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$buildings)
|
||||
->with('data_name','building')
|
||||
->with('data_names','buildings')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p');
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "name":
|
||||
$buildings = Building::where(function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
})->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$buildings = Building::onlyTrashed()->orderBy('name', 'asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
return view('buildings.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$buildings)
|
||||
->with('data_name','building')
|
||||
->with('data_names','buildings')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('buildings.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$building = new Building();
|
||||
$building->name = $request->name;
|
||||
$building->save();
|
||||
Logger::LogCreated($building->id,get_class($building));
|
||||
|
||||
return redirect()->route('buildings.show',['building' => $building]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function show($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
|
||||
return view('buildings.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','building')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return Application|Factory|View
|
||||
*/
|
||||
public function edit($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
return view('buildings.edit')
|
||||
->with('data',$object)
|
||||
->with('data_name','building')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
*/
|
||||
public function update(Request $request, $building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('buildings.show',['building' => $building]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('buildings.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('buildings.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($building)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'buildings_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Building::withTrashed()->where('id','=',$building)->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('buildings.deleted');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Rooms;
|
||||
|
||||
use App\Helpers\Logger;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Building;
|
||||
use App\Models\Loan;
|
||||
use App\Models\LoanType;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoomController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_viewAny'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "name", "name" => "name"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? 10;
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
$search_compare = $request->input('search_compare');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "building":
|
||||
$rooms = Room::where(function ($query) use ($search_term){
|
||||
$query->whereHas('building',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
case "name":
|
||||
$rooms = Room::where('rooms.name','like','%' . $search_term . '%')->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$rooms = Room::join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('rooms.index')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$rooms)
|
||||
->with('data_name','room')
|
||||
->with('data_names','rooms')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
*/
|
||||
public function deleted(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_viewAny_deleted'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$search_types = [];
|
||||
array_push($search_types,array("value" => "building", "name" => "building"));
|
||||
array_push($search_types,array("value" => "room", "name" => "room"));
|
||||
|
||||
$PerPagination = $request->input('p') ?? '10';
|
||||
$search_term = $request->input('search_term');
|
||||
$search_type = $request->input('search_type');
|
||||
|
||||
if($search_term != ""){
|
||||
switch ($search_type){
|
||||
case "building":
|
||||
$rooms = Room::where(function ($query) use ($search_term){
|
||||
$query->whereHas('building',function ($query) use ($search_term){
|
||||
$query->where('name','like','%' . $search_term . '%');
|
||||
});
|
||||
})->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
break;
|
||||
case "room":
|
||||
$rooms = Room::where('rooms.name','like','%' . $search_term . '%')->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->paginate($PerPagination);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
$rooms = Room::onlyTrashed()->join('buildings', 'rooms.building_id', '=', 'buildings.id')->select('rooms.*')->orderBy('buildings.name','asc')->onlyTrashed()->Paginate($PerPagination);
|
||||
}
|
||||
|
||||
|
||||
return view('rooms.deleted')
|
||||
->with('search_types',$search_types)
|
||||
->with('data',$rooms)
|
||||
->with('data_name','room')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
return view('rooms.create')
|
||||
->with('buildings',Building::all()->sortBy(['name','asc']))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_create'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$room = new Room();
|
||||
$room->building_id = $request->building_id;
|
||||
$room->name = $request->name;
|
||||
$room->save();
|
||||
Logger::LogCreated($room->id,get_class($room));
|
||||
|
||||
return redirect()->route('rooms.show',['room' => $room]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Room $room
|
||||
*/
|
||||
public function show($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_view'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
$reservations = Loan::where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id)
|
||||
->where('room_id','=',$object->id)
|
||||
->select('*',DB::raw('count(loanable_id) as amount'))
|
||||
->groupBy('loanable_type','loanable_id','loan_type_id','room_id')
|
||||
->orderBy('loan_type_id')
|
||||
->orderBy('user_id')
|
||||
->orderBy('date_start')
|
||||
->orderBy('date_end')
|
||||
->orderBy('loanable_type')
|
||||
->orderBy('loanable_id')
|
||||
->get()
|
||||
;
|
||||
|
||||
return view('rooms.show')
|
||||
->with('data',$object)
|
||||
->with('data_name','room')
|
||||
->with('reservations',$reservations)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function edit($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
return view('rooms.edit')
|
||||
->with('data',$object)
|
||||
->with('buildings',Building::all()->sortBy([['name','asc']]))
|
||||
->with('data_name','room')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, $room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_edit'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
|
||||
$object->building_id = $request->building_id;
|
||||
if( $object->name != $request->name){
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->name." til ".$request->name);
|
||||
$object->name = $request->name;
|
||||
}
|
||||
if( $object->building_id != $request->building_id){
|
||||
$building = Building::withTrashed()->where('id','=',$request->building_id)->first();
|
||||
Logger::LogEdited($object->id,get_class($object),"Navn : ".$object->building->name." til ".$building->name);
|
||||
$object->building_id = $request->building_id;
|
||||
}
|
||||
$object->save();
|
||||
|
||||
return redirect()->route('rooms.show',['room' => $room]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_delete'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
Logger::LogDeleted($object->id,get_class($object));
|
||||
$object->delete();
|
||||
|
||||
return redirect()->route('rooms.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Permanently Remove the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function delete_force($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_delete_force'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
Logger::LogForceDeleted($object->id,get_class($object));
|
||||
$object->forceDelete();
|
||||
|
||||
return redirect()->route('rooms.deleted');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the specified resource from storage.
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function restore($room)
|
||||
{
|
||||
Auth::user()->role->permissions->contains(Permission::firstWhere('name', '=', 'rooms_restore'))
|
||||
? Response::allow()
|
||||
: Response::deny('you are not the chosen one');
|
||||
|
||||
$object = Room::where('id','=',$room)->withTrashed()->first();
|
||||
$object->restore();
|
||||
Logger::LogRestored($object->id,get_class($object));
|
||||
|
||||
return redirect()->route('rooms.deleted');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user