2020-06-23 09:59:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-08-12 13:25:29 +00:00
|
|
|
use App;
|
2020-06-25 08:34:10 +00:00
|
|
|
use App\MenuPlan;
|
2020-08-07 08:58:50 +00:00
|
|
|
use App\News;
|
2020-07-30 12:38:32 +00:00
|
|
|
use App\User;
|
2020-08-18 13:27:58 +00:00
|
|
|
use Barryvdh\DomPDF\Facade as PDF;
|
2020-08-12 13:25:29 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2020-06-23 09:59:26 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-06-25 08:34:10 +00:00
|
|
|
use Illuminate\Http\Response;
|
2020-07-27 14:03:49 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-07-30 12:38:32 +00:00
|
|
|
use Spatie\Permission\Models\Permission;
|
|
|
|
use Spatie\Permission\Models\Role;
|
2020-06-25 08:34:10 +00:00
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
|
|
|
|
class MenuPlanController extends Controller
|
|
|
|
{
|
2020-06-30 07:21:21 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware([ "auth" ]);
|
2020-08-06 13:31:38 +00:00
|
|
|
$this->middleware([ "lang" ]);
|
2020-06-30 07:21:21 +00:00
|
|
|
|
2020-08-31 07:36:10 +00:00
|
|
|
$this->middleware([ "check.auth:menuplan.show" ])->only("show", "index");
|
2020-06-30 07:21:21 +00:00
|
|
|
$this->middleware([ "check.auth:menuplan.create" ])->only("create", "store");
|
|
|
|
$this->middleware([ "check.auth:menuplan.edit" ])->only("edit", "update");
|
|
|
|
$this->middleware([ "check.auth:menuplan.delete" ])->only("delete");
|
|
|
|
}
|
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-25 08:34:10 +00:00
|
|
|
public function index(Request $request)
|
2020-06-23 09:59:26 +00:00
|
|
|
{
|
2020-06-25 08:34:10 +00:00
|
|
|
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
|
|
|
|
|
2020-06-25 10:37:17 +00:00
|
|
|
return Response::detect("menuplans.index", [ "menuPlans" => $menuPlans]);
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-25 13:29:43 +00:00
|
|
|
public function create()
|
2020-06-23 09:59:26 +00:00
|
|
|
{
|
2020-06-25 10:37:17 +00:00
|
|
|
return Response::detect("menuplans.create");
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-06-25 10:22:22 +00:00
|
|
|
$requestMenuPlanCreate = $request->validate([
|
2020-08-17 10:24:43 +00:00
|
|
|
"week" => "required|max:255",
|
|
|
|
"monday" => "required|max:255",
|
|
|
|
"tuesday" => "required|max:255",
|
|
|
|
"wednesday" => "required|max:255",
|
|
|
|
"thursday" => "required|max:255",
|
2020-06-25 10:22:22 +00:00
|
|
|
]);
|
|
|
|
|
2020-08-07 08:58:50 +00:00
|
|
|
$menuPlan = new MenuPlan($requestMenuPlanCreate);
|
2020-06-25 10:22:22 +00:00
|
|
|
|
2020-08-04 08:11:18 +00:00
|
|
|
$allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->get();
|
|
|
|
|
|
|
|
if(count($allMenuPlans) > 0)
|
2020-08-17 08:21:02 +00:00
|
|
|
return redirect()->route("menu-plans.index");
|
2020-08-04 08:11:18 +00:00
|
|
|
else {
|
2020-08-07 08:58:50 +00:00
|
|
|
$menuPlan->save();
|
2020-07-01 07:16:53 +00:00
|
|
|
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
|
2020-08-07 08:58:50 +00:00
|
|
|
|
2020-08-17 10:24:43 +00:00
|
|
|
$menuArray = [];
|
|
|
|
|
2020-08-07 08:58:50 +00:00
|
|
|
if($request->newsoption == true){
|
|
|
|
$news = new News();
|
|
|
|
|
2020-08-10 07:37:19 +00:00
|
|
|
$news->name = "Ny menuplan";
|
|
|
|
$news->subname = "Uge " . $menuPlan->week;
|
2020-08-17 10:24:43 +00:00
|
|
|
$news->content =
|
|
|
|
'<h2 class="ql-align-center"><strong>Mandag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuPlan->monday.'</p><p class="ql-align-center"><br></p>'.
|
|
|
|
|
|
|
|
'<h2 class="ql-align-center"><strong>Tirsdag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuPlan->tuesday.'</p><p class="ql-align-center"><br></p>'.
|
|
|
|
|
|
|
|
'<h2 class="ql-align-center"><strong>Onsdag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuPlan->wednesday.'</p><p class="ql-align-center"><br></p>'.
|
|
|
|
|
|
|
|
'<h2 class="ql-align-center"><strong>Torsdag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuPlan->thursday.'</p>';
|
2020-08-13 05:38:14 +00:00
|
|
|
$news->type_id = '2';
|
|
|
|
$news->arrangement_id = $menuPlan->id;
|
2020-08-07 08:58:50 +00:00
|
|
|
|
2020-08-12 10:28:05 +00:00
|
|
|
if($request->file("resource")) {
|
|
|
|
$news->resource_id = ResourceController::store($request)->id;
|
|
|
|
}
|
|
|
|
|
2020-08-13 05:38:14 +00:00
|
|
|
NewsController::storeAndGet($news);
|
2020-08-07 08:58:50 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 08:11:18 +00:00
|
|
|
return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]);
|
2020-07-01 07:16:53 +00:00
|
|
|
}
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-26 11:55:04 +00:00
|
|
|
public function show(MenuPlan $id)
|
2020-06-23 09:59:26 +00:00
|
|
|
{
|
2020-06-26 11:55:04 +00:00
|
|
|
return Response::detect("menuplans.show", [ "menuplan" => $id]);
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2020-06-29 06:31:36 +00:00
|
|
|
$menuplan = MenuPlan::find($id);
|
|
|
|
return Response::detect("menuplans.edit", ["menuplan" => $menuplan]);
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
2020-06-29 06:31:36 +00:00
|
|
|
$data = $request->all();
|
2020-06-29 07:08:49 +00:00
|
|
|
//FORCED UPDATE
|
2020-06-25 10:44:06 +00:00
|
|
|
|
2020-06-29 06:31:36 +00:00
|
|
|
$menuplan = MenuPlan::find($id);
|
2020-07-01 07:43:11 +00:00
|
|
|
|
2020-08-04 08:11:18 +00:00
|
|
|
$allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->where('id', '!=', $id)->get();
|
|
|
|
|
|
|
|
if(count($allMenuPlans) > 0){
|
2020-08-17 08:21:02 +00:00
|
|
|
return redirect()->route("menu-plans.index");
|
2020-07-01 07:43:11 +00:00
|
|
|
}else{
|
2020-08-04 08:11:18 +00:00
|
|
|
$menuplan->update($data);
|
|
|
|
$menuplan->save();
|
|
|
|
|
2020-07-01 07:43:11 +00:00
|
|
|
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
|
2020-08-07 08:58:50 +00:00
|
|
|
|
|
|
|
if($request->newsoption == true){
|
2020-08-13 05:38:14 +00:00
|
|
|
$news = new News();
|
|
|
|
|
2020-08-10 07:37:19 +00:00
|
|
|
$news->name = "Opdateret menuplan";
|
|
|
|
$news->subname = "Uge " . $menuplan->week;
|
2020-08-12 13:17:48 +00:00
|
|
|
$news->arrangement_id = $menuplan->id;
|
|
|
|
$news->type_id = '2';
|
2020-08-17 10:24:43 +00:00
|
|
|
$news->content =
|
|
|
|
'<h2 class="ql-align-center"><strong>Mandag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuplan->monday.'</p><p class="ql-align-center"><br></p>'.
|
|
|
|
|
|
|
|
'<h2 class="ql-align-center"><strong>Tirsdag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuplan->tuesday.'</p><p class="ql-align-center"><br></p>'.
|
|
|
|
|
|
|
|
'<h2 class="ql-align-center"><strong>Onsdag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuplan->wednesday.'</p><p class="ql-align-center"><br></p>'.
|
|
|
|
|
|
|
|
'<h2 class="ql-align-center"><strong>Torsdag:</strong></h2>'.
|
|
|
|
'<p class="ql-align-center">'.$menuplan->thursday.'</p>';
|
2020-08-07 08:58:50 +00:00
|
|
|
|
2020-08-13 05:38:14 +00:00
|
|
|
|
2020-08-12 13:26:32 +00:00
|
|
|
NewsController::storeAndGet($news);
|
2020-08-07 08:58:50 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 08:11:18 +00:00
|
|
|
return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]);
|
2020-07-01 07:43:11 +00:00
|
|
|
}
|
2020-06-25 10:44:06 +00:00
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
2020-07-01 08:29:47 +00:00
|
|
|
* Test delete return index function.
|
2020-06-23 09:59:26 +00:00
|
|
|
* @param int $id
|
2020-08-12 13:25:29 +00:00
|
|
|
* @return RedirectResponse
|
2020-06-23 09:59:26 +00:00
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2020-08-31 10:48:59 +00:00
|
|
|
// Find the menu you want to remove
|
2020-06-29 06:31:36 +00:00
|
|
|
$menuplan = MenuPlan::find($id);
|
2020-08-31 10:48:59 +00:00
|
|
|
// Find the news the you made when creating the menu (if there is a news)
|
|
|
|
$news = News::query()->join('news_types', 'news_types.id', '=', 'news.type_id')->where('type', '=', 'Menu')->where('arrangement_id', '=', $id);
|
|
|
|
|
|
|
|
//Delete the news or/and menu
|
|
|
|
$news->delete();
|
2020-06-29 06:31:36 +00:00
|
|
|
$menuplan->delete();
|
|
|
|
return redirect()->route("menu-plans.index");
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
2020-07-27 14:03:49 +00:00
|
|
|
|
2020-08-12 13:25:29 +00:00
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
* Test delete return index function.
|
|
|
|
* @param $Id
|
|
|
|
* @return RedirectResponse
|
|
|
|
*/
|
|
|
|
public function genPDF($Id){
|
|
|
|
$menuPlan = MenuPlan::query()->where("id", "=", $Id)->first();
|
2020-08-18 13:27:58 +00:00
|
|
|
|
|
|
|
$var = 149;
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$pdf = PDF::loadView('pdf.menuplan', ["menuPlan" => $menuPlan]);
|
|
|
|
|
2020-08-14 09:22:18 +00:00
|
|
|
$pdf->setPaper('A4', 'portrait');
|
2020-08-13 07:19:44 +00:00
|
|
|
|
|
|
|
return $pdf->stream("menuplan_uge_".$menuPlan->week.".pdf");
|
2020-07-27 14:03:49 +00:00
|
|
|
|
2020-08-12 13:25:29 +00:00
|
|
|
}
|
2020-08-17 07:21:47 +00:00
|
|
|
|
|
|
|
public function nameCheck(Request $request){
|
|
|
|
$menuplan = MenuPlan::query()->where('week', 'LIKE',$request->nameCheck)->get();
|
|
|
|
if(count($menuplan) > 0 && $request->nameCheck !== NULL){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 08:21:02 +00:00
|
|
|
public function nameCheckUpdate(Request $request){
|
|
|
|
$menuplan = MenuPlan::query()->where('week', 'LIKE',$request->nameCheck)->where('id', '!=', $request->id)->get();
|
|
|
|
if(count($menuplan) > 0 && $request->nameCheck !== NULL){
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|