Skip to content

Commit

Permalink
Merge pull request #1046 from saproto/feature/1023/integrated-dinner-…
Browse files Browse the repository at this point in the history
…form

Integrated dinner form v1
  • Loading branch information
jonathanjuursema committed May 12, 2020
2 parents fc1f85a + 1c04747 commit 9a25c94
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 3 deletions.
Empty file modified app/Events/Event.php
100755 → 100644
Empty file.
159 changes: 159 additions & 0 deletions app/Http/Controllers/DinnerformController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?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)
{
if ($request->end < $request->start) {
Session::flash("flash_message", "You cannot let the dinner form close before it opens.");
return Redirect::back();
}

$dinnerform = Dinnerform::create([
'restaurant' => $request->restaurant,
'description' => $request->description,
'url' => $request->url,
'start' => strtotime($request->start),
'end' => strtotime($request->end),
]);

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)
{

if ($request->end < $request->start) {
Session::flash("flash_message", "You cannot let the dinnerform close before it opens.");
return Redirect::back();
}

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

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

$dinnerform->update([
'restaurant' => $request->restaurant,
'start' => strtotime($request->start),
'end' => strtotime($request->end),
'description' => $request->description,
]);

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.");

$dinnerform->delete();

if(URL::previous() != route('dinnerform::edit', ['id' => $dinnerform->id])) {
return Redirect::back();
} else {
return Redirect::route('dinnerform::add');
}
}

/**
* 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();
}

}
2 changes: 1 addition & 1 deletion config/hashids.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'event' => [
'salt' => getenv('HASHIDS_SECRET_EVENTS'),
'length' => '16',
],
]

],

Expand Down
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')

@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

0 comments on commit 9a25c94

Please sign in to comment.