Merge remote-tracking branch 'upstream-local/clean-main' into clean-main
This commit is contained in:
@@ -27,23 +27,23 @@ class QuizController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
// 1. Validate only the text and number fields
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
'category_id' => 'required|exists:quiz_categories,id',
|
||||
'year' => 'nullable|integer',
|
||||
'type' => 'required|in:multiple_choice,descriptive,mixed',
|
||||
'duration_minutes' => 'required|integer|min:1',
|
||||
'has_negative_score' => 'boolean',
|
||||
'is_free' => 'boolean',
|
||||
'is_published' => 'boolean',
|
||||
'description' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$validated['slug'] = Str::slug($validated['title']) . '-' . time();
|
||||
// 2. Safely handle checkboxes and generate slug
|
||||
$validated['slug'] = \Illuminate\Support\Str::slug($validated['title']) . '-' . time();
|
||||
$validated['has_negative_score'] = $request->has('has_negative_score');
|
||||
$validated['is_free'] = $request->has('is_free');
|
||||
$validated['is_published'] = $request->has('is_published');
|
||||
|
||||
// 3. Create the quiz
|
||||
$quiz = Quiz::create($validated);
|
||||
|
||||
return redirect()->route('quizzes.questions.index', $quiz->id)
|
||||
|
||||
44
app/Http/Controllers/Admin/QuizSubjectController.php
Normal file
44
app/Http/Controllers/Admin/QuizSubjectController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\QuizSubject;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class QuizSubjectController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
// Load subjects and count how many questions belong to each
|
||||
$subjects = QuizSubject::withCount('questions')->latest()->get();
|
||||
return view('admin.quiz-subjects.index', compact('subjects'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'title' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
QuizSubject::create([
|
||||
'title' => $request->title,
|
||||
// Generate a unique slug for potential API/URL usage
|
||||
'slug' => Str::slug($request->title) . '-' . time(),
|
||||
]);
|
||||
|
||||
return back()->with('success', 'درس با موفقیت اضافه شد.');
|
||||
}
|
||||
|
||||
public function destroy(QuizSubject $quiz_subject)
|
||||
{
|
||||
// Prevent deletion if questions are already assigned to this subject
|
||||
if ($quiz_subject->questions()->count() > 0) {
|
||||
return back()->with('error', 'این درس دارای سوال است و نمیتواند حذف شود. ابتدا سوالات مربوطه را ویرایش یا حذف کنید.');
|
||||
}
|
||||
|
||||
$quiz_subject->delete();
|
||||
return back()->with('success', 'درس با موفقیت حذف شد.');
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,13 @@
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="{{ route('quiz-subjects.index') }}" class="waves-effect">
|
||||
<i class="mdi mdi-book-open-page-variant"></i>
|
||||
<span>مدیریت دروس</span>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<a href="javascript:%20void(0);" class="has-arrow waves-effect">
|
||||
|
||||
77
resources/views/admin/quiz-subjects/index.blade.php
Normal file
77
resources/views/admin/quiz-subjects/index.blade.php
Normal file
@@ -0,0 +1,77 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<!-- Form to Add Subject -->
|
||||
<div class="col-lg-4">
|
||||
<div class="card">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h6 class="mb-0 text-white">افزودن درس جدید</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form action="{{ route('quiz-subjects.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="mb-3">
|
||||
<label class="form-label">عنوان درس <span class="text-danger">*</span></label>
|
||||
<input type="text" name="title" class="form-control" value="{{ old('title') }}" placeholder="مثال: حقوق مدنی" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success w-100">ثبت درس</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- List of Subjects -->
|
||||
<div class="col-lg-8">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title mb-4">دروس ثبت شده</h5>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>عنوان درس</th>
|
||||
<th>تعداد سوالات مرتبط</th>
|
||||
<th>عملیات</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse($subjects as $subject)
|
||||
<tr>
|
||||
<td><strong>{{ $subject->title }}</strong></td>
|
||||
<td>
|
||||
<span class="badge bg-soft-info text-info">{{ $subject->questions_count }} سوال</span>
|
||||
</td>
|
||||
<td>
|
||||
<form action="{{ route('quiz-subjects.destroy', $subject->id) }}" method="POST" class="d-inline" onsubmit="return confirm('آیا از حذف این درس اطمینان دارید؟')">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button class="btn btn-sm btn-outline-danger">حذف</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="3" class="text-center py-3">هیچ درسی یافت نشد.</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -1,17 +1,29 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="card">
|
||||
<div class="card">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h5 class="mb-0 text-white">تعریف آزمون جدید</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<!-- Display Validation Errors if any -->
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form action="{{ route('quizzes.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">عنوان آزمون <span class="text-danger">*</span></label>
|
||||
<input type="text" name="title" class="form-control" placeholder="مثلاً: آزمون وکالت کانون وکلا سال ۱۴۰۲" required>
|
||||
<input type="text" name="title" class="form-control" value="{{ old('title') }}" placeholder="مثلاً: آزمون وکالت کانون وکلا سال ۱۴۰۲" required>
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
@@ -19,52 +31,54 @@
|
||||
<select name="category_id" class="form-select" required>
|
||||
<option value="">انتخاب کنید...</option>
|
||||
@foreach($categories as $category)
|
||||
<option value="{{ $category->id }}">{{ $category->title }}</option>
|
||||
<option value="{{ $category->id }}" {{ old('category_id') == $category->id ? 'selected' : '' }}>
|
||||
{{ $category->title }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">سال برگزاری</label>
|
||||
<input type="number" name="year" class="form-control" placeholder="1402">
|
||||
<input type="number" name="year" class="form-control" value="{{ old('year') }}" placeholder="1402">
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">نوع سوالات <span class="text-danger">*</span></label>
|
||||
<select name="type" class="form-select" required>
|
||||
<option value="multiple_choice">چهار گزینهای (تستی)</option>
|
||||
<option value="descriptive">تشریحی</option>
|
||||
<option value="mixed">ترکیبی</option>
|
||||
<option value="multiple_choice" {{ old('type') == 'multiple_choice' ? 'selected' : '' }}>چهار گزینهای (تستی)</option>
|
||||
<option value="descriptive" {{ old('type') == 'descriptive' ? 'selected' : '' }}>تشریحی</option>
|
||||
<option value="mixed" {{ old('type') == 'mixed' ? 'selected' : '' }}>ترکیبی</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<label class="form-label">مدت زمان (دقیقه)</label>
|
||||
<input type="number" name="duration_minutes" class="form-control" value="60" required>
|
||||
<input type="number" name="duration_minutes" class="form-control" value="{{ old('duration_minutes', 60) }}" required>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<label class="form-label">توضیحات آزمون</label>
|
||||
<textarea name="description" class="form-control" rows="3" placeholder="توضیحات و راهنمای شرکت در آزمون..."></textarea>
|
||||
<textarea name="description" class="form-control" rows="3" placeholder="توضیحات و راهنمای شرکت در آزمون...">{{ old('description') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="form-check mt-3">
|
||||
<input class="form-check-input" type="checkbox" name="has_negative_score" id="negScore" checked>
|
||||
<input class="form-check-input" type="checkbox" name="has_negative_score" id="negScore" {{ old('has_negative_score', true) ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="negScore">محاسبه نمره منفی (برای تستی)</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="form-check mt-3">
|
||||
<input class="form-check-input" type="checkbox" name="is_free" id="isFree">
|
||||
<input class="form-check-input" type="checkbox" name="is_free" id="isFree" {{ old('is_free') ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="isFree">آزمون رایگان است (بدون نیاز به اشتراک)</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="form-check mt-3">
|
||||
<input class="form-check-input" type="checkbox" name="is_published" id="isPub" checked>
|
||||
<input class="form-check-input" type="checkbox" name="is_published" id="isPub" {{ old('is_published', true) ? 'checked' : '' }}>
|
||||
<label class="form-check-label" for="isPub">انتشار فوری روی اپلیکیشن</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -76,5 +90,5 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -1,12 +1,12 @@
|
||||
@extends('admin.layouts.app')
|
||||
|
||||
@section('content')
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h4>مدیریت سوالات: {{ $quiz->title }}</h4>
|
||||
<a href="{{ route('quizzes.index') }}" class="btn btn-outline-secondary">بازگشت به لیست آزمونها</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="row">
|
||||
<!-- Form to Add Question -->
|
||||
<div class="col-lg-5">
|
||||
<div class="card">
|
||||
@@ -14,14 +14,26 @@
|
||||
<h6 class="mb-0 text-white">افزودن سوال جدید</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
||||
<!-- 🚨 Display Validation Errors Here 🚨 -->
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form action="{{ route('quizzes.questions.store', $quiz->id) }}" method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">نوع سوال</label>
|
||||
<select name="type" id="questionTypeSelect" class="form-select" onchange="toggleOptionFields(this.value)">
|
||||
<option value="multiple_choice">چهار گزینهای (تستی)</option>
|
||||
<option value="descriptive">تشریحی</option>
|
||||
<option value="multiple_choice" {{ old('type') == 'multiple_choice' ? 'selected' : '' }}>چهار گزینهای (تستی)</option>
|
||||
<option value="descriptive" {{ old('type') == 'descriptive' ? 'selected' : '' }}>تشریحی</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -30,19 +42,21 @@
|
||||
<select name="subject_id" class="form-select">
|
||||
<option value="">انتخاب درس (مثلاً: حقوق مدنی)</option>
|
||||
@foreach($subjects as $subject)
|
||||
<option value="{{ $subject->id }}">{{ $subject->title }}</option>
|
||||
<option value="{{ $subject->id }}" {{ old('subject_id') == $subject->id ? 'selected' : '' }}>
|
||||
{{ $subject->title }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">متن سوال / مسئله حقوقی <span class="text-danger">*</span></label>
|
||||
<textarea name="question_text" class="form-control" rows="4" required placeholder="صورت سوال یا مسئله حقوقی را وارد کنید..."></textarea>
|
||||
<textarea name="question_text" class="form-control" rows="4" required placeholder="صورت سوال یا مسئله حقوقی را وارد کنید...">{{ old('question_text') }}</textarea>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">بارم / ضریب سوال</label>
|
||||
<input type="number" step="0.25" name="score" class="form-control" value="1.00" required>
|
||||
<input type="number" step="0.25" name="score" class="form-control" value="{{ old('score', '1.00') }}" required>
|
||||
</div>
|
||||
|
||||
<!-- Multiple Choice Options Box -->
|
||||
@@ -51,9 +65,11 @@
|
||||
@for($i = 0; $i < 4; $i++)
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-text">
|
||||
<input class="form-check-input mt-0" type="radio" name="correct_option" value="{{ $i }}" {{ $i == 0 ? 'checked' : '' }}>
|
||||
<!-- Keep the correct radio button checked -->
|
||||
<input class="form-check-input mt-0" type="radio" name="correct_option" value="{{ $i }}" {{ old('correct_option', 0) == $i ? 'checked' : '' }}>
|
||||
</div>
|
||||
<input type="text" name="options[]" class="form-control" placeholder="متن گزینه {{ $i + 1 }}">
|
||||
<!-- Keep the typed option text -->
|
||||
<input type="text" name="options[]" class="form-control" value="{{ old('options.'.$i) }}" placeholder="متن گزینه {{ $i + 1 }}">
|
||||
</div>
|
||||
@endfor
|
||||
<small class="text-muted d-block mb-3">دکمه رادیویی کنار هر گزینه نشاندهنده گزینه صحیح است.</small>
|
||||
@@ -61,7 +77,7 @@
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">پاسخ تشریحی و مستندات مواد قانونی</label>
|
||||
<textarea name="solution_explanation" class="form-control" rows="3" placeholder="توضیح پاسخ، استدلال و مواد قانونی مربوطه..."></textarea>
|
||||
<textarea name="solution_explanation" class="form-control" rows="3" placeholder="توضیح پاسخ، استدلال و مواد قانونی مربوطه...">{{ old('solution_explanation') }}</textarea>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-success w-100">افزودن سوال</button>
|
||||
@@ -125,9 +141,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('scripts')
|
||||
<script>
|
||||
// Run this immediately on page load to check if we should hide options
|
||||
// in case the page reloads with old('type') set to 'descriptive'
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
var typeSelect = document.getElementById('questionTypeSelect');
|
||||
toggleOptionFields(typeSelect.value);
|
||||
});
|
||||
|
||||
<script>
|
||||
function toggleOptionFields(type) {
|
||||
const container = document.getElementById('optionsContainer');
|
||||
if (type === 'descriptive') {
|
||||
@@ -136,5 +161,5 @@
|
||||
container.style.display = 'block';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
@endsection
|
||||
@@ -33,6 +33,7 @@ use App\Http\Controllers\Admin\TicketController;
|
||||
use App\Http\Controllers\Admin\DashboardController;
|
||||
use App\Http\Controllers\Admin\QuizController;
|
||||
use App\Http\Controllers\Admin\QuizCategoryController;
|
||||
use App\Http\Controllers\Admin\QuizSubjectController;
|
||||
|
||||
Route::get('payment/callback', [PayController::class, 'callback']);
|
||||
|
||||
@@ -78,5 +79,7 @@ Route::middleware(['auth', config('jetstream.auth_session')])->group(function ()
|
||||
Route::delete('questions/{question}', [QuizController::class, 'destroyQuestion'])->name('questions.destroy');
|
||||
Route::resource('quiz-categories', QuizCategoryController::class)->except(['create', 'show', 'edit', 'update']);
|
||||
|
||||
Route::resource('quiz-subjects', QuizSubjectController::class)->except(['create', 'show', 'edit', 'update']);
|
||||
|
||||
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user