Pogress, not workin though
This commit is contained in:
parent
ddd4632509
commit
44cde39c16
|
|
@ -3,22 +3,24 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\AuditionCacheService;
|
||||
use App\Services\TabulationService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
protected $scoringGuideCacheService;
|
||||
protected $tabulationService;
|
||||
|
||||
public function __construct(AuditionCacheService $scoringGuideCacheService)
|
||||
public function __construct(AuditionCacheService $scoringGuideCacheService, TabulationService $tabulationService)
|
||||
{
|
||||
$this->scoringGuideCacheService = $scoringGuideCacheService;
|
||||
$this->tabulationService = $tabulationService;
|
||||
}
|
||||
|
||||
public function flashTest(Request $request)
|
||||
{
|
||||
$auditions = $this->scoringGuideCacheService->getAuditions();
|
||||
$auditionEleven = $this->scoringGuideCacheService->getAudition(11);
|
||||
return view('test', compact('auditions','auditionEleven'));
|
||||
$auditions = $this->tabulationService->getAuditionsWithStatus();
|
||||
return view('test', compact('auditions'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Collection;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use phpDocumentor\Reflection\Types\Boolean;
|
||||
|
|
@ -139,11 +140,18 @@ class Audition extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
* @return BelongsToMany|\App\Models\User[]
|
||||
*/
|
||||
public function judges()
|
||||
{
|
||||
return $this->room->judges;
|
||||
return $this->belongsToMany(
|
||||
User::class, // The related model
|
||||
'room_user', // The intermediate table
|
||||
'room_id', // The foreign key on the intermediate table
|
||||
'user_id', // The related key on the intermediate table
|
||||
'room_id', // The local key
|
||||
'id' // The local ke
|
||||
);
|
||||
}
|
||||
|
||||
public function scoredEntries()
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
|
||||
class RoomUser extends Model
|
||||
{
|
||||
protected $table = 'room_user';
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ namespace App\Providers;
|
|||
|
||||
use App\Events\AuditionChange;
|
||||
use App\Listeners\RefreshAuditionCache;
|
||||
use App\Services\AuditionCacheService;
|
||||
use App\Services\TabulationService;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
|
|
@ -14,7 +16,13 @@ class AppServiceProvider extends ServiceProvider
|
|||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
$this->app->singleton(AuditionCacheService::class, function ($app) {
|
||||
return new AuditionCacheService();
|
||||
});
|
||||
|
||||
$this->app->singleton(TabulationService::class, function($app) {
|
||||
return new TabulationService($app->make(AuditionCacheService::class));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ class AuditionCacheService
|
|||
//
|
||||
}
|
||||
|
||||
public function getAuditions()
|
||||
public function getAuditions(): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
return Cache::rememberForever($this->cacheKey, function () {
|
||||
return Audition::with(['scoringGuide.subscores'])->get();
|
||||
return Audition::with(['scoringGuide.subscores'])->get()->keyBy('id');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,57 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Audition;
|
||||
use App\Models\Entry;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Services\AuditionCacheService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
class TabulationService
|
||||
{
|
||||
protected $cacheKey = 'entries';
|
||||
protected $auditionCacheService;
|
||||
/**
|
||||
* Create a new class instance.
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(AuditionCacheService $scoringGuideCacheService)
|
||||
{
|
||||
//
|
||||
$this->auditionCacheService = $scoringGuideCacheService;
|
||||
}
|
||||
|
||||
public function getScoredEntries()
|
||||
{
|
||||
return Cache::remember($this->cacheKey, 10, function () {
|
||||
$entries = Entry::with(['scoreSheets'])->get();
|
||||
return $entries->keyBy('id');
|
||||
});
|
||||
}
|
||||
|
||||
public function getAuditionsWithStatus()
|
||||
{
|
||||
$scoreCountByEntry = DB::table('score_sheets')
|
||||
->select('entry_id', DB::raw('count(*) as count'))
|
||||
->groupBy('entry_id')
|
||||
->get()
|
||||
->pluck('count','entry_id');
|
||||
$auditions = $this->auditionCacheService->getAuditions();
|
||||
$auditions->load(['entries' => function ($query) {
|
||||
$query->select('id');
|
||||
}]);
|
||||
$auditions->loadCount('judges');
|
||||
$auditions->loadCount('entries');
|
||||
|
||||
foreach ($auditions as $audition)
|
||||
{
|
||||
// Get the count of entries that have been scored
|
||||
$audition->scored_entries = $audition->entries->filter(function ($entry) use ($scoreCountByEntry) {
|
||||
return $entry->score_sheets_count == $scoreCountByEntry[$entry->id];
|
||||
});
|
||||
// WHY WILL THIS NOT WORK?????
|
||||
|
||||
}
|
||||
|
||||
return $auditions;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,17 @@
|
|||
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||
|
||||
@php
|
||||
dump($auditionEleven);
|
||||
$auditions->load('entries.scoreSheets');
|
||||
dump($auditions);
|
||||
|
||||
@endphp
|
||||
@foreach($auditions as $a)
|
||||
{{$a->entries->count()}}<hr>
|
||||
|
||||
@foreach($auditions as $audition)
|
||||
@php
|
||||
dd($audition->scored_entries);
|
||||
@endphp
|
||||
{{ $audition->name }} has {{ $audition->entries_count }} entries. {{ $audition->scored_entry_count }} are fully scored.<br>
|
||||
@endforeach
|
||||
|
||||
|
||||
|
||||
</x-layout.app>
|
||||
|
|
|
|||
Loading…
Reference in New Issue