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\Entry;
|
||||
use App\Models\ScoreSheet;
|
||||
use App\Models\SubscoreDefinition;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use function compact;
|
||||
|
|
@ -23,9 +25,9 @@ class JudgingController extends Controller
|
|||
public function auditionEntryList(Audition $audition)
|
||||
{
|
||||
// TODO verify user is assigned to judge this audition
|
||||
$entries = Entry::where('audition_id','=',$audition->id)->orderBy('draw_number')->get();
|
||||
|
||||
return view('judging.audition_entry_list', compact('audition','entries'));
|
||||
$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','subscores'));
|
||||
}
|
||||
|
||||
public function entryScoreSheet(Entry $entry)
|
||||
|
|
@ -36,13 +38,30 @@ class JudgingController extends Controller
|
|||
|
||||
public function saveScoreSheet(Request $request, Entry $entry)
|
||||
{
|
||||
Gate::authorize('create',[ScoreSheet::class,$entry]);
|
||||
// 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'));
|
||||
if ($scoreValidation != 'success') {
|
||||
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\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
|
||||
class Entry extends Model
|
||||
|
|
@ -32,4 +34,14 @@ class Entry extends Model
|
|||
'student_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\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
|
@ -129,4 +130,19 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
if ($this->is_admin) return true;
|
||||
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;
|
||||
|
||||
use App\Models\Entry;
|
||||
use App\Models\ScoreSheet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
|
@ -27,9 +28,10 @@ class ScoreSheetPolicy
|
|||
/**
|
||||
* 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>
|
||||
<thead>
|
||||
<tr>
|
||||
<x-table.th>Entry</x-table.th>
|
||||
@foreach($audition->scoringGuide->subscores()->orderBy('display_order')->get(); as $subscore)
|
||||
<x-table.th>{{ $subscore->name }}</x-table.th>
|
||||
<x-table.th :sortable="false"><a href="{{ url()->current() }}">Entry</a></x-table.th>
|
||||
@foreach($subscores as $subscore)
|
||||
<x-table.th :sortable="false">{{ $subscore->name }}</x-table.th>
|
||||
@endforeach
|
||||
<x-table.th :sortable="true">Timestamp</x-table.th>
|
||||
</tr>
|
||||
</thead>
|
||||
<x-table.body>
|
||||
|
|
@ -19,6 +20,16 @@
|
|||
{{ $audition->name }} {{ $entry->draw_number }}
|
||||
</a>
|
||||
</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>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
@php use App\Models\Audition;
|
||||
use App\Models\School;
|
||||
use App\Models\Entry;use App\Models\School;
|
||||
use App\Models\SchoolEmailDomain;
|
||||
use App\Models\ScoreSheet;
|
||||
use App\Models\ScoringGuide;
|
||||
|
|
@ -8,13 +8,24 @@
|
|||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
@endphp
|
||||
@endphp
|
||||
<x-layout.app>
|
||||
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||
|
||||
@php
|
||||
$user = User::find(1);
|
||||
dump($user->isJudge());
|
||||
dump(Auth::user()->scoreSheets->where('entry_id','=','997')->first()->subscores[6]['score']);
|
||||
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
|
||||
|
||||
</x-layout.app>
|
||||
|
|
|
|||
Loading…
Reference in New Issue