v1.5.24bb Added comments
This commit is contained in:
parent
20fe7dbcee
commit
3b0b2ff759
|
@ -7,14 +7,32 @@ use Illuminate\Http\Response;
|
||||||
|
|
||||||
class AboutController extends Controller
|
class AboutController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//Check authentication and languages settings
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
//The middleware is being run just before the pages is getting loaded
|
||||||
$this->middleware(["auth"]);
|
$this->middleware(["auth"]);
|
||||||
$this->middleware(["lang"]);
|
$this->middleware(["lang"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Index controller, all backend work for the about index
|
||||||
|
pages is done here.
|
||||||
|
*/
|
||||||
public function index(Request $request)
|
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");
|
return Response::detect("about.index");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,20 @@ use Illuminate\Http\Request;
|
||||||
|
|
||||||
class AllowActionController extends Controller
|
class AllowActionController extends Controller
|
||||||
{
|
{
|
||||||
|
/*We use $request to get the data from the HTMl pages*/
|
||||||
function AllowActionRegistering(Request $request) {
|
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);
|
$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 ]);
|
$action->update([ 'allow' => $request->allow ]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,13 @@ class ContactController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
//Check authentication and languages settings
|
||||||
$this->middleware([ "auth" ]);
|
$this->middleware([ "auth" ]);
|
||||||
$this->middleware([ "lang" ]);
|
$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.show" ])->only("show", "index");
|
||||||
$this->middleware([ "check.auth:contact.create" ])->only("create", "store");
|
$this->middleware([ "check.auth:contact.create" ])->only("create", "store");
|
||||||
$this->middleware([ "check.auth:contact.edit" ])->only("edit", "update");
|
$this->middleware([ "check.auth:contact.edit" ])->only("edit", "update");
|
||||||
|
@ -26,10 +30,19 @@ class ContactController extends Controller
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @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)
|
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();
|
$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]);
|
return Response::detect("contacts.index", [ "contacts" => $contact]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +51,11 @@ class ContactController extends Controller
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*The create controller, all it has to do is redirect you to the contacts create pages*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
return Response::detect("contacts.create");
|
return Response::detect("contacts.create");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,8 +64,11 @@ class ContactController extends Controller
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//The store controller is used to store user data.
|
||||||
public function store(Request $request)
|
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([
|
$requestContact = $request->validate([
|
||||||
"contactname" => "required|max:255",
|
"contactname" => "required|max:255",
|
||||||
"title" => "required|max:255",
|
"title" => "required|max:255",
|
||||||
|
@ -59,13 +76,20 @@ class ContactController extends Controller
|
||||||
"phone" => "max:255",
|
"phone" => "max:255",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
//Make a new instance of the contact modal and pass $requestContact to be saved in the database
|
||||||
$contact = new Contact($requestContact);
|
$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;
|
$contact->phonetimes = $request->phonetimes;
|
||||||
|
//Call the save function.
|
||||||
$saved = $contact->save();
|
$saved = $contact->save();
|
||||||
|
|
||||||
|
//If it couldn't save redirect to the contacts.store view
|
||||||
if(!$saved){
|
if(!$saved){
|
||||||
return redirect()->route("contacts.store");
|
return redirect()->route("contacts.store");
|
||||||
}else{
|
}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();
|
$contact = Contact::query()->get();
|
||||||
return redirect()->route("contacts.index", ['contacts' => $contact]);
|
return redirect()->route("contacts.index", ['contacts' => $contact]);
|
||||||
}
|
}
|
||||||
|
@ -78,6 +102,8 @@ class ContactController extends Controller
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @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)
|
public function show($id)
|
||||||
{
|
{
|
||||||
return Response::detect("contacts.show", [ "contacts" => $id]);
|
return Response::detect("contacts.show", [ "contacts" => $id]);
|
||||||
|
@ -90,6 +116,10 @@ class ContactController extends Controller
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @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)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
$contact = Contact::find($id);
|
$contact = Contact::find($id);
|
||||||
|
@ -103,17 +133,26 @@ class ContactController extends Controller
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//Update controller
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
//request all the data from the database
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
//Find the entity in the database that match the id
|
||||||
$contact = Contact::find($id);
|
$contact = Contact::find($id);
|
||||||
|
//Call the update function
|
||||||
$contact->update($data);
|
$contact->update($data);
|
||||||
|
//Call the save function
|
||||||
$saved = $contact->save();
|
$saved = $contact->save();
|
||||||
|
|
||||||
|
//If it couldn't save redirect to the contacts.update view
|
||||||
if(!$saved){
|
if(!$saved){
|
||||||
return redirect()->route("contacts.update", [ "contacts" => $contact ]);
|
return redirect()->route("contacts.update", [ "contacts" => $contact ]);
|
||||||
}else{
|
}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();
|
$contact = Contact::query()->get();
|
||||||
return redirect()->route("contacts.index", ['contacts' => $contact]);
|
return redirect()->route("contacts.index", ['contacts' => $contact]);
|
||||||
}
|
}
|
||||||
|
@ -127,6 +166,7 @@ class ContactController extends Controller
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
|
//The destroy controller finds the id and calls a delete function, after that it redirects to contact index.
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
$contact = Contact::find($id);
|
$contact = Contact::find($id);
|
||||||
|
|
|
@ -81,10 +81,14 @@ class EventController extends Controller
|
||||||
$event->save();
|
$event->save();
|
||||||
$events = Event::query()->get();
|
$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){
|
if($request->newsoption == true){
|
||||||
|
//Get all events from the database
|
||||||
$events = Event::query()->get();
|
$events = Event::query()->get();
|
||||||
|
//make a new object of the news calls
|
||||||
$news = new News();
|
$news = new News();
|
||||||
|
|
||||||
|
//Get and save the data
|
||||||
$news->name = "Ny aktivitet";
|
$news->name = "Ny aktivitet";
|
||||||
$news->subname = $event->name;
|
$news->subname = $event->name;
|
||||||
$news->arrangement_id = $event->id;
|
$news->arrangement_id = $event->id;
|
||||||
|
@ -93,6 +97,7 @@ class EventController extends Controller
|
||||||
$news->resource_id = $event->resource_id;
|
$news->resource_id = $event->resource_id;
|
||||||
$news->news_expiration_date = $events[0]->date;
|
$news->news_expiration_date = $events[0]->date;
|
||||||
|
|
||||||
|
//Call the news controller function store and get, pass $news to be saved
|
||||||
NewsController::storeAndGet($news);
|
NewsController::storeAndGet($news);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +113,9 @@ class EventController extends Controller
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
|
//Get the entity that match with the passed id.
|
||||||
$event = Event::query()->where("id", "=", $id)->first();
|
$event = Event::query()->where("id", "=", $id)->first();
|
||||||
|
//return the fetch data to the show pages
|
||||||
return Response::detect("events.show", [ "event" => $event ]);
|
return Response::detect("events.show", [ "event" => $event ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,17 +171,23 @@ class EventController extends Controller
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
//Set $data to holde the value of request->all
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
|
||||||
|
//Get the event with matching id
|
||||||
$event = Event::find($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();
|
$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){
|
if(count($allEvents) > 0){
|
||||||
return redirect()->route("events.index", ['events' => $event]);
|
return redirect()->route("events.index", ['events' => $event]);
|
||||||
}else{
|
}else{
|
||||||
|
//Call the update function
|
||||||
$event->update($data);
|
$event->update($data);
|
||||||
|
|
||||||
|
//If the events has a images call the Resource Controllers store function
|
||||||
if($request->file("resource")) {
|
if($request->file("resource")) {
|
||||||
$event->resource_id = ResourceController::store($request)->id;
|
$event->resource_id = ResourceController::store($request)->id;
|
||||||
}
|
}
|
||||||
|
@ -240,6 +253,7 @@ class EventController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fixes tags that have been substringed
|
//Fixes tags that have been substringed
|
||||||
|
//idk yoink this bitch from stackoverflow, you never going to use it, trust me.
|
||||||
public function closetags($html) {
|
public function closetags($html) {
|
||||||
preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
|
preg_match_all('#<(?!meta|img|br|hr|input\b)\b([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
|
||||||
$openedtags = $result[1];
|
$openedtags = $result[1];
|
||||||
|
@ -261,6 +275,7 @@ class EventController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteNotifications(Request $request){
|
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()){
|
if($request->ajax()){
|
||||||
foreach (Notification::query()->where("user_id", "=", $request->user_id)->get() as $notification) {
|
foreach (Notification::query()->where("user_id", "=", $request->user_id)->get() as $notification) {
|
||||||
$notification->delete();
|
$notification->delete();
|
||||||
|
@ -273,6 +288,7 @@ class EventController extends Controller
|
||||||
|
|
||||||
//Used for checking if the currently typed event name is unique. Create version
|
//Used for checking if the currently typed event name is unique. Create version
|
||||||
public function nameCheck(Request $request){
|
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();
|
$event = Event::query()->where('name', 'LIKE',$request->nameCheck)->get();
|
||||||
if(count($event) > 0 && $request->nameCheck !== NULL){
|
if(count($event) > 0 && $request->nameCheck !== NULL){
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -288,11 +304,9 @@ class EventController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
public function previewPages(Request $request){
|
public function previewPages(Request $request){
|
||||||
//if(!Resource::find($request->preview)){
|
//get the data from the database that match the request and leftjoin the resources table
|
||||||
// $event = Event::find($request->preview);
|
$event = Event::where('events.id', '=', $request->preview)->leftJoin('resources', 'resources.id', '=', 'events.resource_id')->first();
|
||||||
//}else{
|
//convert dababy to a convertible
|
||||||
$event = Event::where('events.id', '=', $request->preview)->leftJoin('resources', 'resources.id', '=', 'events.resource_id')->first();
|
|
||||||
//}
|
|
||||||
$convertToJsonArray = json_encode($event);
|
$convertToJsonArray = json_encode($event);
|
||||||
return $convertToJsonArray;
|
return $convertToJsonArray;
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,19 +214,25 @@ class MenuPlanController extends Controller
|
||||||
* @return RedirectResponse
|
* @return RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function genPDF($Id){
|
public function genPDF($Id){
|
||||||
|
//get the menuplan with the matching id
|
||||||
$menuPlan = MenuPlan::query()->where("id", "=", $Id)->first();
|
$menuPlan = MenuPlan::query()->where("id", "=", $Id)->first();
|
||||||
|
|
||||||
|
//Sub string cap
|
||||||
$var = 250;
|
$var = 250;
|
||||||
|
|
||||||
|
//Substring the data
|
||||||
$menuPlan->monday = substr($menuPlan->monday, 0, $var);
|
$menuPlan->monday = substr($menuPlan->monday, 0, $var);
|
||||||
$menuPlan->tuesday = substr($menuPlan->tuesday, 0, $var);
|
$menuPlan->tuesday = substr($menuPlan->tuesday, 0, $var);
|
||||||
$menuPlan->wednesday = substr($menuPlan->wednesday, 0, $var);
|
$menuPlan->wednesday = substr($menuPlan->wednesday, 0, $var);
|
||||||
$menuPlan->thursday = substr($menuPlan->thursday, 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 = PDF::loadView('pdf.menuplan', ["menuPlan" => $menuPlan]);
|
||||||
|
|
||||||
|
//PDF config
|
||||||
$pdf->setPaper('A4', 'portrait');
|
$pdf->setPaper('A4', 'portrait');
|
||||||
|
|
||||||
|
//return the pdf
|
||||||
return $pdf->stream("menuplan_uge_".$menuPlan->week.".pdf");
|
return $pdf->stream("menuplan_uge_".$menuPlan->week.".pdf");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class NewsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
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()
|
$news = News::query()
|
||||||
->join("news_types", "news.type_id", "=", "news_types.id")
|
->join("news_types", "news.type_id", "=", "news_types.id")
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
//Good luck kid, you gonna need it
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue