diff --git a/db/migrations/2018_10_01_000000_create_users_tables.php b/db/migrations/2018_10_01_000000_create_users_tables.php index 896ec7a4..b9429a2d 100644 --- a/db/migrations/2018_10_01_000000_create_users_tables.php +++ b/db/migrations/2018_10_01_000000_create_users_tables.php @@ -42,7 +42,6 @@ class CreateUsersTables extends Migration $table->string('shirt_size', 4)->nullable(); $table->date('planned_arrival_date')->nullable(); - $table->dateTime('arrival_date')->nullable(); $table->date('planned_departure_date')->nullable(); }); @@ -67,6 +66,7 @@ class CreateUsersTables extends Migration $this->referencesUser($table); $table->boolean('arrived')->default(false); + $table->dateTime('arrival_date')->nullable(); $table->boolean('active')->default(false); $table->boolean('force_active')->default(false); $table->boolean('got_shirt')->default(false); @@ -114,7 +114,6 @@ class CreateUsersTables extends Migration 'last_name' => $data->Name ?: null, 'shirt_size' => $data->Size ?: null, 'planned_arrival_date' => $data->planned_arrival_date ? Carbon::createFromTimestamp($data->planned_arrival_date) : null, - 'arrival_date' => $data->arrival_date ? Carbon::createFromTimestamp($data->arrival_date) : null, 'planned_departure_date' => $data->planned_departure_date ? Carbon::createFromTimestamp($data->planned_departure_date) : null, ]); $personalData->user() @@ -133,6 +132,7 @@ class CreateUsersTables extends Migration $state = new State([ 'arrived' => $data->Gekommen, + 'arrival_date' => $data->arrival_date ? Carbon::createFromTimestamp($data->arrival_date) : null, 'active' => $data->Aktiv, 'force_active' => $data->force_active, 'got_shirt' => $data->Tshirt, @@ -242,7 +242,7 @@ class CreateUsersTables extends Migration 'CreateDate' => $user->created_at ? $user->created_at->toDateTimeString() : null, 'api_key' => $user->api_key, 'got_voucher' => $state->got_voucher, - 'arrival_date' => $personal->arrival_date ? $personal->arrival_date->getTimestamp() : null, + 'arrival_date' => $state->arrival_date ? $state->arrival_date->getTimestamp() : null, 'planned_arrival_date' => $personal->planned_arrival_date ? $personal->planned_arrival_date->getTimestamp() : null, 'planned_departure_date' => $personal->planned_departure_date ? $personal->planned_departure_date->getTimestamp() : null, 'email_by_human_allowed' => $settings->email_human, diff --git a/includes/pages/admin_arrive.php b/includes/pages/admin_arrive.php index f06c2c55..40b8bf44 100644 --- a/includes/pages/admin_arrive.php +++ b/includes/pages/admin_arrive.php @@ -29,9 +29,8 @@ function admin_arrive() $user_source = User::find($user_id); if ($user_source) { $user_source->state->arrived = false; + $user_source->state->arrival_date = null; $user_source->state->save(); - $user_source->personalData->arrival_date = null; - $user_source->personalData->save(); engelsystem_log('User set to not arrived: ' . User_Nick_render($user_source)); success(__('Reset done. Angel has not arrived.')); @@ -44,8 +43,7 @@ function admin_arrive() $user_source = User::find($user_id); if ($user_source) { $user_source->state->arrived = true; - $user_source->state->save(); - $user_source->personalData->arrival_date = new Carbon\Carbon(); + $user_source->state->arrival_date = new Carbon\Carbon(); $user_source->personalData->save(); engelsystem_log('User set has arrived: ' . User_Nick_render($user_source)); @@ -89,7 +87,7 @@ function admin_arrive() $usr['rendered_planned_departure_date'] = '-'; } $usr['rendered_planned_arrival_date'] = $usr->personalData->planned_arrival_date->format('Y-m-d'); - $usr['rendered_arrival_date'] = $usr->personalData->arrival_date ? $usr->personalData->arrival_date->format('Y-m-d') : '-'; + $usr['rendered_arrival_date'] = $usr->state->arrival_date ? $usr->state->arrival_date->format('Y-m-d') : '-'; $usr['arrived'] = $usr->state->arrived ? __('yes') : ''; $usr['actions'] = $usr->state->arrived == 1 ? '' . __('arrived') . ''; - if ($usr->personalData->arrival_date) { - $day = $usr->personalData->arrival_date->format('Y-m-d'); + if ($usr->state->arrival_date) { + $day = $usr->state->arrival_date->format('Y-m-d'); if (!isset($arrival_count_at_day[$day])) { $arrival_count_at_day[$day] = 0; } diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php index fbcd8baf..bc97099e 100644 --- a/includes/pages/user_settings.php +++ b/includes/pages/user_settings.php @@ -57,7 +57,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes) if ($request->has('planned_departure_date')) { $tmp = parse_date('Y-m-d H:i', $request->input('planned_departure_date') . ' 00:00'); - $result = User_validate_planned_departure_date($user_source->personalData->arrival_date->getTimestamp(), $tmp); + $result = User_validate_planned_departure_date($user_source->state->arrival_date->getTimestamp(), $tmp); $user_source->personalData->planned_departure_date = Carbon::createFromTimestamp($result->getValue()); if (!$result->isValid()) { $valid = false; diff --git a/includes/view/User_view.php b/includes/view/User_view.php index bcf9aff7..cfafaeb1 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -25,6 +25,7 @@ function User_settings_view( $tshirt_sizes ) { $personalData = $user_source->personalData; + $state = $user_source->state; return page_with_title(settings_title(), [ msg(), div('row', [ @@ -38,7 +39,7 @@ function User_settings_view( form_date( 'planned_arrival_date', __('Planned date of arrival') . ' ' . entry_required(), - $personalData->arrival_date ? $personalData->arrival_date->getTimestamp() : '', + $state->arrival_date ? $state->arrival_date->getTimestamp() : '', $buildup_start_date, $teardown_end_date ), @@ -726,7 +727,7 @@ function User_view_state_admin($freeloader, $user_source) $state[] = '' . glyph('home') . sprintf( __('Arrived at %s'), - $user_source->personalData->arrival_date ? $user_source->personalData->arrival_date->format('Y-m-d') : '' + $user_source->state->arrival_date ? $user_source->state->arrival_date->format('Y-m-d') : '' ) . ''; diff --git a/src/Models/User/PersonalData.php b/src/Models/User/PersonalData.php index bdd0bafb..5871bcfb 100644 --- a/src/Models/User/PersonalData.php +++ b/src/Models/User/PersonalData.php @@ -6,14 +6,12 @@ namespace Engelsystem\Models\User; * @property string $first_name * @property string $last_name * @property string $shirt_size - * @property \Carbon\Carbon $arrival_date * @property \Carbon\Carbon $planned_arrival_date * @property \Carbon\Carbon $planned_departure_date * * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PersonalData whereFirstName($value) * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PersonalData whereLastName($value) * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PersonalData whereShirtSize($value) - * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PersonalData whereArrivalDate($value) * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PersonalData wherePlannedArrivalDate($value) * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\PersonalData wherePlannedDepartureDate($value) */ @@ -24,7 +22,6 @@ class PersonalData extends HasUserModel /** @var array The attributes that should be mutated to dates */ protected $dates = [ - 'arrival_date', 'planned_arrival_date', 'planned_departure_date', ]; diff --git a/src/Models/User/State.php b/src/Models/User/State.php index 5651736d..93bb8590 100644 --- a/src/Models/User/State.php +++ b/src/Models/User/State.php @@ -3,13 +3,15 @@ namespace Engelsystem\Models\User; /** - * @property bool $arrived - * @property bool $active - * @property bool $force_active - * @property bool $got_shirt - * @property int $got_voucher + * @property bool $arrived + * @property \Carbon\Carbon $arrival_date + * @property bool $active + * @property bool $force_active + * @property bool $got_shirt + * @property int $got_voucher * * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereArrived($value) + * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereArrivalDate($value) * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereActive($value) * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereForceActive($value) * @method static \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\State[] whereGotShirt($value) @@ -24,6 +26,7 @@ class State extends HasUserModel protected $fillable = [ 'user_id', 'arrived', + 'arrival_date', 'active', 'force_active', 'got_shirt',