Doubler blocks displaying on seating page
This commit is contained in:
parent
74e2d47eae
commit
3290687ba7
|
|
@ -20,29 +20,43 @@ class DoublerService
|
||||||
$this->tabulationService = $tabulationService;
|
$this->tabulationService = $tabulationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a collection of students that have more than one entry
|
||||||
|
* @return \Illuminate\Database\Eloquent\Collection
|
||||||
|
*/
|
||||||
public function getDoublers(): \Illuminate\Database\Eloquent\Collection
|
public function getDoublers(): \Illuminate\Database\Eloquent\Collection
|
||||||
{
|
{
|
||||||
return Cache::remember($this->doublersCacheKey, 10, function () {
|
// TODO creating or destroying an entry should refresh the doubler cache
|
||||||
$students = Student::withCount('entries')
|
return Cache::remember($this->doublersCacheKey, 3600, function () {
|
||||||
|
return Student::withCount('entries')
|
||||||
->with('entries')
|
->with('entries')
|
||||||
->havingRaw('entries_count > ?', [1])
|
->havingRaw('entries_count > ?', [1])
|
||||||
->get();
|
->get();
|
||||||
return $students;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDoublerInfo($id): Array
|
/**
|
||||||
|
* Returns an array of information about each entry for a specific doubler. Info for each entry includes
|
||||||
|
* auditionID
|
||||||
|
* auditionName
|
||||||
|
* rank => This student's rank in the given audition
|
||||||
|
* unscored => How many entries remain to be scored in this audition
|
||||||
|
*
|
||||||
|
* @param int $studentId The ID of the doubler
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDoublerInfo($studentId): array
|
||||||
{
|
{
|
||||||
// When getting a doubler we need to know
|
// When getting a doubler we need to know
|
||||||
// 1) What their entrires are
|
// 1) What their entries are
|
||||||
// 2) For each audition they're entered in, what is their rank
|
// 2) For each audition they're entered in, what is their rank
|
||||||
// 3) For each audition they'er entered in, how many entries are unscored
|
// 3) For each audition they're entered in, how many entries are unscored
|
||||||
// 4) How many are accepted on that instrument
|
// 4) How many are accepted on that instrument
|
||||||
$doubler = $this->getDoublers()->firstWhere('id',$id);
|
$doubler = $this->getDoublers()->firstWhere('id',$studentId);
|
||||||
$info = [];
|
$info = [];
|
||||||
|
|
||||||
foreach ($doubler->entries as $entry) {
|
foreach ($doubler->entries as $entry) {
|
||||||
$info[] = [
|
$info[$entry->id] = [
|
||||||
'auditionID' => $entry->audition_id,
|
'auditionID' => $entry->audition_id,
|
||||||
'auditionName' => $this->auditionCacheService->getAudition($entry->audition_id)->name,
|
'auditionName' => $this->auditionCacheService->getAudition($entry->audition_id)->name,
|
||||||
'rank' => $this->tabulationService->entryRank($entry),
|
'rank' => $this->tabulationService->entryRank($entry),
|
||||||
|
|
@ -55,9 +69,14 @@ class DoublerService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function entryIsDoubler(Entry $entry): bool
|
/**
|
||||||
|
* Checks if a student is a doubler based on the given student ID
|
||||||
|
*
|
||||||
|
* @param int $studentId The ID of the student to check
|
||||||
|
* @return bool Returns true if the student is a doubler, false otherwise
|
||||||
|
*/
|
||||||
|
public function studentIsDoubler($studentId): bool
|
||||||
{
|
{
|
||||||
// Return true if $entry->student_id is associated with a student in the collection from $this->getDoublers()
|
return $this->getDoublers()->contains('id', $studentId);
|
||||||
return $this->getDoublers()->contains('id', $entry->student_id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,9 @@ class ScoreService
|
||||||
{
|
{
|
||||||
$audition = $this->auditionCache->getAudition($auditionId);
|
$audition = $this->auditionCache->getAudition($auditionId);
|
||||||
$scoringGuideId = $audition->scoring_guide_id;
|
$scoringGuideId = $audition->scoring_guide_id;
|
||||||
$entries = Entry::where('audition_id',$auditionId)->with('scoreSheets')->get();
|
// $entries = Entry::where('audition_id',$auditionId)->with('scoreSheets')->get();
|
||||||
|
$entries = $this->entryCache->getEntriesForAudition($auditionId);
|
||||||
|
$entries->load('scoreSheets');
|
||||||
|
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$cacheKey = 'entry' . $entry->id . 'totalScores';
|
$cacheKey = 'entry' . $entry->id . 'totalScores';
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,21 @@ class TabulationService
|
||||||
$this->entryCacheService = $entryCacheService;
|
$this->entryCacheService = $entryCacheService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the rank of the entry in its audition
|
||||||
|
* @param Entry $entry
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function entryRank(Entry $entry) {
|
public function entryRank(Entry $entry) {
|
||||||
return $this->auditionEntries($entry->audition_id)[$entry->id]->rank;
|
return $this->auditionEntries($entry->audition_id)[$entry->id]->rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a collection of entries including their calculated final_score_array and ranked
|
||||||
|
* based upon their scores.
|
||||||
|
* @param Int $auditionId
|
||||||
|
* @return \Illuminate\Support\Collection|mixed
|
||||||
|
*/
|
||||||
public function auditionEntries(Int $auditionId)
|
public function auditionEntries(Int $auditionId)
|
||||||
{
|
{
|
||||||
static $cache = [];
|
static $cache = [];
|
||||||
|
|
@ -81,6 +92,11 @@ class TabulationService
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of un-scored entries for the audition with the given ID.
|
||||||
|
* @param $auditionId
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function remainingEntriesForAudition($auditionId)
|
public function remainingEntriesForAudition($auditionId)
|
||||||
{
|
{
|
||||||
$audition = $this->getAuditionsWithStatus()[$auditionId];
|
$audition = $this->getAuditionsWithStatus()[$auditionId];
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
@inject('doublers','\App\Services\DoublerService')
|
@props(['doublerEntryInfo'])
|
||||||
@inject('tabulation','\App\Services\TabulationService')
|
|
||||||
@props(['studentID'])
|
|
||||||
@php
|
|
||||||
$doublerEntryInfo = $doublers->getDoublerInfo($studentID);
|
|
||||||
@endphp
|
|
||||||
<ul role="list" class="divide-y divide-gray-100">
|
<ul role="list" class="divide-y divide-gray-100">
|
||||||
|
|
||||||
@foreach($doublerEntryInfo as $info)
|
@foreach($doublerEntryInfo as $info)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
|
@inject('doublerService','App\Services\DoublerService')
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-slot:page_title>Audition Seating - {{ $audition->name }}</x-slot:page_title>
|
<x-slot:page_title>Audition Seating - {{ $audition->name }}</x-slot:page_title>
|
||||||
|
|
||||||
<x-table.table>
|
<x-table.table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<x-table.th>Rank</x-table.th>
|
||||||
<x-table.th>ID</x-table.th>
|
<x-table.th>ID</x-table.th>
|
||||||
<x-table.th>Draw #</x-table.th>
|
<x-table.th>Draw #</x-table.th>
|
||||||
<x-table.th>Student Name</x-table.th>
|
<x-table.th>Student Name</x-table.th>
|
||||||
|
|
@ -20,6 +21,7 @@
|
||||||
<x-table.body>
|
<x-table.body>
|
||||||
@foreach($entries as $entry)
|
@foreach($entries as $entry)
|
||||||
<tr>
|
<tr>
|
||||||
|
<x-table.td>{{ $entry->rank }}</x-table.td>
|
||||||
<x-table.td>{{ $entry->id }}</x-table.td>
|
<x-table.td>{{ $entry->id }}</x-table.td>
|
||||||
<x-table.td>{{ $entry->draw_number }}</x-table.td>
|
<x-table.td>{{ $entry->draw_number }}</x-table.td>
|
||||||
<x-table.td>
|
<x-table.td>
|
||||||
|
|
@ -27,6 +29,10 @@
|
||||||
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
|
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
|
||||||
</x-table.td>
|
</x-table.td>
|
||||||
<x-table.td>
|
<x-table.td>
|
||||||
|
@if($doublerService->studentIsDoubler($entry->student_id))
|
||||||
|
<x-doubler-block :doublerEntryInfo="$doublerService->getDoublerInfo($entry->student_id)" />
|
||||||
|
@endif
|
||||||
|
|
||||||
{{-- @if($entry->is_doubler)--}}
|
{{-- @if($entry->is_doubler)--}}
|
||||||
{{-- <x-doubler-block :studentID="$entry->student->id" />--}}
|
{{-- <x-doubler-block :studentID="$entry->student->id" />--}}
|
||||||
{{-- @endif--}}
|
{{-- @endif--}}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue