add poker planing for students

This commit is contained in:
2025-11-15 11:11:04 +03:00
parent a78b63ea2d
commit cf635f81dd
14 changed files with 2799 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
<?php
namespace App\Http\Controllers;
use App\Models\EstimationRound;
use App\Models\Vote;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class PokerController extends Controller
{
// Публичная страница голосования
public function showForm(string $token)
{
$round = EstimationRound::where('token', $token)->firstOrFail();
$votedCount = $round->votes()->count();
if ($votedCount >= $round->max_voters) {
return response('Лимит голосов исчерпан', 403);
}
return view('vote', compact('round'));
}
// Отправка голоса
public function submitVote(Request $request, string $token)
{
$request->validate([
'name' => 'required|string|max:100',
'score' => 'required|integer|min:1'
]);
$session = EstimationRound::where('token', $token)->firstOrFail();
if ($session->votes()->count() >= $session->max_voters) {
return back()->withErrors(['msg' => 'Лимит участников достигнут']);
}
if ($request->score > $session->max_score) {
return back()->withErrors(['score' => 'Оценка не должна превышать ' . $session->max_score]);
}
Vote::create([
'estimation_round_id' => $session->id,
'name' => $request->name,
'score' => $request->score
]);
return redirect()->route('vote.thanks');
}
public function thanks()
{
return view('thanks');
}
// Админка: создание сессии
public function createEstimationRoundForm()
{
return view('admin.create');
}
public function createEstimationRound(Request $request)
{
$request->validate([
'max_score' => 'required|integer|min:1',
'max_voters' => 'required|integer|min:1|max:100'
]);
$session = EstimationRound::create([
'token' => Str::random(12),
'max_score' => $request->max_score,
'max_voters' => $request->max_voters
]);
return redirect()->route('admin.sessions')
->with('success', 'Сессия создана. Ссылка: ' . url('/s/' . $session->token));
}
// Админка: список сессий
public function listEstimationRounds()
{
$sessions = EstimationRound::withCount('votes')->latest()->get();
return view('admin.sessions', compact('sessions'));
}
// Админка: детали сессии
public function showEstimationRound($id)
{
$round = EstimationRound::with('votes')->findOrFail($id);
return view('admin.session', compact('round'));
}
}