Rewrite tabulation #14
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
|
|
||||||
class Event extends Model
|
class Event extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +23,7 @@ class Event extends Model
|
||||||
->orderBy('rank');
|
->orderBy('rank');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entries()
|
public function entries(): HasManyThrough
|
||||||
{
|
{
|
||||||
return $this->hasManyThrough(Entry::class, Audition::class);
|
return $this->hasManyThrough(Entry::class, Audition::class);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
|
|
||||||
public function isJudge(): bool
|
public function isJudge(): bool
|
||||||
{
|
{
|
||||||
return $this->judgingAssignments->count() > 0;
|
return $this->judgingAssignments()->count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ use App\Observers\StudentObserver;
|
||||||
use App\Observers\SubscoreDefinitionObserver;
|
use App\Observers\SubscoreDefinitionObserver;
|
||||||
use App\Observers\UserObserver;
|
use App\Observers\UserObserver;
|
||||||
use App\Services\AuditionService;
|
use App\Services\AuditionService;
|
||||||
|
use App\Services\DoublerService;
|
||||||
use App\Services\DrawService;
|
use App\Services\DrawService;
|
||||||
use App\Services\EntryService;
|
use App\Services\EntryService;
|
||||||
use App\Services\ScoreService;
|
use App\Services\ScoreService;
|
||||||
|
|
@ -49,6 +50,7 @@ class AppServiceProvider extends ServiceProvider
|
||||||
$this->app->singleton(EntryService::class, EntryService::class);
|
$this->app->singleton(EntryService::class, EntryService::class);
|
||||||
$this->app->singleton(ScoreService::class, ScoreService::class);
|
$this->app->singleton(ScoreService::class, ScoreService::class);
|
||||||
$this->app->singleton(UserService::class, UserService::class);
|
$this->app->singleton(UserService::class, UserService::class);
|
||||||
|
$this->app->singleton(DoublerService::class, DoublerService::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,32 +3,36 @@
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
|
use App\Models\Event;
|
||||||
use App\Models\Student;
|
use App\Models\Student;
|
||||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class DoublerService
|
class DoublerService
|
||||||
{
|
{
|
||||||
protected $doublersCacheKey = 'doublers';
|
public function doublersForEvent(Event $event)
|
||||||
|
{
|
||||||
protected $auditionService;
|
$cacheKey = 'event'.$event->id.'doublers';
|
||||||
|
return Cache::remember($cacheKey, 60, function () use ($event) {
|
||||||
protected $tabulationService;
|
return $this->findDoublersForEvent($event);
|
||||||
|
});
|
||||||
protected $seatingService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new class instance.
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
AuditionService $auditionService,
|
|
||||||
TabulationService $tabulationService,
|
|
||||||
SeatingService $seatingService
|
|
||||||
) {
|
|
||||||
$this->auditionService = $auditionService;
|
|
||||||
$this->tabulationService = $tabulationService;
|
|
||||||
$this->seatingService = $seatingService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function findDoublersForEvent(Event $event): array
|
||||||
|
{
|
||||||
|
$entries = $event->entries;
|
||||||
|
$entries->load('student.school');
|
||||||
|
$entries->load('audition');
|
||||||
|
$grouped = $entries->groupBy('student_id');
|
||||||
|
// Filter out student groups with only one entry in the event
|
||||||
|
$grouped = $grouped->filter(fn ($s) => $s->count() > 1);
|
||||||
|
$doubler_array = [];
|
||||||
|
foreach ($grouped as $student_id => $entries) {
|
||||||
|
$doubler_array[$student_id] = [
|
||||||
|
'student' => $entries[0]->student,
|
||||||
|
'entries' => $entries,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $doubler_array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue