|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace agoalofalife\Reports\Http\Controllers; |
|
5
|
|
|
|
|
6
|
|
|
use agoalofalife\Reports\Http\Resources\ReportsCollection; |
|
7
|
|
|
use agoalofalife\Reports\Models\Report; |
|
8
|
|
|
use Illuminate\Http\JsonResponse; |
|
9
|
|
|
use Illuminate\Http\Request; |
|
10
|
|
|
use Illuminate\Routing\Controller; |
|
11
|
|
|
use Illuminate\Support\Facades\Storage; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class DashboardController |
|
15
|
|
|
* @package agoalofalife\Reports\Http\Controllers |
|
16
|
|
|
*/ |
|
17
|
|
|
class DashboardController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Get table columns |
|
21
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
22
|
|
|
*/ |
|
23
|
1 |
|
public function tableColumn() : JsonResponse |
|
24
|
|
|
{ |
|
25
|
1 |
|
return response()->json(trans("reports::dashboard")); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get list reports |
|
30
|
|
|
* @return JsonResponse |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getReports() : JsonResponse |
|
33
|
|
|
{ |
|
34
|
3 |
|
$reports = collect(config('reports.reports'))->map(function (string $classReport) { |
|
35
|
2 |
|
$report = new $classReport; |
|
36
|
2 |
|
$reportDatabase = Report::firstOrCreate( |
|
37
|
|
|
[ |
|
38
|
2 |
|
'class_name' => $report->getNameClass() |
|
39
|
|
|
], |
|
40
|
|
|
[ |
|
41
|
2 |
|
'class_name' => $report->getNameClass() |
|
42
|
|
|
] |
|
43
|
|
|
); |
|
44
|
2 |
|
$reportDatabase->is_completed ? $report->changeCompleted(true) : false; |
|
45
|
2 |
|
$report->changeStatus($reportDatabase->status ?? Report::STATUS_NEW); |
|
46
|
2 |
|
return $report; |
|
47
|
3 |
|
}); |
|
48
|
3 |
|
return (new ReportsCollection($reports))->response(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Get count not read reports |
|
53
|
|
|
* @return JsonResponse |
|
54
|
|
|
*/ |
|
55
|
2 |
|
public function getNotificationCount() : JsonResponse |
|
56
|
|
|
{ |
|
57
|
2 |
|
return response()->json(['data' => [ |
|
58
|
2 |
|
'count' => Report::where('is_completed', true)->get()->count() |
|
59
|
|
|
]]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Update report |
|
64
|
|
|
* @param Request $request |
|
65
|
|
|
* @return JsonResponse |
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function updateReport(Request $request) : JsonResponse |
|
68
|
|
|
{ |
|
69
|
1 |
|
$report = Report::where('class_name', $request->class)->get()->first(); |
|
70
|
1 |
|
$report->update([ |
|
71
|
1 |
|
'status' => Report::STATUS_PROCESS |
|
72
|
|
|
]); |
|
73
|
1 |
|
return response()->json(['data' => [ |
|
74
|
|
|
'status' => 'success' |
|
75
|
|
|
]]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string $className |
|
80
|
|
|
* @return mixed= |
|
|
|
|
|
|
81
|
|
|
*/ |
|
82
|
2 |
|
public function downloadFile(string $className) |
|
83
|
|
|
{ |
|
84
|
2 |
|
$className = str_replace('@', '\\', $className); |
|
85
|
2 |
|
if (class_exists($className)) { |
|
86
|
1 |
|
$report = app()->make($className); |
|
87
|
1 |
|
$report->getReportModel()->update([ |
|
88
|
1 |
|
'is_completed' => false |
|
89
|
|
|
]); |
|
90
|
1 |
|
return Storage::disk($report->disk)->download($report->getFileNormalize()); |
|
91
|
|
|
} |
|
92
|
1 |
|
return response('Class not exist', 500); |
|
93
|
|
|
} |
|
94
|
|
|
} |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.