Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion app/app/Filament/Admin/Resources/CourseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Infolists\Components\GamesWithPlayers;
use App\Infolists\Components\PlayerTable;
use App\Models\Course;
use App\Models\Player;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists\Components\TextEntry;
Expand All @@ -21,6 +20,14 @@ class CourseResource extends Resource
{
protected static ?string $model = Course::class;

// --- Customize resource names here ---
// The name in the navigation sidebar
protected static ?string $navigationLabel = 'Kurse';
// The singular name displayed on pages and in breadcrumbs
protected static ?string $label = 'Kurs';
// The plural name displayed in the sidebar and table headers
protected static ?string $pluralModelLabel = 'Kurse';

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
use App\Filament\Imports\PlayerImporter;
use App\Models\Course;
use App\Models\Game;
use App\Models\Player;
use Domain\CoreGameLogic\DrivingPorts\ForCoreGameLogic;
use Domain\CoreGameLogic\Feature\Initialization\Command\StartPreGame;
use Domain\CoreGameLogic\GameId;
use Domain\CoreGameLogic\PlayerId;
use Filament\Actions\Action;
use Filament\Actions\ImportAction;
use Filament\Facades\Filament;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Support\Str;

Expand All @@ -37,6 +39,7 @@ protected function getHeaderActions(): array

$allPlayers = $course->players;
$players = [];
// TODO players who created their own game are not included at this point
foreach ($allPlayers as $player) {
// check if player is already in a game for this course
/** @phpstan-ignore staticMethod.dynamicCall, staticMethod.dynamicCall */
Expand All @@ -45,20 +48,26 @@ protected function getHeaderActions(): array
}
}

// current user is the creator of the games
$panel = Filament::getCurrentPanel();
$user = $panel?->auth()->user();

$playersPerGame = 4;
$numberOfGames = (int) ceil(count($players) / $playersPerGame);
for ($i = 0; $i < $numberOfGames; $i++) {
$game = new Game();
/** @phpstan-ignore assign.propertyType */
$game->id = Str::ulid();
$game->course()->associate($course);
$game->creator()->associate($user); // no creator
$game->save();
$game->players()->attach(array_slice($players, $i * $playersPerGame, $playersPerGame));
/** @phpstan-ignore method.nonObject */
$coreGameLogic->handle(GameId::fromString($game->id->toString()), StartPreGame::create(
numberOfPlayers: count($game->players)
)->withFixedPlayerIds(
...array_map(fn($user) => PlayerId::fromString($user->email), $game->players->all())
/** @phpstan-ignore argument.type */
array_map(fn(Player $user) => PlayerId::fromString($user->id), $game->players->all())
));
}
$this->redirect($this::getResource()::getUrl('view', ['record' => $course]));
Expand Down
25 changes: 23 additions & 2 deletions app/app/Filament/Admin/Resources/GameResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class GameResource extends Resource
{
protected static ?string $model = Game::class;

// --- Customize resource names here ---
// The name in the navigation sidebar
protected static ?string $navigationLabel = 'Spiele';
// The singular name displayed on pages and in breadcrumbs
protected static ?string $label = 'Spiel';
// The plural name displayed in the sidebar and table headers
protected static ?string $pluralModelLabel = 'Spiele';

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
Expand All @@ -24,6 +32,13 @@ public static function form(Form $form): Form
Forms\Components\Select::make('course_id')
->relationship('course', 'name')
->preload(),
Forms\Components\Select::make('players')
->label('Spieler:innen')
// email = ScoSciSurvey-ID
->relationship('players', 'email')
->multiple()
->preload()
->searchable(),
]);
}

Expand All @@ -33,8 +48,14 @@ public static function table(Table $table): Table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->searchable()
->toggleable(isToggledHiddenByDefault: false),
->searchable(),
Tables\Columns\TextColumn::make('course.name')
->label('Kurs')
->searchable(),
Tables\Columns\TextColumn::make('creator_name')
->label('Erstellt von')
->getStateUsing(fn (Game $record): string => $record->getCreatorName())
->searchable(),
])
->filters([
//
Expand Down
28 changes: 26 additions & 2 deletions app/app/Filament/Admin/Resources/PlayerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Hash;

class PlayerResource extends Resource
{
protected static ?string $model = Player::class;

// --- Customize resource names here ---
// The name in the navigation sidebar
protected static ?string $navigationLabel = 'Spieler:innen';
// The singular name displayed on pages and in breadcrumbs
protected static ?string $label = 'Spieler:in';
// The plural name displayed in the sidebar and table headers
protected static ?string $pluralModelLabel = 'Spieler:innen';

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
Expand All @@ -27,8 +36,18 @@ public static function form(Form $form): Form
->required()
->maxLength(255),
Forms\Components\TextInput::make('password')
->required()
->maxLength(255),
->label('Passwort')
->password()
->maxLength(255)
// only update password when a new password is set
->afterStateHydrated(function (Forms\Components\TextInput $component, $state) {
$component->state('');
})
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (string $context): bool => $context === 'create'),
Forms\Components\Toggle::make('can_create_games')
->label('Kann Spiele erstellen')
]);
}

Expand All @@ -47,6 +66,11 @@ public static function table(Table $table): Table
->label('SoSciSurvey ID')
->searchable()
->toggleable(),
// bool flag for 'can_create_games'
Tables\Columns\IconColumn::make('can_create_games')
->label('Kann Spiele erstellen')
->boolean()
->toggleable(),
])
->filters([
//
Expand Down
25 changes: 21 additions & 4 deletions app/app/Filament/Admin/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Hash;

class UserResource extends Resource
{
protected static ?string $model = User::class;

// --- Customize resource names here ---
// The name in the navigation sidebar
protected static ?string $navigationLabel = 'Benutzer:innen';
// The singular name displayed on pages and in breadcrumbs
protected static ?string $label = 'Benutzer:in';
// The plural name displayed in the sidebar and table headers
protected static ?string $pluralModelLabel = 'Benutzer:innen';

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';

public static function form(Form $form): Form
Expand All @@ -37,8 +46,16 @@ public static function form(Form $form): Form
->required()
->maxLength(255),
Forms\Components\TextInput::make('password')
->required()
->maxLength(255),
->label('Passwort')
->password()
->maxLength(255)
// only update password when a new password is set
->afterStateHydrated(function (Forms\Components\TextInput $component, $state) {
$component->state('');
})
->dehydrateStateUsing(fn ($state) => Hash::make($state))
->dehydrated(fn ($state) => filled($state))
->required(fn (string $context): bool => $context === 'create'),
Forms\Components\DateTimePicker::make('email_verified_at')
->disabled(),
Forms\Components\Toggle::make('role_superadmin')
Expand All @@ -64,7 +81,7 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('email_verified_at')
->dateTime()
->sortable()
->toggleable(),
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
Expand All @@ -75,7 +92,7 @@ public static function table(Table $table): Table
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\IconColumn::make('role_superadmin')
->boolean()
->toggleable(),
->toggleable(isToggledHiddenByDefault: true),
])
->filters([

Expand Down
Loading