Model updates dealing with doublers.
This commit is contained in:
parent
630efaf00f
commit
f0daa05fcf
|
|
@ -4,6 +4,7 @@ namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class Doubler extends Model
|
class Doubler extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -28,6 +29,11 @@ class Doubler extends Model
|
||||||
return $this->belongsTo(Event::class);
|
return $this->belongsTo(Event::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function entries(): Collection
|
||||||
|
{
|
||||||
|
return Entry::whereIn('id', $this->entries)->get();
|
||||||
|
}
|
||||||
|
|
||||||
// Find a doubler based on both keys
|
// Find a doubler based on both keys
|
||||||
public static function findDoubler($studentId, $eventId)
|
public static function findDoubler($studentId, $eventId)
|
||||||
{
|
{
|
||||||
|
|
@ -54,20 +60,19 @@ class Doubler extends Model
|
||||||
->where('auditions.event_id', $eventId)
|
->where('auditions.event_id', $eventId)
|
||||||
->groupBy('students.id')
|
->groupBy('students.id')
|
||||||
->havingRaw('COUNT(entries.id) > 1')
|
->havingRaw('COUNT(entries.id) > 1')
|
||||||
|
->with('entries')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($studentsWithMultipleEntries as $student) {
|
foreach ($studentsWithMultipleEntries as $student) {
|
||||||
// Get entries that are not declined. If only one, they're our accepted entry.
|
// Get entries that are not declined. If only one, they're our accepted entry.
|
||||||
$availableEntries = $student->entries()->available()->get();
|
$entryList = collect(); // List of entry ids for th is student in this event
|
||||||
if ($availableEntries->count() === 1) {
|
$undecidedEntries = collect(); // List of entry ids that are not declined, no-show, or failed prelim
|
||||||
$acceptedEntryId = $availableEntries->first()->id;
|
$entryList = $student->entriesForEvent($eventId)->pluck('id');
|
||||||
} else {
|
$undecidedEntries = $student->entriesForEvent($eventId)
|
||||||
$acceptedEntryId = null;
|
->whereDoesntHave('flags', function ($query) {
|
||||||
}
|
$query->whereIn('flag_name', ['declined', 'no-show', 'failed-prelim']);
|
||||||
|
})
|
||||||
// Form a list of entry IDs for this doubler
|
->pluck('id');
|
||||||
$entryList = [];
|
|
||||||
$entryList = $student->entriesForEvent($eventId)->pluck('id')->toArray();
|
|
||||||
|
|
||||||
// Create or update the doubler record
|
// Create or update the doubler record
|
||||||
static::updateOrCreate(
|
static::updateOrCreate(
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class Student extends Model
|
||||||
{
|
{
|
||||||
$eventId = $event instanceof Event ? $event->id : $event;
|
$eventId = $event instanceof Event ? $event->id : $event;
|
||||||
|
|
||||||
return DoublerEntryCount::where([
|
return Doubler::where([
|
||||||
'event_id' => $eventId,
|
'event_id' => $eventId,
|
||||||
'student_id' => $this->id,
|
'student_id' => $this->id,
|
||||||
])->exists();
|
])->exists();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue