Judging working
This commit is contained in:
parent
359ad3252c
commit
1f4f919c48
|
|
@ -4,8 +4,10 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
use App\Models\Entry;
|
use App\Models\Entry;
|
||||||
|
use App\Models\ScoreSheet;
|
||||||
use App\Models\SubscoreDefinition;
|
use App\Models\SubscoreDefinition;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use function compact;
|
use function compact;
|
||||||
|
|
@ -23,9 +25,9 @@ class JudgingController extends Controller
|
||||||
public function auditionEntryList(Audition $audition)
|
public function auditionEntryList(Audition $audition)
|
||||||
{
|
{
|
||||||
// TODO verify user is assigned to judge this audition
|
// TODO verify user is assigned to judge this audition
|
||||||
$entries = Entry::where('audition_id','=',$audition->id)->orderBy('draw_number')->get();
|
$entries = Entry::where('audition_id','=',$audition->id)->orderBy('draw_number')->with('audition')->get();
|
||||||
|
$subscores = $audition->scoringGuide->subscores()->orderBy('display_order')->get();
|
||||||
return view('judging.audition_entry_list', compact('audition','entries'));
|
return view('judging.audition_entry_list', compact('audition','entries','subscores'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entryScoreSheet(Entry $entry)
|
public function entryScoreSheet(Entry $entry)
|
||||||
|
|
@ -36,13 +38,30 @@ class JudgingController extends Controller
|
||||||
|
|
||||||
public function saveScoreSheet(Request $request, Entry $entry)
|
public function saveScoreSheet(Request $request, Entry $entry)
|
||||||
{
|
{
|
||||||
|
Gate::authorize('create',[ScoreSheet::class,$entry]);
|
||||||
// TODO verify user is assigned to judge this audition
|
// TODO verify user is assigned to judge this audition
|
||||||
$scoringGuide = $entry->audition->scoringGuide;
|
$scoringGuide = $entry->audition->scoringGuide()->with('subscores')->first();
|
||||||
$scoreValidation = $scoringGuide->validateScores($request->input('score'));
|
$scoreValidation = $scoringGuide->validateScores($request->input('score'));
|
||||||
if ($scoreValidation != 'success') {
|
if ($scoreValidation != 'success') {
|
||||||
return redirect(url()->previous())->with('error', $scoreValidation)->with('oldScores',$request->all());
|
return redirect(url()->previous())->with('error', $scoreValidation)->with('oldScores',$request->all());
|
||||||
}
|
}
|
||||||
dd($scoreValidation);
|
$scoreSheetArray = [];
|
||||||
|
foreach($scoringGuide->subscores as $subscore) {
|
||||||
|
$scoreSheetArray[$subscore->id] = [
|
||||||
|
'score' => $request->input('score')[$subscore->id],
|
||||||
|
'subscore_id' => $subscore->id,
|
||||||
|
'subscore_name' => $subscore->name
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreSheet::create([
|
||||||
|
'user_id' => Auth::user()->id,
|
||||||
|
'entry_id' => $entry->id,
|
||||||
|
'subscores' => $scoreSheetArray
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect('/judging/audition/' . $entry->audition_id)->with('success','Entered scores for ' . $entry->audition->name . ' ' . $entry->draw_number);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ 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\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||||
|
|
||||||
class Entry extends Model
|
class Entry extends Model
|
||||||
|
|
@ -32,4 +34,14 @@ class Entry extends Model
|
||||||
'student_id',
|
'student_id',
|
||||||
'school_id');
|
'school_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scoreSheets(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(ScoreSheet::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scoreFromJudge($user): ScoreSheet|null
|
||||||
|
{
|
||||||
|
return $this->scoreSheets()->where('user_id','=',$user)->first() ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
|
@ -129,4 +130,19 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
if ($this->is_admin) return true;
|
if ($this->is_admin) return true;
|
||||||
return $this->is_tab;
|
return $this->is_tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scoreSheets(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(ScoreSheet::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scoresForEntry($entry)
|
||||||
|
{
|
||||||
|
return $this->scoreSheets->where('entry_id','=',$entry)->first()?->subscores;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function timeForEntryScores($entry)
|
||||||
|
{
|
||||||
|
return $this->scoreSheets->where('entry_id','=',$entry)->first()?->created_at;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Policies;
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\Entry;
|
||||||
use App\Models\ScoreSheet;
|
use App\Models\ScoreSheet;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Auth\Access\Response;
|
use Illuminate\Auth\Access\Response;
|
||||||
|
|
@ -27,9 +28,10 @@ class ScoreSheetPolicy
|
||||||
/**
|
/**
|
||||||
* Determine whether the user can create models.
|
* Determine whether the user can create models.
|
||||||
*/
|
*/
|
||||||
public function create(User $user): bool
|
public function create(User $user, Entry $entry): bool
|
||||||
{
|
{
|
||||||
//
|
$room = $entry->audition->room;
|
||||||
|
return $user->judgingAssignments->contains($room);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,11 @@
|
||||||
<x-table.table>
|
<x-table.table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<x-table.th>Entry</x-table.th>
|
<x-table.th :sortable="false"><a href="{{ url()->current() }}">Entry</a></x-table.th>
|
||||||
@foreach($audition->scoringGuide->subscores()->orderBy('display_order')->get(); as $subscore)
|
@foreach($subscores as $subscore)
|
||||||
<x-table.th>{{ $subscore->name }}</x-table.th>
|
<x-table.th :sortable="false">{{ $subscore->name }}</x-table.th>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
<x-table.th :sortable="true">Timestamp</x-table.th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<x-table.body>
|
<x-table.body>
|
||||||
|
|
@ -19,6 +20,16 @@
|
||||||
{{ $audition->name }} {{ $entry->draw_number }}
|
{{ $audition->name }} {{ $entry->draw_number }}
|
||||||
</a>
|
</a>
|
||||||
</x-table.td>
|
</x-table.td>
|
||||||
|
@foreach($subscores as $subscore)
|
||||||
|
<x-table.td>
|
||||||
|
@php
|
||||||
|
if( $x = Auth::user()->scoresForEntry($entry->id)) echo $x[$subscore->id]['score'];
|
||||||
|
@endphp
|
||||||
|
</x-table.td>
|
||||||
|
@endforeach
|
||||||
|
<x-table.td>
|
||||||
|
{{ Auth::user()->timeForEntryScores($entry->id)?->setTimezone('America/Chicago')->format('m/d/y H:i') }}
|
||||||
|
</x-table.td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</x-table.body>
|
</x-table.body>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
@php use App\Models\Audition;
|
@php use App\Models\Audition;
|
||||||
use App\Models\School;
|
use App\Models\Entry;use App\Models\School;
|
||||||
use App\Models\SchoolEmailDomain;
|
use App\Models\SchoolEmailDomain;
|
||||||
use App\Models\ScoreSheet;
|
use App\Models\ScoreSheet;
|
||||||
use App\Models\ScoringGuide;
|
use App\Models\ScoringGuide;
|
||||||
|
|
@ -13,8 +13,19 @@
|
||||||
<x-slot:page_title>Test Page</x-slot:page_title>
|
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||||
|
|
||||||
@php
|
@php
|
||||||
$user = User::find(1);
|
dump(Auth::user()->scoreSheets->where('entry_id','=','997')->first()->subscores[6]['score']);
|
||||||
dump($user->isJudge());
|
echo "-----";
|
||||||
|
dump(Auth::user()->scoresForEntry(997));
|
||||||
|
echo "-----";
|
||||||
|
dump(Auth::user()->scoresForEntry(997)[6]['score']);
|
||||||
|
echo "-----";
|
||||||
|
dump(Auth::user()->scoresForEntry(997)[7]['score']);
|
||||||
|
echo "-----";
|
||||||
|
dump(Auth::user()->scoresForEntry(997)[8]['score']);
|
||||||
|
echo "-----";
|
||||||
|
dump(Auth::user()->scoresForEntry(997)[9]['score']);
|
||||||
|
echo "-----";
|
||||||
|
dump(Auth::user()->scoresForEntry(997)[10]['score']);
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
</x-layout.app>
|
</x-layout.app>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue