2017-08-27 04:44:53 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Ejaculation;
|
2017-11-03 20:38:09 +09:00
|
|
|
use App\Information;
|
2017-08-27 04:44:53 +09:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class HomeController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the application dashboard.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2018-01-05 22:27:16 +09:00
|
|
|
$informations = Information::query()
|
|
|
|
->select('id', 'category', 'pinned', 'title', 'created_at')
|
|
|
|
->orderByDesc('pinned')
|
|
|
|
->orderByDesc('created_at')
|
2018-01-07 22:45:57 +09:00
|
|
|
->take(3)
|
|
|
|
->get();
|
2018-01-05 22:27:16 +09:00
|
|
|
$categories = Information::CATEGORIES;
|
2017-11-03 20:38:09 +09:00
|
|
|
|
2018-01-05 22:27:16 +09:00
|
|
|
if (Auth::check()) {
|
2019-02-09 02:34:53 +09:00
|
|
|
// チェックイン動向グラフ用のデータ取得
|
|
|
|
$groupByDay = Ejaculation::select(DB::raw(
|
|
|
|
<<<'SQL'
|
|
|
|
to_char(ejaculated_date, 'YYYY/MM/DD') AS "date",
|
|
|
|
count(*) AS "count"
|
|
|
|
SQL
|
|
|
|
))
|
|
|
|
->join('users', function ($join) {
|
|
|
|
$join->on('users.id', '=', 'ejaculations.user_id')
|
|
|
|
->where('users.accept_analytics', true);
|
|
|
|
})
|
|
|
|
->where('ejaculated_date', '>=', now()->subDays(14))
|
|
|
|
->groupBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')"))
|
|
|
|
->orderBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM/DD')"))
|
|
|
|
->get()
|
|
|
|
->mapWithKeys(function ($item) {
|
|
|
|
return [$item['date'] => $item['count']];
|
|
|
|
});
|
|
|
|
$globalEjaculationCounts = [];
|
|
|
|
$day = Carbon::now()->subDays(29);
|
|
|
|
for ($i = 0; $i < 30; $i++) {
|
|
|
|
$globalEjaculationCounts[$day->format('Y/m/d') . ' の総チェックイン数'] = $groupByDay[$day->format('Y/m/d')] ?? 0;
|
|
|
|
$day->addDay();
|
|
|
|
}
|
|
|
|
|
2018-01-07 22:19:33 +09:00
|
|
|
// お惣菜コーナー用のデータ取得
|
2018-01-07 22:42:30 +09:00
|
|
|
$publicLinkedEjaculations = Ejaculation::join('users', 'users.id', '=', 'ejaculations.user_id')
|
|
|
|
->where('users.is_protected', false)
|
|
|
|
->where('ejaculations.is_private', false)
|
|
|
|
->where('ejaculations.link', '<>', '')
|
|
|
|
->orderBy('ejaculations.ejaculated_date', 'desc')
|
|
|
|
->select('ejaculations.*')
|
2018-01-08 10:28:12 +09:00
|
|
|
->with('user', 'tags')
|
2019-01-12 00:14:51 +09:00
|
|
|
->take(10)
|
2018-01-07 22:19:33 +09:00
|
|
|
->get();
|
|
|
|
|
2019-02-09 02:34:53 +09:00
|
|
|
return view('home')->with(compact('informations', 'categories', 'globalEjaculationCounts', 'publicLinkedEjaculations'));
|
2017-08-27 04:44:53 +09:00
|
|
|
} else {
|
2018-01-05 22:27:16 +09:00
|
|
|
return view('guest')->with(compact('informations', 'categories'));
|
2017-08-27 04:44:53 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|