Skip to content

Commit

Permalink
Removed use of hashed ids and did some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jessseee committed Feb 13, 2020
1 parent a4dcae1 commit c1bd404
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
1 change: 0 additions & 1 deletion .env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ SAML2_IDP_KEY=X509_KEY_RELATIVE_PATH
PERSONAL_PROTO_KEY=personal_proto_key

HASHIDS_SECRET_EVENTS=RAND_STRING
HASHIDS_SECRET_DINNERFORM=RAND_STRING

SEPA_IBAN=IBAN
SEPA_BIC=BIC
Expand Down
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ SAML2_IDP_KEY=X509_KEY_RELATIVE_PATH
PERSONAL_PROTO_KEY=personal_proto_key

HASHIDS_SECRET_EVENTS=RAND_STRING
HASHIDS_SECRET_DINNERFORM=RAND_STRING

SEPA_IBAN=IBAN
SEPA_BIC=BIC
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/DinnerformController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Illuminate\Http\Request;

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

use Session;
use Redirect;
use Auth;
use Response;

Expand All @@ -22,7 +22,7 @@ class DinnerformController extends Controller
*/
public function create()
{
$dinnerformList = Dinnerform::all();
$dinnerformList = Dinnerform::all()->sortByDesc('end');

return view('dinnerform.admin', ['dinnerformCurrent' => null, 'dinnerformList' => $dinnerformList]);
}
Expand Down Expand Up @@ -62,7 +62,7 @@ public function store(Request $request)
*/
public function show($id)
{
$dinnerform = Dinnerform::fromPublicId($id);
$dinnerform = Dinnerform::findOrFail($id);

if ($dinnerform->isCurrent()) {
return Redirect::away($dinnerform->url);
Expand All @@ -81,7 +81,7 @@ public function show($id)
public function edit($id)
{
$dinnerformCurrent = Dinnerform::findOrFail($id);
$dinnerformList = Dinnerform::all();
$dinnerformList = Dinnerform::all()->sortByDesc('end');

if($dinnerformCurrent != null) {
return view('dinnerform.admin', ['dinnerformCurrent' => $dinnerformCurrent, 'dinnerformList' => $dinnerformList]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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())->first();
$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();

Expand Down
35 changes: 17 additions & 18 deletions app/Models/Dinnerform.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\URL;
use Vinkla\Hashids\Facades\Hashids;

use Auth;

class Dinnerform extends Model
{
Expand All @@ -17,35 +12,39 @@ class Dinnerform extends Model

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

protected $guarded = ['id'];

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

public function getPublicId()
{
return Hashids::connection('dinnerform')->encode($this->id);
}

public static function fromPublicId($public_id)
{
$id = Hashids::connection('dinnerform')->decode($public_id);
return Dinnerform::findOrFail(count($id) > 0 ? $id[0] : 0);
}

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

protected $guarded = ['id'];

/**
* 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();
}
Expand Down
4 changes: 2 additions & 2 deletions resources/views/dinnerform/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

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

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

</div>
<div class="col-xl-4 offset-xl-2">
<div class="col-xl-8">

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<td>Open</td>
<td>Start</td>
<td>End</td>
<td>Controls</td>
<td></td>
</tr>

</thead>
Expand Down Expand Up @@ -59,6 +61,7 @@
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
@endif

Expand Down
4 changes: 2 additions & 2 deletions resources/views/dinnerform/dinnerform_block.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="card mb-3 leftborder leftborder-info">
<a style="text-decoration: none !important;"
href="{{ route("dinnerform::show", ['id' => $dinnerform->getPublicId()]) }}">
href="{{ route("dinnerform::show", ['id' => $dinnerform->id]) }}">
<div class="card-body" style="text-align: left;">
@if($dinnerform->hasExpired())
<div class="btn btn-danger btn-block mb-3 ">
Expand All @@ -10,7 +10,7 @@
@else
<div class="btn btn-info btn-block mb-3 ">
<i class="fas fa-history fa-fw fa-pulse mr-2" aria-hidden="true"></i>
<span class="proto-countdown" data-countdown-start="{{ $dinnerform->end->timestamp }}" data-countdown-text-counting="Closes in {}" data-countdown-text-finished="Food is underway!">
<span class="proto-countdown" data-countdown-start="{{ $dinnerform->end->timestamp }}" data-countdown-text-counting="Closes in {}" data-countdown-text-finished="Food is on its way!">
Counting down...
</span>
</div>
Expand Down

0 comments on commit c1bd404

Please sign in to comment.