first commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'registration_id',
|
||||
'comment',
|
||||
];
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Relationships
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// Comment belongs to a student
|
||||
public function registration()
|
||||
{
|
||||
return $this->belongsTo(Registration::class);
|
||||
}
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Helper methods
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// Optional: short preview for UI
|
||||
public function getPreviewAttribute()
|
||||
{
|
||||
return strlen($this->comment) > 50
|
||||
? substr($this->comment, 0, 50) . '...'
|
||||
: $this->comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class GameSession extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'registration_id',
|
||||
'play_date',
|
||||
'score',
|
||||
];
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Relationships
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// Session belongs to a student
|
||||
public function registration()
|
||||
{
|
||||
return $this->belongsTo(Registration::class);
|
||||
}
|
||||
|
||||
// Session has many shots (1 session = 3 shots)
|
||||
public function shots()
|
||||
{
|
||||
return $this->hasMany(GameShot::class);
|
||||
}
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Helper methods
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// Get score as array like [1,0,1]
|
||||
public function getShotArray()
|
||||
{
|
||||
return $this->shots()
|
||||
->orderBy('shot_number')
|
||||
->pluck('result')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
// Check if session is complete (3 shots done)
|
||||
public function isComplete()
|
||||
{
|
||||
return $this->shots()->count() >= 3;
|
||||
}
|
||||
|
||||
// Calculate score from shots (reliable source)
|
||||
public function calculateScore()
|
||||
{
|
||||
return $this->shots()->where('result', 1)->count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class GameShot extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'game_session_id',
|
||||
'shot_number',
|
||||
'result',
|
||||
];
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Relationships
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// Each shot belongs to a session
|
||||
public function session()
|
||||
{
|
||||
return $this->belongsTo(GameSession::class, 'game_session_id');
|
||||
}
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Helper methods
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// Check if this shot is a goal
|
||||
public function isGoal()
|
||||
{
|
||||
return (bool) $this->result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Registration extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'phone',
|
||||
'total_score',
|
||||
];
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Relationships
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// A student has many game sessions (daily plays)
|
||||
public function sessions()
|
||||
{
|
||||
return $this->hasMany(GameSession::class);
|
||||
}
|
||||
|
||||
// A student has many comments
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
|
||||
/*
|
||||
|---------------------------
|
||||
| Helper methods
|
||||
|---------------------------
|
||||
*/
|
||||
|
||||
// Check if student already played today
|
||||
public function playedToday(): bool
|
||||
{
|
||||
return $this->sessions()
|
||||
->whereDate('play_date', today())
|
||||
->whereHas('shots', fn($q) => $q->havingRaw('COUNT(*) >= 3'))
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'role',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->role === 'admin';
|
||||
}
|
||||
|
||||
public function isCounselor()
|
||||
{
|
||||
return $this->role === 'counselor';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user