discard elapsed timeフラグの立ったチェックインの表示対応

This commit is contained in:
shibafu 2020-11-08 23:07:51 +09:00
parent 855011c624
commit 3825228344
5 changed files with 34 additions and 17 deletions

View File

@ -105,4 +105,33 @@ class Ejaculation extends Model
'is_too_sensitive' => $this->is_too_sensitive, '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分');
}
}
} }

View File

@ -121,21 +121,7 @@ class EjaculationController extends Controller
->firstOrFail(); ->firstOrFail();
$user = User::findOrFail($ejaculation->user_id); $user = User::findOrFail($ejaculation->user_id);
// 1つ前のチェックインからの経過時間を求める return view('ejaculation.show')->with(compact('user', 'ejaculation'));
$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'));
} }
public function edit(Request $request, $id) public function edit(Request $request, $id)

View File

@ -35,6 +35,7 @@ is_private,
is_too_sensitive, is_too_sensitive,
link, link,
source, source,
discard_elapsed_time,
to_char(before_dates.before_date, 'YYYY/MM/DD HH24:MI') AS before_date, 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 to_char(ejaculated_date - before_dates.before_date, 'FMDDD日 FMHH24時間 FMMI分') AS ejaculated_span
SQL SQL
@ -169,6 +170,7 @@ is_private,
is_too_sensitive, is_too_sensitive,
link, link,
source, source,
discard_elapsed_time,
to_char(before_dates.before_date, 'YYYY/MM/DD HH24:MI') AS before_date, 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 to_char(ejaculated_date - before_dates.before_date, 'FMDDD日 FMHH24時間 FMMI分') AS ejaculated_span
SQL SQL

View File

@ -31,7 +31,7 @@
<div class="card-body"> <div class="card-body">
<!-- span --> <!-- span -->
<div> <div>
<h5>{{ $ejaculatedSpan ?? '精通' }} <small class="text-muted">{{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}</small></h5> <h5>{{ $ejaculation->ejaculatedSpan() }} <small class="text-muted">{{ !empty($ejaculation->before_date) && !$ejaculation->discard_elapsed_time ? $ejaculation->before_date . ' ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}</small></h5>
</div> </div>
<!-- tags --> <!-- tags -->
@if ($ejaculation->is_private || $ejaculation->source !== 'web' || $ejaculation->tags->isNotEmpty()) @if ($ejaculation->is_private || $ejaculation->source !== 'web' || $ejaculation->tags->isNotEmpty())

View File

@ -58,7 +58,7 @@
<li class="list-group-item border-bottom-only pt-3 pb-3 text-break"> <li class="list-group-item border-bottom-only pt-3 pb-3 text-break">
<!-- span --> <!-- span -->
<div> <div>
<h5>{{ $ejaculation->ejaculated_span ?? '精通' }} <a href="{{ route('checkin.show', ['id' => $ejaculation->id]) }}" class="text-muted"><small>{{ $ejaculation->before_date }}{{ !empty($ejaculation->before_date) ? ' ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}</small></a></h5> <h5>{{ $ejaculation->ejaculatedSpan() }} <a href="{{ route('checkin.show', ['id' => $ejaculation->id]) }}" class="text-muted"><small>{{ !empty($ejaculation->before_date) && !$ejaculation->discard_elapsed_time ? $ejaculation->before_date . ' ' : '' }}{{ $ejaculation->ejaculated_date->format('Y/m/d H:i') }}</small></a></h5>
</div> </div>
<!-- tags --> <!-- tags -->
@if ($ejaculation->is_private || $ejaculation->source !== 'web' || $ejaculation->tags->isNotEmpty()) @if ($ejaculation->is_private || $ejaculation->source !== 'web' || $ejaculation->tags->isNotEmpty())