add poker planing for students
This commit is contained in:
93
app/Http/Controllers/PokerController.php
Normal file
93
app/Http/Controllers/PokerController.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user