198 lines
6.9 KiB
PHP
198 lines
6.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\MultipleEvents;
|
|
use App\MultipleEventsParent;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
//Not in use yet
|
|
use App\Event;
|
|
use App\News;
|
|
use App\Notification;
|
|
use App\Resource;
|
|
use App\UserEvent;
|
|
|
|
class MultipleEventsController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware([ "auth" ]);
|
|
$this->middleware([ "lang" ]);
|
|
|
|
$this->middleware([ "check.auth:event.show" ])->only("show", "index");
|
|
$this->middleware([ "check.auth:event.create" ])->only("create", "store");
|
|
$this->middleware([ "check.auth:event.edit" ])->only("edit", "update");
|
|
$this->middleware([ "check.auth:event.delete" ])->only("delete");
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$multiEvents = MultipleEventsParent::query()->join("multiple_events", "multiple_events.multiple_events_parent_id", "=", "multiple_events_parent.id")->orderBY('multiple_events_parent.id' , 'desc')->get();
|
|
return Response::detect("multiple-events.index", [ "multiEvents" => $multiEvents]);
|
|
}
|
|
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//returns create multiple events blade file from the view folder
|
|
return Response::detect("multiple-events.create");
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$requestBody = $request->validate([
|
|
"week" => "max:255",
|
|
"name" => "array",
|
|
"description" => "array",
|
|
"accountable" => "array",
|
|
"date" => "array",
|
|
"name.*" => "max:255",
|
|
"description.*" => "max:255",
|
|
"accountable.*" => "max:255",
|
|
"date.*" => "max:255"
|
|
]);
|
|
|
|
$multipleParent = new MultipleEventsParent();
|
|
|
|
$multipleParent->week = $request->week;
|
|
if($request->file("resource")) {
|
|
$multipleParent->resource_id = ResourceController::store($request)->id;
|
|
}
|
|
$multipleParent->save();
|
|
|
|
|
|
|
|
|
|
for ($i = 0; $i < count($requestBody["name"]); $i++) {
|
|
$multi_event = new MultipleEvents();
|
|
|
|
$multi_event->date = $requestBody['date'][$i];
|
|
$multi_event->description = $requestBody['description'][$i];
|
|
$multi_event->accountable = $requestBody['accountable'][$i];
|
|
$multi_event->name = $requestBody['name'][$i];
|
|
$multi_event->event_end = "2021-27-04 16:00:00";
|
|
$multi_event->multiple_events_parent_id = $multipleParent->id;
|
|
$multi_event->save();
|
|
}
|
|
|
|
//creates a new Event model with the given parameter
|
|
$event = new MultipleEventsParent($requestBody);
|
|
|
|
$multiEvents = MultipleEventsParent::query()->get();
|
|
if($request->newsoption == true){
|
|
$news = new News();
|
|
$news->name = "Nye ugenlig aktivitet";
|
|
$news->subname = $event->week;
|
|
$news->arrangement_id = $multipleParent->id;
|
|
$news->type_id = '5';
|
|
$news->content = "Den ugenlige aktivitets plan er landet";
|
|
$news->resource_id = $event->resource_id;
|
|
NewsController::storeAndGet($news);
|
|
|
|
}
|
|
|
|
return redirect()->route('multiple-events.index', ['multiEvents' => $multiEvents]);
|
|
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param \App\MultipleEvents $multipleeventsController
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(MultipleeventsController $multipleeventsController)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\MultipleEvents $multipleeventsController
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(MultipleeventsController $multipleeventsController)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \App\MultipleEvents $multipleeventsController
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, MultipleeventsController $multipleeventsController)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\MultipleEvents $multipleeventsController
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Request $request, MultipleeventsController $multipleeventsController)
|
|
{
|
|
if ($request->signup != null) { // If input signup is not empty, which has been set when you look at the individuel signup, then delete the user who have signed up for the event
|
|
$UserEvent = UserEvent::query()->where('user_id', "=", $request->signup)->where('multiple_event_id', "=", $multipleeventsController);
|
|
|
|
$UserEvent->delete();
|
|
|
|
return redirect()->route("multiple-events.signups", [ "event" => $multipleeventsController ]);
|
|
} else { // Else if you are deleting an event. Then delete all the sign ups AND the event
|
|
$userEvents = UserEvent::where('multiple_event_id', "=", $multipleeventsController)->get();
|
|
$multiparent = MultipleEventsParent::where('id', '=', $multipleeventsController)->get();
|
|
$multievent = MultipleEvents::where('multiple_events_parent_id', '=', $multiparent->id)->get();
|
|
|
|
foreach ($userEvents as $userEvent) {
|
|
$userEvent->delete();
|
|
}
|
|
|
|
foreach ($multievent as $me) {
|
|
$me->delete();
|
|
}
|
|
|
|
$news = News::query()->join('news_types', 'news_types.id', '=', 'news.type_id')->where("type", "=", "MultipleEvent")->where("arrangement_id", "=", $multipleeventsController);
|
|
$news->delete();
|
|
|
|
$multiparent->delete();
|
|
|
|
return redirect()->route("multiple-events.index");
|
|
}
|
|
}
|
|
|
|
public function previewPages(Request $request){
|
|
/*if(!Resource::find($request->preview)){
|
|
$multipleEventsParent = MultipleEventsParent::find($request->preview);
|
|
$multipleEvents = MultipleEvents::where('multiple_events_parent_id', '=', $multipleEventsParent->id)->get();
|
|
} else {*/
|
|
//$multipleEventsParent = MultipleEventsParent::find($request->preview);
|
|
$multipleEventsParent = MultipleEventsParent::leftJoin('resources', 'resources.id', '=', 'multiple_events_parent.resource_id')->where('multiple_events_parent.id', '=', $request->preview)->first();
|
|
$multipleEvents = MultipleEvents::where('multiple_events_parent_id', '=', $multipleEventsParent->id)->get();
|
|
//}
|
|
|
|
return [$multipleEventsParent, $multipleEvents];
|
|
}
|
|
}
|