This commit is contained in:
Kekskurse 2021-01-21 15:36:33 +01:00
parent da043fd71b
commit e1745c40be
4 changed files with 95 additions and 0 deletions

View file

@ -0,0 +1,63 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\DB;
class ReportController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function showReportList()
{
$oldesDate = DB::select("SELECT `year`, `month` FROM `go-mysql-admin`.storage WHERE tenant = " . (int)session("current_tenant_id") . " ORDER BY `date` ASC LIMIT 1;")[0];
$avalibleReports = [];
for ($i = $oldesDate->year; $i <= date("Y"); $i++) {
for ($m = 1; $m <= 12; $m++) {
if($i == $oldesDate->year && $m < $oldesDate->month) {
continue;
}
if($i == date("Y") && $m > date("m")) {
continue;
}
$avalibleReports[] = ["year" => $i, "month" => $m];
}
}
return view("dashboard.reports", ["avalibleReports" => $avalibleReports]);
}
public function spaceReport($year, $month) {
$reportData = DB::select("SELECT * FROM storage WHERE tenant = ".(int)session("current_tenant_id")." AND `year` = ".(int)$year." AND `month` = ".(int)$month.";");
$report = "year;month;day;hour;size\n";
foreach ($reportData as $reportLine) {
$report .= $reportLine->year.";".$reportLine->month.";".$reportLine->day.";".$reportLine->hour.";".$reportLine->size."\n";
}
$res = new Response();
$res->header("Content-type", "text/csv");
$res->header("Content-Disposition", "attachment; filename=".$year."_".$month."_space.csv");
$res->setContent($report);
return $res;
}
public function traficReport($year, $month) {
$reportData = DB::select("SELECT * FROM traffic WHERE tenant = ".(int)session("current_tenant_id")." AND `year` = ".(int)$year." AND `month` = ".(int)$month.";");
$report = "year;month;day;hour;gallery;traffic\n";
foreach ($reportData as $reportLine) {
$report .= $reportLine->year.";".$reportLine->month.";".$reportLine->day.";".$reportLine->hour.";".$reportLine->gallery.";".$reportLine->traffic."\n";
}
$res = new Response();
$res->header("Content-type", "text/csv");
$res->header("Content-Disposition", "attachment; filename=".$year."_".$month."_trafficg.csv");
$res->setContent($report);
return $res;
}
}

View file

@ -0,0 +1,28 @@
@extends('layout/template')
@section('content')
<div class="row" style="margin-top: 20px;">
<div class="col-md-12">
<h1>Reports</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<ul class="list-group">
@foreach ($avalibleReports as $report)
<li class="list-group-item">
<a href="/s/reports/{{ $report["year"] }}/{{ $report["month"] }}/traffic" class="btn btn-sm btn-outline-primary" style="float: right;">Traffic</a>
<a href="/s/reports/{{ $report["year"] }}/{{ $report["month"] }}/space" class="btn btn-sm btn-outline-primary" style="float: right;margin-right: 5px;">Space</a>
Year: {{ $report["year"] }}<br>
Month: {{ $report["month"] }}
</li>
@endforeach
</ul>
</div>
</div>
@endsection

View file

@ -25,6 +25,7 @@
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Settings</a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="/s/watermark">Watermark</a>
<a class="dropdown-item" href="/s/reports">Reports</a>
</div>
</li>
</ul>

View file

@ -49,6 +49,9 @@ Route::middleware([\App\Http\Middleware\TenanMiddleware::class])->group(function
Route::post("/s/watermark", [\App\Http\Controllers\TenantController::class, 'watermarkSave']);
Route::get("/s/watermark/image", [\App\Http\Controllers\PublicController::class, "returnWatermakeFile"]);
Route::get("/s/watermark/delete", [\App\Http\Controllers\TenantController::class, "deleteWatermark"]);
Route::get("s/reports", [\App\Http\Controllers\ReportController::class, "showReportList"]);
Route::get("s/reports/{year}/{month}/space", [\App\Http\Controllers\ReportController::class, "spaceReport"]);
Route::get("s/reports/{year}/{month}/traffic", [\App\Http\Controllers\ReportController::class, "traficReport"]);
});
Route::get("/{name}", [\App\Http\Controllers\PublicController::class, 'listGalleriesView'])->middleware([\App\Http\Middleware\TenanMiddleware::class]);