TeacherWeeklyStatsReport.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Filament\Pages;
  3. use App\Support\TeacherWeeklyStatsReportPaths;
  4. use Filament\Actions\Action;
  5. use Filament\Notifications\Notification;
  6. use Filament\Pages\Page;
  7. use Illuminate\Support\Facades\Artisan;
  8. use Livewire\Attributes\Computed;
  9. use UnitEnum;
  10. class TeacherWeeklyStatsReport extends Page
  11. {
  12. protected static ?string $title = '老师周报统计';
  13. protected static ?string $navigationLabel = '老师周报统计';
  14. protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-document-chart-bar';
  15. protected static string|UnitEnum|null $navigationGroup = '其他';
  16. protected static ?int $navigationSort = 95;
  17. protected string $view = 'filament.pages.teacher-weekly-stats-report';
  18. #[Computed(cache: false)]
  19. public function hasLatestPdf(): bool
  20. {
  21. return TeacherWeeklyStatsReportPaths::resolveLatestPdfPath() !== null;
  22. }
  23. #[Computed(cache: false)]
  24. public function latestPdfBasename(): ?string
  25. {
  26. $p = TeacherWeeklyStatsReportPaths::resolveLatestPdfPath();
  27. return $p !== null ? basename($p) : null;
  28. }
  29. #[Computed(cache: false)]
  30. public function latestPdfMtime(): ?string
  31. {
  32. $p = TeacherWeeklyStatsReportPaths::resolveLatestPdfPath();
  33. return $p !== null ? date('Y-m-d H:i:s', filemtime($p)) : null;
  34. }
  35. #[Computed(cache: false)]
  36. public function pdfOpenUrl(): string
  37. {
  38. return route('filament.admin.reports.teacher-weekly-stats.open');
  39. }
  40. protected function getHeaderActions(): array
  41. {
  42. return [
  43. Action::make('regenerate')
  44. ->label('生成 / 刷新周报 PDF')
  45. ->icon('heroicon-o-arrow-path')
  46. ->action(function (): void {
  47. $code = Artisan::call('report:teacher-weekly-pdf');
  48. if ($code !== 0) {
  49. Notification::make()
  50. ->title('生成失败')
  51. ->danger()
  52. ->body('请查看日志或终端输出')
  53. ->send();
  54. return;
  55. }
  56. $this->dispatch('$refresh');
  57. Notification::make()
  58. ->title('周报已生成')
  59. ->success()
  60. ->send();
  61. }),
  62. ];
  63. }
  64. }