From 3825228344aaaf2b526db6a8222040992c4bdb2f Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 8 Nov 2020 23:07:51 +0900 Subject: [PATCH] =?UTF-8?q?discard=20elapsed=20time=E3=83=95=E3=83=A9?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E7=AB=8B=E3=81=A3=E3=81=9F=E3=83=81=E3=82=A7?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=A4=E3=83=B3=E3=81=AE=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Ejaculation.php | 29 +++++++++++++++++++ .../Controllers/EjaculationController.php | 16 +--------- app/Http/Controllers/UserController.php | 2 ++ resources/views/ejaculation/show.blade.php | 2 +- resources/views/user/profile.blade.php | 2 +- 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/app/Ejaculation.php b/app/Ejaculation.php index adc13a7..1ada581 100644 --- a/app/Ejaculation.php +++ b/app/Ejaculation.php @@ -105,4 +105,33 @@ class Ejaculation extends Model 'is_too_sensitive' => $this->is_too_sensitive, ]); } + + public function ejaculatedSpan(): string + { + if (array_key_exists('ejaculated_span', $this->attributes)) { + if ($this->ejaculated_span === null) { + return '精通'; + } + if ($this->discard_elapsed_time) { + return '0日 0時間 0分'; // TODO: 気の効いたフレーズにする + } + + return $this->ejaculated_span; + } else { + $previous = Ejaculation::select('ejaculated_date') + ->where('user_id', $this->user_id) + ->where('ejaculated_date', '<', $this->ejaculated_date) + ->orderByDesc('ejaculated_date') + ->first(); + + if ($previous === null) { + return '精通'; + } + if ($this->discard_elapsed_time) { + return '0日 0時間 0分'; + } + + return $this->ejaculated_date->diff($previous->ejaculated_date)->format('%a日 %h時間 %i分'); + } + } } diff --git a/app/Http/Controllers/EjaculationController.php b/app/Http/Controllers/EjaculationController.php index d1cf236..b0feb2d 100644 --- a/app/Http/Controllers/EjaculationController.php +++ b/app/Http/Controllers/EjaculationController.php @@ -121,21 +121,7 @@ class EjaculationController extends Controller ->firstOrFail(); $user = User::findOrFail($ejaculation->user_id); - // 1つ前のチェックインからの経過時間を求める - $previousEjaculation = Ejaculation::select('ejaculated_date') - ->where('user_id', $ejaculation->user_id) - ->where('ejaculated_date', '<', $ejaculation->ejaculated_date) - ->orderByDesc('ejaculated_date') - ->first(); - if (!empty($previousEjaculation)) { - $ejaculatedSpan = $ejaculation->ejaculated_date - ->diff($previousEjaculation->ejaculated_date) - ->format('%a日 %h時間 %i分'); - } else { - $ejaculatedSpan = null; - } - - return view('ejaculation.show')->with(compact('user', 'ejaculation', 'ejaculatedSpan')); + return view('ejaculation.show')->with(compact('user', 'ejaculation')); } public function edit(Request $request, $id) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 40b9894..81b68ea 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -35,6 +35,7 @@ is_private, is_too_sensitive, link, source, +discard_elapsed_time, to_char(before_dates.before_date, 'YYYY/MM/DD HH24:MI') AS before_date, to_char(ejaculated_date - before_dates.before_date, 'FMDDD日 FMHH24時間 FMMI分') AS ejaculated_span SQL @@ -169,6 +170,7 @@ is_private, is_too_sensitive, link, source, +discard_elapsed_time, to_char(before_dates.before_date, 'YYYY/MM/DD HH24:MI') AS before_date, to_char(ejaculated_date - before_dates.before_date, 'FMDDD日 FMHH24時間 FMMI分') AS ejaculated_span SQL diff --git a/resources/views/ejaculation/show.blade.php b/resources/views/ejaculation/show.blade.php index 9506eb1..8344480 100644 --- a/resources/views/ejaculation/show.blade.php +++ b/resources/views/ejaculation/show.blade.php @@ -31,7 +31,7 @@
-
{{ $ejaculatedSpan ?? '精通' }} {{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ~ ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
+
{{ $ejaculation->ejaculatedSpan() }} {{ !empty($ejaculation->before_date) && !$ejaculation->discard_elapsed_time ? $ejaculation->before_date . ' ~ ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
@if ($ejaculation->is_private || $ejaculation->source !== 'web' || $ejaculation->tags->isNotEmpty()) diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index 64c2476..48ef78f 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -58,7 +58,7 @@
  • -
    {{ $ejaculation->ejaculated_span ?? '精通' }} {{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ~ ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
    +
    {{ $ejaculation->ejaculatedSpan() }} {{ !empty($ejaculation->before_date) && !$ejaculation->discard_elapsed_time ? $ejaculation->before_date . ' ~ ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}
    @if ($ejaculation->is_private || $ejaculation->source !== 'web' || $ejaculation->tags->isNotEmpty())