Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated dinner form v1 #1046

Merged
merged 9 commits into from
May 12, 2020
Empty file modified app/Events/Event.php
100755 → 100644
Empty file.
160 changes: 160 additions & 0 deletions app/Http/Controllers/DinnerformController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php

namespace Proto\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;
use Proto\Models\Dinnerform;
use Carbon\Carbon;

use Session;
use Auth;
use Response;

class DinnerformController extends Controller
{
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
{
$dinnerformList = Dinnerform::all()->sortByDesc('end');

return view('dinnerform.admin', ['dinnerformCurrent' => null, 'dinnerformList' => $dinnerformList]);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request)
{
$dinnerform = new Dinnerform();
$dinnerform->restaurant = $request->restaurant;
$dinnerform->description = $request->description;
$dinnerform->url = $request->url;
$dinnerform->start = strtotime($request->start);
$dinnerform->end = strtotime($request->end);
Jessseee marked this conversation as resolved.
Show resolved Hide resolved

if ($dinnerform->end < $dinnerform->start) {
Session::flash("flash_message", "You cannot let the dinner form close before it opens.");
return Redirect::back();
}
Jessseee marked this conversation as resolved.
Show resolved Hide resolved

$dinnerform->save();

Session::flash("flash_message", "Your dinner form at '" . $dinnerform->restaurant . "' has been added.");
return Redirect::route('dinnerform::add');

}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$dinnerform = Dinnerform::findOrFail($id);

if ($dinnerform->isCurrent()) {
return Redirect::away($dinnerform->url);
} else {
Session::flash("flash_message", "Sorry, you can't order anymore, food is already on its way");
return Redirect::route('homepage');
}
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function edit($id)
{
$dinnerformCurrent = Dinnerform::findOrFail($id);
$dinnerformList = Dinnerform::all()->sortByDesc('end');

return view('dinnerform.admin', ['dinnerformCurrent' => $dinnerformCurrent, 'dinnerformList' => $dinnerformList]);
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request, $id)
{

$dinnerform = Dinnerform::findOrFail($id);

$changed_important_details = $dinnerform->start->timestamp != strtotime($request->start) || $dinnerform->end->timestamp != strtotime($request->end) || $dinnerform->restaurant != $request->restaurant;

$dinnerform->restaurant = $request->restaurant;
$dinnerform->start = strtotime($request->start);
$dinnerform->end = strtotime($request->end);
$dinnerform->description = $request->description;
Jessseee marked this conversation as resolved.
Show resolved Hide resolved

if ($dinnerform->end < $dinnerform->start) {
Session::flash("flash_message", "You cannot let the dinnerform close before it opens.");
return Redirect::back();
}
Jessseee marked this conversation as resolved.
Show resolved Hide resolved

$dinnerform->save();

if ($changed_important_details) {
Session::flash("flash_message", "Your dinner form for '" . $dinnerform->restaurant . "' has been saved. You updated some important information. Don't forget to update your participants with this info!");
} else {
Session::flash("flash_message", "Your dinner form for '" . $dinnerform->restaurant . "' has been saved.");
}

return Redirect::route('dinnerform::add');

}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$dinnerform = Dinnerform::findOrFail($id);

Session::flash("flash_message", "The dinner form for '" . $dinnerform->restaurant . "' has been deleted.");

if(URL::previous() != route('dinnerform::edit', ['id' => $dinnerform->id])) {
$dinnerform->delete();
return Redirect::back();
} else {
$dinnerform->delete();
return Redirect::route('dinnerform::add');
}
Jessseee marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Close the specified resource by changing the end time to the current time.
*
* @param $id
* @return \Illuminate\Http\Response
*/
public function close($id)
{
$dinnerform = Dinnerform::findOrFail($id);
$dinnerform->end = Carbon::now();
$dinnerform->save();
return Redirect::route('dinnerform::add');
}

}
4 changes: 3 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Proto\Models\OrderLine;
use Proto\Models\Page;
use Proto\Models\User;
use Proto\Models\Dinnerform;

use Auth;
use Carbon;
Expand All @@ -36,13 +37,14 @@ public function show()
$companies = Company::where('in_logo_bar', true)->orderBy('sort', 'asc')->get();
$newsitems = Newsitem::where('published_at', '<=', Carbon::now())->where('published_at', '>', Carbon::now()->subWeeks(2))->orderBy('published_at', 'desc')->take(3)->get();
$birthdays = User::has('member')->where('show_birthday', true)->where('birthdate', 'LIKE', date('%-m-d'))->get();
$dinnerform = Dinnerform::where('start', '<=', Carbon::now())->where('end', '>', Carbon::now()->subHour(1))->first();
$header = HeaderImage::inRandomOrder()->first();
$videos = Video::orderBy('video_date', 'desc')->where('video_date', '>', Carbon::now()->subMonths(3))->limit(3)->get();

if (Auth::check() && Auth::user()->member) {
$message = WelcomeMessage::where('user_id', Auth::user()->id)->first();
return view('website.home.members', ['companies' => $companies, 'message' => $message,
'newsitems' => $newsitems, 'birthdays' => $birthdays, 'header' => $header, 'videos' => $videos]);
'newsitems' => $newsitems, 'birthdays' => $birthdays, 'dinnerform' => $dinnerform, 'header' => $header, 'videos' => $videos]);
} else {
return view('website.home.external', ['companies' => $companies, 'header' => $header]);
}
Expand Down
52 changes: 52 additions & 0 deletions app/Models/Dinnerform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Proto\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Dinnerform extends Model
{

protected $hidden = ['created_at', 'updated_at'];

protected $dates = ['start', 'end'];

protected $guarded = ['id'];

/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'dinnerforms';

/**
* Generate a timespan string with format 'D H:i'.
*
* @return string
*/
public function generateTimespanText()
{
return $this->start->format('D H:i') . " - " . Carbon::parse($this->end)->format('D H:i');
}

/**
* Check if a dinnerform is currently open.
*
* @return bool
*/
public function isCurrent() {
return $this->start->isPast() && $this->end->isFuture();
}

/**
* Check if dinnerform is more than 1 hour past end time.
*
* @return bool
*/
public function hasExpired() {
return $this->end->addHours(1)->isPast();
}

}
5 changes: 5 additions & 0 deletions config/hashids.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
'length' => '16',
],

'dinnerform' => [
'salt' => getenv('HASHIDS_SECRET_DINNERFORM'),
Jessseee marked this conversation as resolved.
Show resolved Hide resolved
'length' => '16',
]

],

];
36 changes: 36 additions & 0 deletions database/migrations/2019_11_29_103335_create_dinnerforms_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateDinnerformsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('dinnerforms', function (Blueprint $table) {
$table->increments('id');
$table->string('restaurant');
$table->string('description');
$table->string('url');
$table->dateTime("start");
$table->dateTime('end');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('dinnerforms');
}
}
20 changes: 20 additions & 0 deletions resources/views/dinnerform/admin.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@extends('website.layouts.redesign.generic')
Jessseee marked this conversation as resolved.
Show resolved Hide resolved

@section('page-title')
Dinner Form Admin
@endsection

@section('container')
<div class="row">
<div class="col-xl-4">

@include('dinnerform.admin_includes.dinnerform-details')

</div>
<div class="col-xl-8">

@include('dinnerform.admin_includes.dinnerform-list')

</div>
</div>
@endsection
13 changes: 13 additions & 0 deletions resources/views/dinnerform/admin_includes/buttonbar.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="card-footer border-bottom">
Jessseee marked this conversation as resolved.
Show resolved Hide resolved

<button type="submit" class="btn btn-success pull-right" style="margin-left: 15px;">Submit
</button>

@if($dinnerformCurrent)
<a href="{{ route("dinnerform::delete", ['id' => $dinnerformCurrent->id]) }}"
class="btn btn-danger pull-left">Delete</a>
@endif

<a href="{{ route("dinnerform::add") }}"></a>

</div>