2018-04-29 16:25:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-08-28 03:07:36 +00:00
|
|
|
use App\Media;
|
2018-09-03 01:25:08 +00:00
|
|
|
use App\Profile;
|
2018-09-01 02:26:56 +00:00
|
|
|
use App\Report;
|
2018-08-28 03:07:36 +00:00
|
|
|
use App\Status;
|
|
|
|
use App\User;
|
2018-09-03 01:25:08 +00:00
|
|
|
use Carbon\Carbon;
|
2018-04-29 16:25:57 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-09-01 02:26:56 +00:00
|
|
|
use App\Http\Controllers\Admin\{
|
|
|
|
AdminReportController
|
|
|
|
};
|
2018-04-29 16:25:57 +00:00
|
|
|
|
|
|
|
class AdminController extends Controller
|
|
|
|
{
|
2018-09-01 02:26:56 +00:00
|
|
|
use AdminReportController;
|
|
|
|
|
2018-05-26 22:45:05 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2018-09-16 05:15:45 +00:00
|
|
|
$this->middleware('admin');
|
|
|
|
$this->middleware('twofactor');
|
2018-05-26 22:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function home()
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
return view('admin.home');
|
2018-05-26 22:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function users(Request $request)
|
|
|
|
{
|
2018-09-11 03:06:36 +00:00
|
|
|
$stats = [];
|
2018-08-28 03:07:36 +00:00
|
|
|
$users = User::orderBy('id', 'desc')->paginate(10);
|
2018-09-03 01:25:08 +00:00
|
|
|
return view('admin.users.home', compact('users', 'stats'));
|
|
|
|
}
|
|
|
|
|
2018-05-26 22:45:05 +00:00
|
|
|
|
2018-09-03 01:25:08 +00:00
|
|
|
public function editUser(Request $request, $id)
|
|
|
|
{
|
|
|
|
$user = User::find($id);
|
|
|
|
$profile = $user->profile;
|
|
|
|
return view('admin.users.edit', compact('user', 'profile'));
|
2018-08-28 03:07:36 +00:00
|
|
|
}
|
2018-05-26 22:45:05 +00:00
|
|
|
|
|
|
|
public function statuses(Request $request)
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
$statuses = Status::orderBy('id', 'desc')->paginate(10);
|
|
|
|
|
|
|
|
return view('admin.statuses.home', compact('statuses'));
|
2018-05-26 22:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function showStatus(Request $request, $id)
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
$status = Status::findOrFail($id);
|
|
|
|
|
|
|
|
return view('admin.statuses.show', compact('status'));
|
2018-05-26 22:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function media(Request $request)
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
$media = Status::whereHas('media')->orderby('id', 'desc')->paginate(12);
|
|
|
|
|
|
|
|
return view('admin.media.home', compact('media'));
|
2018-05-26 22:45:05 +00:00
|
|
|
}
|
2018-09-01 02:26:56 +00:00
|
|
|
|
|
|
|
public function reports(Request $request)
|
|
|
|
{
|
|
|
|
$reports = Report::orderBy('created_at','desc')->paginate(12);
|
|
|
|
return view('admin.reports.home', compact('reports'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function showReport(Request $request, $id)
|
|
|
|
{
|
|
|
|
$report = Report::findOrFail($id);
|
|
|
|
return view('admin.reports.show', compact('report'));
|
|
|
|
}
|
2018-09-03 01:25:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
protected function collectUserStats($request)
|
2018-09-11 03:06:36 +00:00
|
|
|
{
|
2018-09-03 01:25:08 +00:00
|
|
|
$total_duration = $request->query('total_duration') ?? '30';
|
|
|
|
$new_duration = $request->query('new_duration') ?? '7';
|
|
|
|
$stats = [];
|
|
|
|
$stats['total'] = [
|
|
|
|
'count' => User::where('created_at', '>', Carbon::now()->subDays($total_duration))->count(),
|
2018-09-03 01:57:27 +00:00
|
|
|
'points' => 0//User::selectRaw('day(created_at) day, count(*) as count')->where('created_at','>', Carbon::now()->subDays($total_duration))->groupBy('day')->pluck('count')
|
2018-09-03 01:25:08 +00:00
|
|
|
];
|
|
|
|
$stats['new'] = [
|
|
|
|
'count' => User::where('created_at', '>', Carbon::now()->subDays($new_duration))->count(),
|
2018-09-03 01:57:27 +00:00
|
|
|
'points' => 0//User::selectRaw('day(created_at) day, count(*) as count')->where('created_at','>', Carbon::now()->subDays($new_duration))->groupBy('day')->pluck('count')
|
2018-09-03 01:25:08 +00:00
|
|
|
];
|
|
|
|
$stats['active'] = [
|
|
|
|
'count' => Status::groupBy('profile_id')->count()
|
|
|
|
];
|
|
|
|
$stats['profile'] = [
|
|
|
|
'local' => Profile::whereNull('remote_url')->count(),
|
|
|
|
'remote' => Profile::whereNotNull('remote_url')->count()
|
|
|
|
];
|
|
|
|
$stats['avg'] = [
|
2018-09-11 03:06:36 +00:00
|
|
|
'age' => 0,
|
2018-09-03 01:25:08 +00:00
|
|
|
'posts' => floor(Status::avg('profile_id'))
|
|
|
|
];
|
|
|
|
return $stats;
|
|
|
|
|
|
|
|
}
|
2018-04-29 16:25:57 +00:00
|
|
|
}
|