Scaffolded from the Ladill mini/events extraction pattern: multi-file transfers, retention controls, public landing pages, analytics, and Gitea deploy workflow. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Transfer;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Transfer;
|
|
use App\Models\TransferDownloadEvent;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
|
|
class AnalyticsController extends Controller
|
|
{
|
|
public function index(Request $request): View
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$transferIds = Transfer::query()
|
|
->where('user_id', $account->id)
|
|
->pluck('id');
|
|
|
|
$downloads30d = TransferDownloadEvent::query()
|
|
->whereIn('transfer_id', $transferIds)
|
|
->where('downloaded_at', '>=', now()->subDays(30))
|
|
->count();
|
|
|
|
$topTransfers = Transfer::query()
|
|
->where('user_id', $account->id)
|
|
->where('status', Transfer::STATUS_ACTIVE)
|
|
->orderByDesc('downloads_total')
|
|
->limit(10)
|
|
->get();
|
|
|
|
$recentDownloads = TransferDownloadEvent::query()
|
|
->whereIn('transfer_id', $transferIds)
|
|
->with(['transfer', 'file'])
|
|
->latest('downloaded_at')
|
|
->limit(20)
|
|
->get();
|
|
|
|
return view('transfer.analytics.index', [
|
|
'downloads30d' => $downloads30d,
|
|
'topTransfers' => $topTransfers,
|
|
'recentDownloads' => $recentDownloads,
|
|
]);
|
|
}
|
|
}
|