diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 3c51369..618997c 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -62,7 +62,18 @@ SQL ->limit(10) ->get(); - return view('user.profile')->with(compact('user', 'ejaculations', 'tags')); + // シコ草 + $countByDayQuery = $this->countEjaculationByDay($user) + ->where('ejaculated_date', '>=', now()->startOfMonth()->subMonths(9)) + ->where('ejaculated_date', '<', now()->addMonth()->startOfMonth()) + ->get(); + $countByDay = []; + foreach ($countByDayQuery as $data) { + $date = Carbon::createFromFormat('Y/m/d', $data->date); + $countByDay[$date->timestamp] = $data->count; + } + + return view('user.profile')->with(compact('user', 'ejaculations', 'tags', 'countByDay')); } public function stats($name) @@ -223,16 +234,8 @@ SQL $dateCondition[] = ['ejaculated_date', '>=', $dateSince]; } - $groupByDay = Ejaculation::select(DB::raw( - <<<'SQL' -to_char(ejaculated_date, 'YYYY/MM/DD') AS "date", -count(*) AS "count" -SQL - )) - ->where('user_id', $user->id) + $groupByDay = $this->countEjaculationByDay($user) ->where($dateCondition) - ->groupBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')")) - ->orderBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')")) ->get(); $groupByHour = Ejaculation::select(DB::raw( @@ -287,4 +290,17 @@ SQL 'hourlySum' => array_values($hourlySum), ]; } + + private function countEjaculationByDay(User $user) + { + return Ejaculation::select(DB::raw( + <<<'SQL' +to_char(ejaculated_date, 'YYYY/MM/DD') AS "date", +count(*) AS "count" +SQL + )) + ->where('user_id', $user->id) + ->groupBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')")) + ->orderBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')")); + } } diff --git a/resources/assets/js/user/profile.js b/resources/assets/js/user/profile.js new file mode 100644 index 0000000..24cba77 --- /dev/null +++ b/resources/assets/js/user/profile.js @@ -0,0 +1,15 @@ +import CalHeatMap from 'cal-heatmap'; + +if (document.getElementById('cal-heatmap')) { + new CalHeatMap().init({ + itemSelector: '#cal-heatmap', + domain: 'month', + subDomain: 'day', + domainLabelFormat: '%Y/%m', + weekStartOnMonday: false, + start: new Date().setMonth(new Date().getMonth() - 9), + range: 10, + data: JSON.parse(document.getElementById('count-by-day').textContent), + legend: [1, 2, 3, 4] + }); +} diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index 5823026..978a39a 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -2,6 +2,12 @@ @section('title', $user->display_name . ' (@' . $user->name . ')') +@push('head') + @if (Route::currentRouteName() === 'user.profile') + + @endif +@endpush + @section('sidebar') {{-- TODO: タイムラインとオカズのテンプレを分けたら条件外す --}} @if (Route::currentRouteName() === 'user.profile') @@ -32,6 +38,11 @@ このユーザはチェックイン履歴を公開していません。

@else + @if ($ejaculations->count() !== 0 && $ejaculations->currentPage() === 1) +
Shikontributions
+
+
+ @endif