Files
scrum-poker-internal/app/Models/Player.php
T
Twyco 4dfe79ce5c
CI/CD / test_and_check_app (push) Successful in 2m19s
CI/CD / Publish immutable image (push) Successful in 1m16s
kick forever
2026-09-24 14:38:18 +02:00

85 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
/**
* @property int $id
* @property string $room_id
* @property int|null $user_id
* @property string|null $active_instance_id
* @property string $name
* @property bool $is_moderator
* @property Carbon|null $last_seen_at
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read Room $room
*/
class Player extends Model
{
protected $fillable = [
'room_id',
'user_id',
'active_instance_id',
'name',
'is_moderator',
'last_seen_at',
];
protected function casts(): array
{
return [
'is_moderator' => 'boolean',
'last_seen_at' => 'datetime',
];
}
/** @return BelongsTo<Room, $this> */
public function room(): BelongsTo
{
return $this->belongsTo(Room::class);
}
/** @return HasMany<Vote, $this> */
public function votes(): HasMany
{
return $this->hasMany(Vote::class);
}
/** @return BelongsTo<User, $this> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function currentVote(): ?Vote
{
return $this->votes()
->where('round', $this->room->current_round)
->first();
}
public function hasVoted(): bool
{
return $this->votes()
->where('round', $this->room->current_round)
->exists();
}
public function isModerator(): bool
{
return $this->is_moderator;
}
public function markAsSeen(): void
{
$this->update([
'last_seen_at' => now(),
]);
}
}