From 6ed0938694d500254964a05fcb1f402c22a0c06a Mon Sep 17 00:00:00 2001 From: shibafu Date: Sun, 5 Nov 2017 01:26:52 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=97=E3=83=AD=E3=83=95=E3=82=A3=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E5=B7=A6=E3=82=AB=E3=83=A9=E3=83=A0=E3=81=AB?= =?UTF-8?q?=E3=81=82=E3=82=8B=E6=83=85=E5=A0=B1=E3=81=AB=E9=96=A2=E3=81=99?= =?UTF-8?q?=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Ejaculation.php | 4 ++ app/Http/Controllers/HomeController.php | 46 +------------- app/Http/Controllers/UserController.php | 49 ++++++--------- app/Http/ViewComposers/ProfileComposer.php | 61 +++++++++++++++++++ app/Providers/ViewComposerServiceProvider.php | 30 +++++++++ config/app.php | 1 + resources/views/components/profile.blade.php | 23 +++++++ resources/views/home.blade.php | 25 +------- resources/views/user/base.blade.php | 25 +------- resources/views/user/okazu.blade.php | 4 ++ resources/views/user/profile.blade.php | 12 ++-- resources/views/user/stats.blade.php | 4 ++ 12 files changed, 157 insertions(+), 127 deletions(-) create mode 100644 app/Http/ViewComposers/ProfileComposer.php create mode 100644 app/Providers/ViewComposerServiceProvider.php create mode 100644 resources/views/components/profile.blade.php create mode 100644 resources/views/user/okazu.blade.php create mode 100644 resources/views/user/stats.blade.php diff --git a/app/Ejaculation.php b/app/Ejaculation.php index f6f8628..8b975ef 100644 --- a/app/Ejaculation.php +++ b/app/Ejaculation.php @@ -13,4 +13,8 @@ class Ejaculation extends Model 'note', 'geo_latitude', 'geo_longitude', 'is_private' ]; + + protected $dates = [ + 'ejaculated_date' + ]; } diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 9659481..e8b1e5e 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -28,50 +28,6 @@ class HomeController extends Controller public function index() { if (Auth::check()) { - $ejaculations = Ejaculation::select(DB::raw(<<<'SQL' -to_char(ejaculated_date, 'YYYY/MM/DD HH24:MI') AS ejaculated_date, -note, -is_private, -to_char(lead(ejaculated_date, 1, NULL) OVER (ORDER BY ejaculated_date DESC), 'YYYY/MM/DD HH24:MI') AS before_date, -to_char(ejaculated_date - (lead(ejaculated_date, 1, NULL) OVER (ORDER BY ejaculated_date DESC)), 'FMDDD日 FMHH24時間 FMMI分') AS ejaculated_span -SQL -)) - ->where(['user_id' => Auth::id()]) - ->orderBy('ejaculated_date', 'desc') - ->limit(9) - ->get(); - - // 現在のオナ禁セッションの経過時間 - if (count($ejaculations) > 0) { - $currentSession = Carbon::parse($ejaculations[0]['ejaculated_date']) - ->diff(Carbon::now()) - ->format('%a日 %h時間 %i分'); - } else { - $currentSession = null; - } - - // 概況欄のデータ取得 - $summary = DB::select(<<<'SQL' -SELECT - avg(span) AS average, - max(span) AS longest, - min(span) AS shortest, - sum(span) AS total_times, - count(*) AS total_checkins -FROM - ( - SELECT - extract(epoch from ejaculated_date - lead(ejaculated_date, 1, NULL) OVER (ORDER BY ejaculated_date DESC)) AS span - FROM - ejaculations - WHERE - user_id = :user_id - ORDER BY - ejaculated_date DESC - ) AS temp -SQL -, ['user_id' => Auth::id()]); - $informations = Information::query() ->select('id', 'category', 'pinned', 'title', 'created_at') ->orderBy('pinned') @@ -79,7 +35,7 @@ SQL ->paginate(3); $categories = Information::CATEGORIES; - return view('home')->with(compact('ejaculations', 'currentSession', 'summary', 'informations', 'categories')); + return view('home')->with(compact('informations', 'categories')); } else { return view('guest'); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index f398126..bb17762 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -23,7 +23,7 @@ class UserController extends Controller // チェックインの取得 $query = Ejaculation::select(DB::raw(<<<'SQL' id, -to_char(ejaculated_date, 'YYYY/MM/DD HH24:MI') AS ejaculated_date, +ejaculated_date, note, is_private, to_char(lead(ejaculated_date, 1, NULL) OVER (ORDER BY ejaculated_date DESC), 'YYYY/MM/DD HH24:MI') AS before_date, @@ -37,37 +37,26 @@ SQL $ejaculations = $query->orderBy('ejaculated_date', 'desc') ->paginate(20); - // 現在のオナ禁セッションの経過時間 - if (count($ejaculations) > 0) { - $currentSession = Carbon::parse($ejaculations[0]['ejaculated_date']) - ->diff(Carbon::now()) - ->format('%a日 %h時間 %i分'); - } else { - $currentSession = null; + return view('user.profile')->with(compact('user', 'ejaculations')); + } + + public function stats($name) + { + $user = User::where('name', $name)->first(); + if (empty($user)) { + abort(404); } - // 概況欄のデータ取得 - $summary = DB::select(<<<'SQL' -SELECT - avg(span) AS average, - max(span) AS longest, - min(span) AS shortest, - sum(span) AS total_times, - count(*) AS total_checkins -FROM - ( - SELECT - extract(epoch from ejaculated_date - lead(ejaculated_date, 1, NULL) OVER (ORDER BY ejaculated_date DESC)) AS span - FROM - ejaculations - WHERE - user_id = :user_id - ORDER BY - ejaculated_date DESC - ) AS temp -SQL - , ['user_id' => $user->id]); + return view('user.stats')->with(compact('user')); + } - return view('user.profile')->with(compact('user', 'ejaculations', 'currentSession', 'summary')); + public function okazu($name) + { + $user = User::where('name', $name)->first(); + if (empty($user)) { + abort(404); + } + + return view('user.okazu')->with(compact('user')); } } diff --git a/app/Http/ViewComposers/ProfileComposer.php b/app/Http/ViewComposers/ProfileComposer.php new file mode 100644 index 0000000..5a0f862 --- /dev/null +++ b/app/Http/ViewComposers/ProfileComposer.php @@ -0,0 +1,61 @@ +offsetExists('user')) { + throw new \LogicException('View data "user" was not exist.'); + } + $user = $view->offsetGet('user'); + + // 現在のオナ禁セッションの経過時間 + $latestEjaculation = Ejaculation::select('ejaculated_date') + ->where('user_id', $user->id) + ->orderByDesc('ejaculated_date') + ->first(); + if (!empty($latestEjaculation)) { + $currentSession = $latestEjaculation->ejaculated_date + ->diff(Carbon::now()) + ->format('%a日 %h時間 %i分'); + } else { + $currentSession = null; + } + + // 概況欄のデータ取得 + $summary = DB::select(<<<'SQL' +SELECT + avg(span) AS average, + max(span) AS longest, + min(span) AS shortest, + sum(span) AS total_times, + count(*) AS total_checkins +FROM + ( + SELECT + extract(epoch from ejaculated_date - lead(ejaculated_date, 1, NULL) OVER (ORDER BY ejaculated_date DESC)) AS span + FROM + ejaculations + WHERE + user_id = :user_id + ORDER BY + ejaculated_date DESC + ) AS temp +SQL + , ['user_id' => $user->id]); + + $view->with(compact('latestEjaculation', 'currentSession', 'summary')); + } +} \ No newline at end of file diff --git a/app/Providers/ViewComposerServiceProvider.php b/app/Providers/ViewComposerServiceProvider.php new file mode 100644 index 0000000..bb4f062 --- /dev/null +++ b/app/Providers/ViewComposerServiceProvider.php @@ -0,0 +1,30 @@ + +
+ +

{{ $user->display_name }}

+
@{{ $user->name }}
+ +
現在のセッション
+ @if (isset($currentSession)) +

{{ $currentSession }}経過

+

({{ $latestEjaculation->ejaculated_date->format('Y/m/d H:i') }} にリセット)

+ @else +

計測がまだ始まっていません

+

(一度チェックインすると始まります)

+ @endif + +
概況
+

平均記録: {{ Formatter::formatInterval($summary[0]->average) }}

+

最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}

+

最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}

+

合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}

+

通算回数: {{ $summary[0]->total_checkins }}回

+
+ \ No newline at end of file diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index d3ad6e6..4e9aae1 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -7,29 +7,8 @@
-
-
- -

{{ Auth::user()->display_name }}

-
@{{ Auth::user()->name }}
- -
現在のセッション
- @if (isset($currentSession)) -

{{ $currentSession }}経過

-

({{ $ejaculations[0]['ejaculated_date'] }} にリセット)

- @else -

計測がまだ始まっていません

-

(一度チェックインすると始まります)

- @endif - -
概況
-

平均記録: {{ Formatter::formatInterval($summary[0]->average) }}

-

最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}

-

最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}

-

合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}

-

通算回数: {{ $summary[0]->total_checkins }}回

-
-
+ @component('components.profile', ['user' => Auth::user()]) + @endcomponent
diff --git a/resources/views/user/base.blade.php b/resources/views/user/base.blade.php index 8eb53b2..732a569 100644 --- a/resources/views/user/base.blade.php +++ b/resources/views/user/base.blade.php @@ -4,29 +4,8 @@
-
-
- -

{{ $user->display_name }}

-
@{{ $user->name }}
- -
現在のセッション
- @if (isset($currentSession)) -

{{ $currentSession }}経過

-

({{ $ejaculations[0]['ejaculated_date'] }} にリセット)

- @else -

計測がまだ始まっていません

-

(一度チェックインすると始まります)

- @endif - -
概況
-

平均記録: {{ Formatter::formatInterval($summary[0]->average) }}

-

最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}

-

最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}

-

合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}

-

通算回数: {{ $summary[0]->total_checkins }}回

-
-
+ @component('components.profile', ['user' => $user]) + @endcomponent
--}} - @if (!empty($ejaculation['note'])) + @if (!empty($ejaculation->note))

- {!! Formatter::linkify(nl2br(e($ejaculation['note']))) !!} + {!! Formatter::linkify(nl2br(e($ejaculation->note))) !!}

@endif diff --git a/resources/views/user/stats.blade.php b/resources/views/user/stats.blade.php new file mode 100644 index 0000000..6bc8f66 --- /dev/null +++ b/resources/views/user/stats.blade.php @@ -0,0 +1,4 @@ +@extends('user.base') + +@section('tab-content') +@endsection \ No newline at end of file