diff --git a/skolehjem/app/Http/Controllers/AboutController.php b/skolehjem/app/Http/Controllers/AboutController.php index be083dd..2aa2764 100644 --- a/skolehjem/app/Http/Controllers/AboutController.php +++ b/skolehjem/app/Http/Controllers/AboutController.php @@ -7,14 +7,32 @@ use Illuminate\Http\Response; class AboutController extends Controller { + + //Check authentication and languages settings public function __construct() { + //The middleware is being run just before the pages is getting loaded $this->middleware(["auth"]); $this->middleware(["lang"]); } + /* + Index controller, all backend work for the about index + pages is done here. + */ public function index(Request $request) { + /* + Response::detect is a library that we use to + detect if you are on mobile or desktop. + If you are on mobile it sends you to the + /resources/views/app/about/index + and if you are on desktop it sends you to + /resources/views/admin/about/index (There is no "about" on desktop view). + + Normally the index pages only contain the return of the index pages + but you are allowed to modify the index function to how may like. + */ return Response::detect("about.index"); } } diff --git a/skolehjem/app/Http/Controllers/AllowActionController.php b/skolehjem/app/Http/Controllers/AllowActionController.php index 191e3df..f9a5813 100644 --- a/skolehjem/app/Http/Controllers/AllowActionController.php +++ b/skolehjem/app/Http/Controllers/AllowActionController.php @@ -7,8 +7,20 @@ use Illuminate\Http\Request; class AllowActionController extends Controller { + /*We use $request to get the data from the HTMl pages*/ function AllowActionRegistering(Request $request) { + /* + Here we use our model AllowAction and the Laravel function "find", + in the "find" functions parameter we pass "$request->id" to find out what + number the it contains. + */ $action = AllowAction::find($request->id); + + /*Call the Laravel "update" function to update number in the database + + If the allow column in the database is equal to 1 there is open for registration + If the allow column is equal to 0 there is closed for registration + */ $action->update([ 'allow' => $request->allow ]); } } diff --git a/skolehjem/app/Http/Controllers/ContactController.php b/skolehjem/app/Http/Controllers/ContactController.php index 47db1e6..2f59a16 100644 --- a/skolehjem/app/Http/Controllers/ContactController.php +++ b/skolehjem/app/Http/Controllers/ContactController.php @@ -12,9 +12,13 @@ class ContactController extends Controller { public function __construct() { + //Check authentication and languages settings $this->middleware([ "auth" ]); $this->middleware([ "lang" ]); + //The middleware is being run just before the pages is getting loaded. + + //We use this middleware to chek if a user has the right permission/authentication to view the pages $this->middleware([ "check.auth:contact.show" ])->only("show", "index"); $this->middleware([ "check.auth:contact.create" ])->only("create", "store"); $this->middleware([ "check.auth:contact.edit" ])->only("edit", "update"); @@ -26,10 +30,19 @@ class ContactController extends Controller * * @return \Illuminate\Http\Response */ + + //Controller for the contact index pages, all backend work for the contact index pages is done here. public function index(Request $request) { + //We use the Contact model to query all information from the contact form in the database $contact = Contact::query()->get(); + /* + Here we return/pass the contact variable containing all the database information to the + contacts.index pages as a parameter. The "contacts" in green text is the name you have to use + on the index pages to get the data from the database, you can name it what ever you want, but its best + best practice to give it a describing name. + */ return Response::detect("contacts.index", [ "contacts" => $contact]); } @@ -38,10 +51,11 @@ class ContactController extends Controller * * @return \Illuminate\Http\Response */ + + /*The create controller, all it has to do is redirect you to the contacts create pages*/ public function create() { return Response::detect("contacts.create"); - } /** @@ -50,8 +64,11 @@ class ContactController extends Controller * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ + + //The store controller is used to store user data. public function store(Request $request) { + //Validate that the user gave a contactname, title, email, phone and make sure its required and only contains max 255. $requestContact = $request->validate([ "contactname" => "required|max:255", "title" => "required|max:255", @@ -59,13 +76,20 @@ class ContactController extends Controller "phone" => "max:255", ]); + //Make a new instance of the contact modal and pass $requestContact to be saved in the database $contact = new Contact($requestContact); + //Set phonetimes to what the user entered, we dont validate thats why it has its on "save" function . $contact->phonetimes = $request->phonetimes; + //Call the save function. $saved = $contact->save(); + //If it couldn't save redirect to the contacts.store view if(!$saved){ return redirect()->route("contacts.store"); }else{ + /*If it did get saved query all information from the database and redirect to contacts.index with the parameter + contacts + */ $contact = Contact::query()->get(); return redirect()->route("contacts.index", ['contacts' => $contact]); } @@ -78,6 +102,8 @@ class ContactController extends Controller * @param int $id * @return \Illuminate\Http\Response */ + + //The show controller is used to show a single entity from the database based on the id its get public function show($id) { return Response::detect("contacts.show", [ "contacts" => $id]); @@ -90,6 +116,10 @@ class ContactController extends Controller * @param int $id * @return \Illuminate\Http\Response */ + + /*Edit controller finds all the data on the specific id passed to it, finds that entity from the database and + that match with the id and redirect you to the edit pages. + */ public function edit($id) { $contact = Contact::find($id); @@ -103,17 +133,26 @@ class ContactController extends Controller * @param int $id * @return \Illuminate\Http\Response */ + + //Update controller public function update(Request $request, $id) { - + //request all the data from the database $data = $request->all(); + //Find the entity in the database that match the id $contact = Contact::find($id); + //Call the update function $contact->update($data); + //Call the save function $saved = $contact->save(); + //If it couldn't save redirect to the contacts.update view if(!$saved){ return redirect()->route("contacts.update", [ "contacts" => $contact ]); }else{ + /*If it did get saved query all information from the database and redirect to contacts.index with the parameter + contacts + */ $contact = Contact::query()->get(); return redirect()->route("contacts.index", ['contacts' => $contact]); } @@ -127,6 +166,7 @@ class ContactController extends Controller * @return \Illuminate\Http\RedirectResponse * @throws \Exception */ + //The destroy controller finds the id and calls a delete function, after that it redirects to contact index. public function destroy($id) { $contact = Contact::find($id); diff --git a/skolehjem/app/Http/Controllers/EventController.php b/skolehjem/app/Http/Controllers/EventController.php index 0952bd7..db3653e 100644 --- a/skolehjem/app/Http/Controllers/EventController.php +++ b/skolehjem/app/Http/Controllers/EventController.php @@ -81,10 +81,14 @@ class EventController extends Controller $event->save(); $events = Event::query()->get(); + //If the check on the create pages that is was a news and has to be displayed on the news pages if($request->newsoption == true){ + //Get all events from the database $events = Event::query()->get(); + //make a new object of the news calls $news = new News(); + //Get and save the data $news->name = "Ny aktivitet"; $news->subname = $event->name; $news->arrangement_id = $event->id; @@ -93,6 +97,7 @@ class EventController extends Controller $news->resource_id = $event->resource_id; $news->news_expiration_date = $events[0]->date; + //Call the news controller function store and get, pass $news to be saved NewsController::storeAndGet($news); } @@ -108,7 +113,9 @@ class EventController extends Controller */ public function show($id) { + //Get the entity that match with the passed id. $event = Event::query()->where("id", "=", $id)->first(); + //return the fetch data to the show pages return Response::detect("events.show", [ "event" => $event ]); } @@ -164,17 +171,23 @@ class EventController extends Controller */ public function update(Request $request, $id) { + //Set $data to holde the value of request->all $data = $request->all(); + //Get the event with matching id $event = Event::find($id); + //get all events that has a match with the passed id $allEvents = Event::query()->where('name', '=', $request->name)->where('id', '!=', $id)->get(); + //If the amount of $allevents is equal to 0 redirect to index if(count($allEvents) > 0){ return redirect()->route("events.index", ['events' => $event]); }else{ + //Call the update function $event->update($data); + //If the events has a images call the Resource Controllers store function if($request->file("resource")) { $event->resource_id = ResourceController::store($request)->id; } @@ -240,6 +253,7 @@ class EventController extends Controller } //Fixes tags that have been substringed + //idk yoink this bitch from stackoverflow, you never going to use it, trust me. public function closetags($html) { preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?#iU', $html, $result); $openedtags = $result[1]; @@ -261,6 +275,7 @@ class EventController extends Controller } public function deleteNotifications(Request $request){ + //If the request is equal to ajax, delete every notification where the user_id is = to the $request->user_id if($request->ajax()){ foreach (Notification::query()->where("user_id", "=", $request->user_id)->get() as $notification) { $notification->delete(); @@ -273,6 +288,7 @@ class EventController extends Controller //Used for checking if the currently typed event name is unique. Create version public function nameCheck(Request $request){ + //Search the database to check that the name they are typing is uniq $event = Event::query()->where('name', 'LIKE',$request->nameCheck)->get(); if(count($event) > 0 && $request->nameCheck !== NULL){ return 1; @@ -288,11 +304,9 @@ class EventController extends Controller } public function previewPages(Request $request){ - //if(!Resource::find($request->preview)){ - // $event = Event::find($request->preview); - //}else{ - $event = Event::where('events.id', '=', $request->preview)->leftJoin('resources', 'resources.id', '=', 'events.resource_id')->first(); - //} + //get the data from the database that match the request and leftjoin the resources table + $event = Event::where('events.id', '=', $request->preview)->leftJoin('resources', 'resources.id', '=', 'events.resource_id')->first(); + //convert dababy to a convertible $convertToJsonArray = json_encode($event); return $convertToJsonArray; } diff --git a/skolehjem/app/Http/Controllers/MenuPlanController.php b/skolehjem/app/Http/Controllers/MenuPlanController.php index d528a57..cd61ac8 100644 --- a/skolehjem/app/Http/Controllers/MenuPlanController.php +++ b/skolehjem/app/Http/Controllers/MenuPlanController.php @@ -214,19 +214,25 @@ class MenuPlanController extends Controller * @return RedirectResponse */ public function genPDF($Id){ + //get the menuplan with the matching id $menuPlan = MenuPlan::query()->where("id", "=", $Id)->first(); + //Sub string cap $var = 250; + //Substring the data $menuPlan->monday = substr($menuPlan->monday, 0, $var); $menuPlan->tuesday = substr($menuPlan->tuesday, 0, $var); $menuPlan->wednesday = substr($menuPlan->wednesday, 0, $var); $menuPlan->thursday = substr($menuPlan->thursday, 0, $var); + //Pass the substring data to the genPDF pages $pdf = PDF::loadView('pdf.menuplan', ["menuPlan" => $menuPlan]); + //PDF config $pdf->setPaper('A4', 'portrait'); + //return the pdf return $pdf->stream("menuplan_uge_".$menuPlan->week.".pdf"); } diff --git a/skolehjem/app/Http/Controllers/NewsController.php b/skolehjem/app/Http/Controllers/NewsController.php index 0e7d494..daafca9 100644 --- a/skolehjem/app/Http/Controllers/NewsController.php +++ b/skolehjem/app/Http/Controllers/NewsController.php @@ -33,7 +33,7 @@ class NewsController extends Controller */ public function index(Request $request) { - //Edit is fuck cuz of my inner join, has to get fixed at som point + //joining news and news_types $news = News::query() ->join("news_types", "news.type_id", "=", "news_types.id") ->orderBy('id', 'desc') diff --git a/skolehjem/app/Http/Controllers/UserController.php b/skolehjem/app/Http/Controllers/UserController.php index 05dec76..d48cddc 100644 --- a/skolehjem/app/Http/Controllers/UserController.php +++ b/skolehjem/app/Http/Controllers/UserController.php @@ -1,4 +1,5 @@