<?php
namespace App\Filament\Widgets;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Actions\ExportAction;
use Filament\Widgets\TableWidget as BaseWidget;
use Filament\Widgets\Concerns\InteractsWithPageFilters;
use App\Models\UserActivity;
use App\Models\Group;
use App\Models\Activity;
use Illuminate\Support\Facades\DB;
use App\Filament\Exports\GroupsReportExporter;
class GroupsReportTable extends BaseWidget
{
use InteractsWithPageFilters;
public function table(Table $table): Table
{
$group_id_filter = $this->filters['group_id_filter'] ?? null;
$activity_id_filter = $this->filters['activity_id_filter'] ?? null;
if($group_id_filter == null) {
$group_id_filter = Group::all()->pluck('id')->toArray();
}
if($activity_id_filter == null) {
$activity_id_filter = Activity::all()->pluck('id')->toArray();
}
return $table
->query(Group::query()
->select("groups.*",
DB::raw("get_group_points(groups.id, '".implode(",", $activity_id_filter)."') AS point")
)
->whereIn("id", $group_id_filter)
)
->columns([
TextColumn::make('desc'),
TextColumn::make('point'),
]);
}
}