Users timezones, rainbow font, fix deleting event types, sort event type by name
Diff
app/Http/routes.php | 2 +-
app/Models/Timezone.php | 40 ++++++++++++++++++++++++++++++++++++++++
app/Models/User.php | 20 ++++++++++++++++++++
database/migrations/2016_06_25_173046_create_users_timezones_table.php | 33 +++++++++++++++++++++++++++++++++
resources/assets/sass/_misc.sass | 6 ++++++
app/Http/Controllers/DJ/TimetableController.php | 40 +++++++++++++++++++++++++++++++++++++++-
app/Http/Controllers/Event/TimetableController.php | 12 +++++++++++-
app/Http/Controllers/Management/EventTypeController.php | 2 +-
8 files changed, 147 insertions(+), 8 deletions(-)
@@ -95,7 +95,7 @@
Route::get('event-type', ['as' => 'event-type', 'uses' => 'EventTypeController@index']);
Route::get('event-type/add', ['as' => 'event-type.form', 'uses' => 'EventTypeController@form']);
Route::put('event-type', ['as' => 'event-type.add', 'uses' => 'EventTypeController@add']);
Route::delete('event-type/{id}', ['as' => 'event-type.delete', 'uses' => 'eventtypecontroller@delete']);
Route::delete('event-type/{id}', ['as' => 'event-type.delete', 'uses' => 'EventTypeController@delete']);
});
Route::group([
@@ -1,0 +1,40 @@
<?php
namespace App\Models;
use Carbon\Carbon;
use Eloquent;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Query\Builder;
/**
* Table to hold all "remember me" tokens for users.
*
* @author Jordan Doyle <jordan@doyle.wf>
* @property integer $user_id id of the user this token belongs to
* @property string $timezone timezone this user wants to show times as
* @property Carbon $created_at when this timezone setting was created
* @property Carbon $updated_at when this timezone setting was last updated
* @property-read User $user user this token belongs to
* @method static Builder|Token whereUserId($value)
* @method static Builder|Token whereTimezone($value)
* @method static Builder|Token whereCreatedAt($value)
* @method static Builder|Token whereUpdatedAt($value)
* @mixin Eloquent
*/
class Timezone extends Model
{
public $table = 'users_timezones';
protected $primaryKey = 'user_id';
protected $fillable = ['remember_token', 'user_id'];
/**
* Get the user this timezone token belongs to.
*
* @return BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
}
@@ -50,6 +50,26 @@
}
/**
* Get this user's timezone.
*
* @return HasOne
*/
public function timezone()
{
return $this->hasOne(Timezone::class);
}
/**
* Get the user's timezone or the app's timezone if that is not set.
*
* @return string
*/
public function getTimezone()
{
return $this->timezone ? $this->timezone->timezone : config('app.timezone');
}
/**
* Get this user's custom fields.
*
* @return HasOne
@@ -1,0 +1,33 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTimezonesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users_timezones', function (Blueprint $table) {
$table->integer('user_id')->unsigned();
$table->string('timezone');
$table->timestamps();
$table->primary('user_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users_timezones');
}
}
@@ -75,3 +75,9 @@
position: fixed
bottom: 2rem
right: 2rem
.rainbow
color: #9c9c9c
background: linear-gradient(to right, #ea2fc7 0%, #7a2cc5 20%, #61b8c9 40%, #69c343 60%, #f2c61d 80%, #e9980f 100%)
-webkit-background-clip: text
-webkit-text-fill-color: transparent
@@ -37,10 +37,30 @@
'hour' => 'required|integer|min:0|max:23'
]);
$carbon = Carbon::now(auth()->user()->getTimezone())->setISODate(
Carbon::now()->year,
Carbon::now()->weekOfYear,
$request->get('day') + 1
)->setTime($request->get('hour'), 0);
if (Carbon::now()->weekOfYear !== $carbon->weekOfYear) {
if ($request->ajax()) {
return [
'error' => true,
'msg' => _('This slot will be unbooked when the timetable is cleared on Monday at 00:00 GMT.')
];
} else {
return redirect()
->back()
->with('msg', ['type' => 'danger', 'msg' => _('This slot will be unbooked when the timetable is cleared on Monday at 00:00 GMT.')])
->with('tab', $request->get('day'));
}
}
$slot = Timetable::where('week', Carbon::now()->weekOfYear)
->where('year', Carbon::now()->year)
->where('day', $request->get('day'))
->where('hour', $request->get('hour'))
->where('day', $carbon->dayOfWeek)
->where('hour', $carbon->hour)
->take(1)
->count();
@@ -62,8 +82,8 @@
$slot = new Timetable;
$slot->year = Carbon::now()->year;
$slot->week = Carbon::now()->weekOfYear;
$slot->day = $request->get('day');
$slot->hour = $request->get('hour');
$slot->day = $carbon->dayOfWeek;
$slot->hour = $carbon->hour;
$slot->dj = auth()->user()->userid;
$slot->save();
@@ -155,7 +175,17 @@
}
foreach ($week as $slot) {
$timetable[$slot->day][$slot->hour] = [
$carbon = Carbon::now()->setISODate(
Carbon::now()->year,
Carbon::now()->weekOfYear,
$slot->day + 1
)->setTime($slot->hour, 0)->tz(auth()->check() ? auth()->user()->getTimezone() : 'Europe/London');
if (Carbon::now()->weekOfYear !== $carbon->weekOfYear) {
continue;
}
$timetable[$carbon->dayOfWeek - 1][$carbon->hour] = [
'id' => $slot->user->userid,
'name' => $raw ? $slot->user->getDisplayName()->toHtml() : $slot->user->getDisplayName()
];
@@ -239,7 +239,17 @@
foreach ($week as $slot) {
$type = $slot->type->name;
$timetable[$slot->day][$slot->hour] = [
$carbon = Carbon::now()->setISODate(
Carbon::now()->year,
Carbon::now()->weekOfYear,
$slot->day + 1
)->setTime($slot->hour, 0)->tz(auth()->check() ? auth()->user()->getTimezone() : 'Europe/London');
if (Carbon::now()->weekOfYear !== $carbon->weekOfYear) {
continue;
}
$timetable[$carbon->dayOfWeek][$carbon->hour] = [
'id' => $slot->user()->first()->userid,
'name' => $raw ? $slot->user()->first()->getDisplayName()->toHtml() :
$slot->user()->first()->getDisplayName(),
@@ -20,7 +20,7 @@
public function index()
{
return view('management.event-types', [
'types' => EventType::orderBy('id', 'desc')->paginate(15)
'types' => EventType::orderBy('name', 'desc')->paginate(15)
]);
}