diff --git a/skolehjem/app/Http/Controllers/EventController.php b/skolehjem/app/Http/Controllers/EventController.php index 557e846..5d5cb2b 100644 --- a/skolehjem/app/Http/Controllers/EventController.php +++ b/skolehjem/app/Http/Controllers/EventController.php @@ -277,6 +277,7 @@ class EventController extends Controller } } + //Used for checking if the currently typed event name is unique. Create version public function nameCheck(Request $request){ $event = Event::query()->where('name', 'LIKE',$request->nameCheck)->get(); if(count($event) > 0 && $request->nameCheck !== NULL){ @@ -284,6 +285,7 @@ class EventController extends Controller } } + //Used for checking if the currently typed event name is unique. Edit version public function nameCheckUpdate(Request $request){ $event = Event::query()->where('name', 'LIKE',$request->nameCheck)->where('id', '!=', $request->id)->get(); if(count($event) > 0 && $request->nameCheck !== NULL){ diff --git a/skolehjem/app/Http/Controllers/FeedbackController.php b/skolehjem/app/Http/Controllers/FeedbackController.php index 682f15f..fd61561 100644 --- a/skolehjem/app/Http/Controllers/FeedbackController.php +++ b/skolehjem/app/Http/Controllers/FeedbackController.php @@ -127,45 +127,6 @@ class FeedbackController extends Controller return redirect()->route("feedbacks.index"); } - - - public function search(Request $request){ - if($request->ajax()){ - $output = "". - "Dato". - "Feedback Besked". - "Feedback type". - "\"Delete\"". - ""; - - //$value = Feedbacks::query('feedbacks')->select('suggestion_form ')->dump(); - //$value = DB::table('feedbacks')->select('suggestion_form ')->dump(); - if($request->option === "Ris" || $request->option === "Ros" || $request->option === "Andet") - $feedbacks = Feedbacks::query()->orderBy('created_at', 'desc')->where('suggestion_form', '=', $request->option) - ->get(); - else - $feedbacks = Feedbacks::all(); - - if(count($feedbacks) !== 0){ - foreach ($feedbacks as $key => $feedback){ - $output.=''. - '' . date('d-m-Y', strtotime($feedback->created_at)) . ''. - '' . $feedback->message . ''. - '' . $feedback->suggestion_form . ''. - '
$feedback ]). '" class="w-100 nostyle">'. - csrf_field(). - method_field("delete"). - - ''. - '
'. - ''. - ''; - } - } - return Response($output); - } - } - public function storeajax(Request $request) { $requestBody = $request->validate([ "message" => "required", @@ -175,6 +136,4 @@ class FeedbackController extends Controller $feedbacks = new Feedbacks($requestBody); $feedbacks->save(); } - - } diff --git a/skolehjem/app/Http/Controllers/GuideController.php b/skolehjem/app/Http/Controllers/GuideController.php index 00a8a89..c0bc847 100644 --- a/skolehjem/app/Http/Controllers/GuideController.php +++ b/skolehjem/app/Http/Controllers/GuideController.php @@ -63,6 +63,7 @@ class GuideController extends Controller $guide = new Guide($requestGuide); + //If an image has been uploaded, store the file if($request->file("resource")) { $guide->resource_id = ResourceController::store($request)->id; } @@ -179,6 +180,7 @@ class GuideController extends Controller return redirect()->route("guides.index"); } + //Used to fix html, that have been substringed public function closetags($html) { preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?#iU', $html, $result); $openedtags = $result[1]; @@ -199,8 +201,7 @@ class GuideController extends Controller return $html; } - - + //Used for checking if the currently typed guide name is unique. Create version public function nameCheck(Request $request) { $guide = Guide::query()->where('name', 'LIKE',$request->nameCheck)->get(); if(count($guide) > 0 && $request->nameCheck !== NULL){ @@ -208,6 +209,7 @@ class GuideController extends Controller } } + //Used for checking if the currently typed guide name is unique. Edit version public function nameCheckUpdate(Request $request) { $guide = Guide::query()->where('name', 'LIKE',$request->nameCheck)->where('id', '!=', $request->id)->get(); if(count($guide) > 0 && $request->nameCheck !== NULL){ diff --git a/skolehjem/app/Http/Controllers/GuidesCategoryController.php b/skolehjem/app/Http/Controllers/GuidesCategoryController.php index 5656cb8..4a44086 100644 --- a/skolehjem/app/Http/Controllers/GuidesCategoryController.php +++ b/skolehjem/app/Http/Controllers/GuidesCategoryController.php @@ -132,6 +132,7 @@ class GuidesCategoryController extends Controller return redirect()->route("guides.index"); } + //Used for checking if the currently typed Guide Category name is unique. Create version public function nameCheck(Request $request) { $guide = GuidesCategory::query()->where('guidesCategoryName', 'LIKE',$request->nameCheck)->get(); if(count($guide) > 0 && $request->nameCheck !== NULL){ @@ -139,6 +140,7 @@ class GuidesCategoryController extends Controller } } + //Used for checking if the currently typed Guide Category name is unique. Edit version public function nameCheckUpdate(Request $request) { $guide = GuidesCategory::query()->where('guidesCategoryName', 'LIKE',$request->nameCheck)->where('id', '!=', $request->id)->get(); if(count($guide) > 0 && $request->nameCheck !== NULL){ diff --git a/skolehjem/app/Http/Controllers/MenuPlanController.php b/skolehjem/app/Http/Controllers/MenuPlanController.php index 5ef2a2d..dbcc26b 100644 --- a/skolehjem/app/Http/Controllers/MenuPlanController.php +++ b/skolehjem/app/Http/Controllers/MenuPlanController.php @@ -156,6 +156,7 @@ class MenuPlanController extends Controller $menuPlans = MenuPlan::query()->paginate(20); + //Create news if($request->newsoption == true){ $news = new News(); diff --git a/skolehjem/app/Http/Controllers/RolesController.php b/skolehjem/app/Http/Controllers/RolesController.php index 5ef2029..4865d7f 100644 --- a/skolehjem/app/Http/Controllers/RolesController.php +++ b/skolehjem/app/Http/Controllers/RolesController.php @@ -104,6 +104,7 @@ class RolesController extends Controller */ public function edit($id) { + //Disables editing of roles: Administrator & Bruger if($id == 1 || $id == 2) return redirect()->route("roles.index"); @@ -150,6 +151,7 @@ class RolesController extends Controller $allRoles = Role::query()->where('name', '=', $request->name)->where('id', '!=', $id)->get(); + //Check if role already exist if not save if(count($allRoles) > 0){ return redirect()->route("roles.index", [ "role" => $role ]); }else{ @@ -170,6 +172,7 @@ class RolesController extends Controller */ public function destroy($id) { + //Disables deletion of roles: Administrator & Bruger if($id == 1 || $id == 2) return redirect()->route("roles.index"); @@ -178,6 +181,7 @@ class RolesController extends Controller return redirect()->route("roles.index"); } + //Used for checking if the currently typed role name is unique. Create version public function nameCheck(Request $request){ $roles = Role::query()->where('name', 'LIKE',$request->nameCheck)->get(); if(count($roles) > 0 && $request->nameCheck !== NULL){ @@ -185,6 +189,7 @@ class RolesController extends Controller } } + //Used for checking if the currently typed role name is unique. Edit version public function nameCheckUpdate(Request $request){ $roles = Role::query()->where('name', 'LIKE',$request->nameCheck)->where('id', '!=', $request->id)->get(); if(count($roles) > 0 && $request->nameCheck !== NULL){ diff --git a/skolehjem/app/Http/Controllers/RootController.php b/skolehjem/app/Http/Controllers/RootController.php index 40e5eb1..c74dfd7 100644 --- a/skolehjem/app/Http/Controllers/RootController.php +++ b/skolehjem/app/Http/Controllers/RootController.php @@ -18,8 +18,10 @@ class RootController extends Controller public function index() { $perPage = 5; + //All news $newsCollection = News::query()->orderBy('id', 'desc')->paginate($perPage); + //Runs through all the news and deletes the old stuff foreach ($newsCollection as $new) { if($new->type_id == 3) @@ -27,6 +29,7 @@ class RootController extends Controller $new->delete(); } + //Return either the admin or app index page without the old news if(auth()->user()->can('admin.panel.show')) { if(Response::detect("root.index")->name() == "admin.root.index") return view("admin.root.index"); diff --git a/skolehjem/app/Http/Controllers/UserEventController.php b/skolehjem/app/Http/Controllers/UserEventController.php index 61f9b1b..e8e4fd6 100644 --- a/skolehjem/app/Http/Controllers/UserEventController.php +++ b/skolehjem/app/Http/Controllers/UserEventController.php @@ -46,8 +46,7 @@ class UserEventController extends Controller ]); // Check the UserEvent table if there is a row that has the user_id AND the event_id - $getTableInfo = UserEvent::where('user_id', auth()->user()->id) - ->where('event_id', $request->event_id)->get(); + $getTableInfo = UserEvent::where('user_id', auth()->user()->id)->where('event_id', $request->event_id)->get(); // If the row has both, then go back and show an error - Cause you're not allowed to be on the same event twice. if (count($getTableInfo) > 0) { @@ -81,8 +80,6 @@ class UserEventController extends Controller public function destroy($id) { // Check the UserEvent table if there is a row that has the user_id AND the event_id - //$UserEvent = UserEvent::find($eventid) - $UserEvent = UserEvent::query()->where('user_id', "=", auth()->user()->id)->where('event_id', "=", $id); $UserEvent->delete(); @@ -101,14 +98,15 @@ class UserEventController extends Controller { } - public function edit() { - + public function edit() + { } - public function update() { - + public function update() + { } + //Signs a user up to an event via ajax public function createajax(Request $request) { // Get written data from events.index @@ -143,6 +141,7 @@ class UserEventController extends Controller return '

Du er hermed tilmeldt denne aktivitet!

'; } + //Removes a users participation in an event via ajax public function createajaxcancel(Request $request) { // Check the UserEvent table if there is a row that has the user_id AND the event_id diff --git a/skolehjem/app/Http/Controllers/WashingMachineController.php b/skolehjem/app/Http/Controllers/WashingMachineController.php index a853ed3..8e4b2b1 100644 --- a/skolehjem/app/Http/Controllers/WashingMachineController.php +++ b/skolehjem/app/Http/Controllers/WashingMachineController.php @@ -154,6 +154,7 @@ class WashingMachineController extends Controller return redirect()->route("washing-machines.index"); } + //Used for checking if the currently typed washingmachine name is unique. Create version public function nameCheck(Request $request){ $washing = WashingMachine::query()->where('name', 'LIKE',$request->nameCheck)->where('location_id', '=', $request->location)->get(); if(count($washing) > 0 && $request->nameCheck !== NULL){ @@ -161,6 +162,7 @@ class WashingMachineController extends Controller } } + //Used for checking if the currently typed washingmachine name is unique. Edit version public function nameCheckUpdate(Request $request){ $washing = WashingMachine::query()->where('name', 'LIKE',$request->nameCheck)->where('location_id', '=', $request->location)->where('id', '!=', $request->id)->get(); if(count($washing) > 0 && $request->nameCheck !== NULL){ diff --git a/skolehjem/app/Http/Controllers/WashingReservationController.php b/skolehjem/app/Http/Controllers/WashingReservationController.php index f3c4fda..05a9ab2 100644 --- a/skolehjem/app/Http/Controllers/WashingReservationController.php +++ b/skolehjem/app/Http/Controllers/WashingReservationController.php @@ -76,6 +76,7 @@ class WashingReservationController extends Controller $allMachineReservations = WashingReservation::query()->where('time', '=', $request->time)->where('machine_id', '=', $request->machine_id)->get(); + //Check if a reservation at that time on that machine already exists if (count($allMachineReservations) > 0) { return redirect()->route("washing-reservations.create", ["washing_reservation" => $machineReservation])->with('ReservationExists', '

Der findes allerede en reservation til denne tid, men denne vaskemaskine!

'); } else { @@ -143,6 +144,7 @@ class WashingReservationController extends Controller return redirect()->route("washing-reservations.index", [ "reservations" => $reservations]); } + //Used for creating the "create reservation" form in the app public function api(Request $request){ if($request->ajax()){ $date = $request->date; @@ -171,6 +173,7 @@ class WashingReservationController extends Controller } } + //Returns the washingmachines to an ajax request public function getMachines(Request $request){ if($request->ajax()){ if($request->location_id == 0) @@ -183,6 +186,7 @@ class WashingReservationController extends Controller } } + //Returns the unavailable reservation times to an ajax request public function getTimes(Request $request){ if($request->ajax()){ if($request->location_id == 0) @@ -203,6 +207,7 @@ class WashingReservationController extends Controller $output = json_encode(["unavailable_times" => $times]); return Response($output); } + return null; } public function appindex(Request $request) diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index 86c9024..656c571 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -44,16 +44,6 @@ Route::post("/feedbacks/store", "FeedbackController@storeajax")->name("feedbacks Route::get("/signup", "UserController@signup")->name("users.signup"); Route::post("/signupStore", "UserController@signupStore")->name("users.signupStore"); -//Search/Filter -Route::get("/contactsapi", "ContactController@search")->name("contacts.search"); -Route::get("/eventsapi", "EventController@search")->name("events.search"); -Route::get("/menuplansapi", "MenuPlanController@search")->name("menu-plans.search"); -Route::get("/rolesapi", "RolesController@search")->name("roles.search"); -Route::get("/userapi", "UserController@search")->name("users.search"); -Route::get("/vaskeapi", "WashingReservationController@search")->name("washing-reservations.search"); -Route::get("/risrosapi", "FeedbackController@search")->name("feedbacks.search"); -Route::get("/machineapi", "WashingMachineController@search")->name("washing-machines.search"); - //Cookies Route::get("/languages", "UserController@setLanguages")->name("users.setLanguages"); Route::get("/darkmode", "UserController@setDarkMode")->name("users.setDarkMode");