-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1046 from saproto/feature/1023/integrated-dinner-…
…form Integrated dinner form v1
- Loading branch information
Showing
13 changed files
with
513 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
'event' => [ | ||
'salt' => getenv('HASHIDS_SECRET_EVENTS'), | ||
'length' => '16', | ||
], | ||
] | ||
|
||
], | ||
|
||
|
36 changes: 36 additions & 0 deletions
36
database/migrations/2019_11_29_103335_create_dinnerforms_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.