Audition status screen updated to use Tabulation service
This commit is contained in:
parent
b970828b31
commit
6386a204d7
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
use App\Models\ScoreSheet;
|
use App\Models\ScoreSheet;
|
||||||
|
use App\Services\TabulationService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use function compact;
|
use function compact;
|
||||||
|
|
@ -14,14 +15,19 @@ use function redirect;
|
||||||
|
|
||||||
class TabulationController extends Controller
|
class TabulationController extends Controller
|
||||||
{
|
{
|
||||||
|
protected $tabulationService;
|
||||||
|
|
||||||
|
public function __construct(TabulationService $tabulationService)
|
||||||
|
{
|
||||||
|
$this->tabulationService = $tabulationService;
|
||||||
|
}
|
||||||
|
|
||||||
public function status()
|
public function status()
|
||||||
{
|
{
|
||||||
$auditions = Audition::with(['entries' => function($query) {
|
// $auditions = Audition::with(['entries' => function($query) {
|
||||||
$query->withCount('scoreSheets');
|
// $query->withCount('scoreSheets');
|
||||||
},'room.judges'])->orderBy('score_order')->get();
|
// },'room.judges'])->orderBy('score_order')->get();
|
||||||
|
$auditions = $this->tabulationService->getAuditionsWithStatus();
|
||||||
return view('tabulation.status',compact('auditions'));
|
return view('tabulation.status',compact('auditions'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace App\Services;
|
||||||
|
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
|
use App\Models\ScoreSheet;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use App\Services\AuditionCacheService;
|
use App\Services\AuditionCacheService;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
@ -32,8 +33,7 @@ class TabulationService
|
||||||
public function getAuditionsWithStatus()
|
public function getAuditionsWithStatus()
|
||||||
{
|
{
|
||||||
// Create an array with the number of scores for each entry
|
// Create an array with the number of scores for each entry
|
||||||
$scoreCountByEntry = DB::table('score_sheets')
|
$scoreCountByEntry = ScoreSheet::select('entry_id', DB::raw('count(*) as count'))
|
||||||
->select('entry_id', DB::raw('count(*) as count'))
|
|
||||||
->groupBy('entry_id')
|
->groupBy('entry_id')
|
||||||
->get()
|
->get()
|
||||||
->pluck('count','entry_id');
|
->pluck('count','entry_id');
|
||||||
|
|
@ -42,20 +42,16 @@ class TabulationService
|
||||||
$auditions = $this->auditionCacheService->getAuditions();
|
$auditions = $this->auditionCacheService->getAuditions();
|
||||||
$auditions->load('entries');
|
$auditions->load('entries');
|
||||||
|
|
||||||
$auditions->loadCount('judges');
|
// Eager load the count of related models
|
||||||
$auditions->loadCount('entries');
|
$auditions->loadCount(['judges', 'entries']);
|
||||||
|
|
||||||
foreach ($auditions as $audition) {
|
// Iterate over the auditions and calculate the scored_entries_count
|
||||||
$audition->scored_entries_count = 0;
|
return $auditions->map(function ($audition) use ($scoreCountByEntry) {
|
||||||
foreach ($audition->entries as $entry) {
|
$audition->scored_entries_count = $audition->entries->reduce(function ($carry, $entry) use ($audition, $scoreCountByEntry) {
|
||||||
if ($audition->judges_count == $scoreCountByEntry[$entry->id]) {
|
$entry->fully_scored = $audition->judges_count == $scoreCountByEntry[$entry->id];
|
||||||
$entry->fully_scored = true;
|
return $carry + ($entry->fully_scored ? 1 : 0);
|
||||||
$audition->scored_entries_count++;
|
}, 0);
|
||||||
} else {
|
return $audition;
|
||||||
$entry->fully_scored = false;
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $auditions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@
|
||||||
<x-table.td><a href="/tabulation/auditions/{{ $audition->id }}">
|
<x-table.td><a href="/tabulation/auditions/{{ $audition->id }}">
|
||||||
{{ $audition->name }}
|
{{ $audition->name }}
|
||||||
</a></x-table.td>
|
</a></x-table.td>
|
||||||
<x-table.td>{{ $audition->scoredEntries()->count() }} / {{ $audition->entries->count() }} Scored</x-table.td>
|
<x-table.td>{{ $audition->scored_entries_count }} / {{ $audition->entries_count }} Scored</x-table.td>
|
||||||
<td>
|
<td>
|
||||||
@if($audition->scoringIsComplete())
|
@if( $audition->scored_entries_count == $audition->entries_count)
|
||||||
<x-icons.checkmark color="green"/>
|
<x-icons.checkmark color="green"/>
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue