prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
18 changed files with 685 additions and 2 deletions
Showing only changes of commit 566087919b - Show all commits

View File

@ -0,0 +1,105 @@
<?php
namespace App\Http\Controllers\admin\Catalog\Direction;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\Direction\StoreEntranceExaminationRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateEntranceExaminationRequest;
use App\Models\Direction;
use App\Models\EntranceExamination;
use App\Models\ExaminationType;
use App\Models\Subject;
use App\Models\SubjectType;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
class EntranceExaminationController extends Controller
{
public function index(): View
{
$entranceExaminations = EntranceExamination::all();
return view('admin.catalog.direction.entrance_examination.index', compact('entranceExaminations'));
}
public function create(): View
{
$directions = Direction::pluck('name', 'id');
$examination_types = ExaminationType::pluck('name', 'id');
$subjects = Subject::pluck('name', 'id');
$subjectTypes = SubjectType::pluck('name', 'id');
return view(
'admin.catalog.direction.entrance_examination.create',
compact(
'directions',
'examination_types',
'subjects',
'subjectTypes',
)
);
}
public function store(StoreEntranceExaminationRequest $request): RedirectResponse
{
$validated = $request->validated();
$entranceExamination = new EntranceExamination();
$entranceExamination->examination_type_id = $validated['examination_type_id'];
$entranceExamination->direction_id = $validated['direction_id'];
$entranceExamination->subject_id = $validated['subject_id'];
$entranceExamination->scores = $validated['scores'];
$entranceExamination->position = $validated['position'];
$entranceExamination->subject_type_id = $validated['subject_type_id'];
$entranceExamination->save();
return redirect()->route('entrance_examinations.index');
}
public function show(EntranceExamination $entranceExamination): View
{
return view(
'admin.catalog.direction.entrance_examination.show',
compact('entranceExamination')
);
}
public function edit(EntranceExamination $entranceExamination): View
{
$directions = Direction::pluck('name', 'id');
$examination_types = ExaminationType::pluck('name', 'id');
$subjects = Subject::pluck('name', 'id');
$subjectTypes = SubjectType::pluck('name', 'id');
return view(
'admin.catalog.direction.entrance_examination.edit',
compact(
'entranceExamination',
'directions',
'examination_types',
'subjects',
'subjectTypes',
)
);
}
public function update(
UpdateEntranceExaminationRequest $request,
EntranceExamination $entranceExamination
): RedirectResponse {
$validated = $request->validated();
$entranceExamination->examination_type_id = $validated['examination_type_id'];
$entranceExamination->direction_id = $validated['direction_id'];
$entranceExamination->subject_id = $validated['subject_id'];
$entranceExamination->scores = $validated['scores'];
$entranceExamination->position = $validated['position'];
$entranceExamination->subject_type_id = $validated['subject_type_id'];
$entranceExamination->save();
return redirect()->route('entrance_examinations.index');
}
public function destroy(EntranceExamination $entranceExamination): RedirectResponse
{
$entranceExamination->delete();
return redirect()->route('entrance_examinations.index');
}
}

View File

@ -93,6 +93,9 @@ class DirectionController extends Controller
public function destroy(Direction $direction): RedirectResponse
{
if ($direction->entranceExaminations()->exists()) {
return back();
}
$direction->delete();
return redirect()->route('directions.index');
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Http\Requests\admin\Catalog\Direction;
use Illuminate\Foundation\Http\FormRequest;
class StoreEntranceExaminationRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
return [
'direction_id' => 'required|numeric|int|max:1000',
'examination_type_id' => 'required|numeric|int|max:1000',
'subject_id' => 'required|numeric|int|max:1000',
'subject_type_id' => 'required|numeric|int|max:1000',
'scores' => 'required|numeric|int|max:1000',
'position' => 'required|numeric|int|max:1000',
];
}
}

View File

@ -8,13 +8,18 @@ class UpdateEntranceExaminationRequest extends FormRequest
{
public function authorize(): bool
{
return false;
return true;
}
public function rules(): array
{
return [
'direction_id' => 'required|numeric|int|max:1000',
'examination_type_id' => 'required|numeric|int|max:1000',
'subject_id' => 'required|numeric|int|max:1000',
'subject_type_id' => 'required|numeric|int|max:1000',
'scores' => 'required|numeric|int|max:1000',
'position' => 'required|numeric|int|max:1000',
];
}
}

View File

@ -5,6 +5,7 @@ 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;
class Direction extends Model
{
@ -33,4 +34,9 @@ class Direction extends Model
{
return $this->belongsTo(EducationForm::class);
}
public function entranceExaminations(): HasMany
{
return $this->hasMany('App\Models\EntranceExamination', 'direction_id');
}
}

View File

@ -0,0 +1,42 @@
<?php
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;
class EntranceExamination extends Model
{
use HasFactory;
protected $fillable = [
'direction_id',
'examination_type_id',
'subject_id',
'subject_type_id',
'scores',
'position',
];
public function examinationType(): BelongsTo
{
return $this->belongsTo(ExaminationType::class);
}
public function direction(): BelongsTo
{
return $this->belongsTo(Direction::class);
}
public function subject(): BelongsTo
{
return $this->belongsTo(Subject::class);
}
public function subjectType(): BelongsTo
{
return $this->belongsTo(SubjectType::class);
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class EntranceExaminationFactory extends Factory
{
public function definition(): array
{
return [
'examination_type_id' => 1,
'direction_id' => 1,
'subject_id' => 1,
'scores' => 45,
'position' => fake()->randomDigit(),
'subject_type_id' => 1,
];
}
}

View File

@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('entrance_examinations', function (Blueprint $table) {
$table->id();
$table->foreignId('examination_type_id')->constrained('examination_types');
$table->foreignId('direction_id')->constrained('directions');
$table->foreignId('subject_id')->constrained('subjects');
$table->integer('scores');
$table->integer('position');
$table->foreignId('subject_type_id')->constrained('subject_types');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('entrance_examinations');
}
};

View File

@ -31,6 +31,7 @@ class DatabaseSeeder extends Seeder
SubjectSeeder::class,
SubjectTypeSeeder::class,
DirectionSeeder::class,
EntranceExaminationSeeder::class,
]);
$this->call([

View File

@ -0,0 +1,40 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class EntranceExaminationSeeder extends Seeder
{
public function run(): void
{
DB::table('entrance_examinations')->insert([
[
'examination_type_id' => 1,
'direction_id' => 1,
'subject_id' => 1,
'scores' => 40,
'position' => 1,
'subject_type_id' => 1,
],
[
'examination_type_id' => 1,
'direction_id' => 1,
'subject_id' => 2,
'scores' => 45,
'position' => 2,
'subject_type_id' => 1,
],
[
'examination_type_id' => 1,
'direction_id' => 1,
'subject_id' => 3,
'scores' => 50,
'position' => 3,
'subject_type_id' => 1,
],
]);
}
}

View File

@ -0,0 +1,90 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать вступительный экзамен</h1>
{{ Form::open(['url' => route('entrance_examinations.store'), 'method' => 'POST', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('direction_id', 'Направление подготовки') }}
</div>
<div class="mt-1">
{{ Form::select('direction_id', $directions, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('direction_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('examination_type_id', 'Тип экзамена') }}
</div>
<div class="mt-1">
{{ Form::select('examination_type_id', $examination_types, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('examination_type_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('subject_id', 'Предмет') }}
</div>
<div class="mt-1">
{{ Form::select('subject_id', $subjects, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('subject_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('subject_type_id', 'Тип предмета') }}
</div>
<div class="mt-1">
{{ Form::select('subject_type_id', $subjectTypes, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('subject_type_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('scores', 'Кол-во баллов') }}
</div>
<div class="mt-1">
{{ Form::text('scores', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('scores') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,90 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class="">Изменить вступительный экзамен</h1>
{{ Form::open(['url' => route('entrance_examinations.update', $entranceExamination), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('direction_id', 'Направление подготовки') }}
</div>
<div class="mt-1">
{{ Form::select('direction_id', $directions, $entranceExamination->direction->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('direction_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('examination_type_id', 'Тип экзамена') }}
</div>
<div class="mt-1">
{{ Form::select('examination_type_id', $examination_types, $entranceExamination->examinationType->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('examination_type_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('subject_id', 'Предмет') }}
</div>
<div class="mt-1">
{{ Form::select('subject_id', $subjects, $entranceExamination->subject->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('subject_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('subject_type_id', 'Тип предмета') }}
</div>
<div class="mt-1">
{{ Form::select('subject_type_id', $subjectTypes, $entranceExamination->subjectType->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('subject_type_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('scores', 'Кол-во баллов') }}
</div>
<div class="mt-1">
{{ Form::text('scores', $entranceExamination->scores, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('scores') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $entranceExamination->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,47 @@
@extends('layouts.admin_layout')
@section('content')
<div class="container">
<h2>Вступительные экзамены</h2>
<br>
<a href="{{ route('entrance_examinations.create') }}" class="btn btn-primary">Создать вступительный экзамен</a>
<br>
<br>
<table class="table">
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
<tr>
<th scope="col">Направление подготовки</th>
<th scope="col">Тип экзамена</th>
<th scope="col">Предмет</th>
<th scope="col">Тип предмета</th>
<th scope="col">Кол-во баллов</th>
<th scope="col">Позиция</th>
<th scope="col">действия</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach($entranceExaminations as $entranceExamination)
<tr class="">
<td><a href="{{ route('directions.show', $entranceExamination->direction) }}">{{ $entranceExamination->direction->name }}</a></td>
<td><a href="{{ route('examination_types.show', $entranceExamination->examinationType) }}">{{ $entranceExamination->examinationType->name }}</a></td>
<td><a href="{{ route('subjects.show', $entranceExamination->subject) }}">{{ $entranceExamination->subject->name }}</a></td>
<td><a href="{{ route('subject_types.show', $entranceExamination->subjectType) }}">{{ $entranceExamination->subjectType->name }}</a></td>
<td>{{ $entranceExamination->scores }}</td>
<td>{{ $entranceExamination->position }}</td>
<td>
<a href="{{ route("entrance_examinations.show", $entranceExamination) }}"
class="btn btn-info">посмотреть</a>
<a href="{{ route("entrance_examinations.edit", $entranceExamination) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('entrance_examinations.destroy', $entranceExamination) }}"
class="btn btn-danger">удалить</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

@ -0,0 +1,19 @@
@extends('layouts.admin_layout')
@section('content')
@auth()
<div class="container mt-4">
<h2>Направление подготовки</h2>
<p>{{ $entranceExamination->direction->name }}</p>
<h2>Тип экзамена</h2>
<p>{{ $entranceExamination->examinationType->name }}</p>
<h2>Предмет</h2>
<p>{{ $entranceExamination->subject->name }}</p>
<h2>Тип предмета</h2>
<p>{{ $entranceExamination->subjectType->name }}</p>
<h2>Мин. кол-во баллов</h2>
<p>{{ $entranceExamination->scores }}</p>
<h2>Позиция</h2>
<p>{{ $entranceExamination->position }}</p>
</div>
@endauth
@endsection

View File

@ -56,6 +56,7 @@
<li class="list-group-item"><a href="{{ route('faculties.index') }}">Факультеты</a></li>
<li class="list-group-item"><a href="{{ route('departments.index') }}">Кафедры</a></li>
<li class="list-group-item"><a href="{{ route('directions.index') }}">Направления</a></li>
<li class="list-group-item"><a href="{{ route('entrance_examinations.index') }}">Вступ. экзамены</a></li>
<li class="list-group-item"><a href="{{ route('education_levels.index') }}">Уровни образования</a></li>
<li class="list-group-item"><a href="{{ route('education_forms.index') }}">Формы образования</a></li>
<li class="list-group-item"><a href="{{ route('examination_types.index') }}">Типы Экзаменов</a></li>

View File

@ -4,6 +4,7 @@ use App\Http\Controllers\admin\AdmissionController;
use App\Http\Controllers\admin\Catalog\DepartmentController;
use App\Http\Controllers\admin\Catalog\Direction\EducationFormController;
use App\Http\Controllers\admin\Catalog\Direction\EducationLevelController;
use App\Http\Controllers\admin\Catalog\Direction\EntranceExaminationController;
use App\Http\Controllers\admin\Catalog\Direction\ExaminationTypeController;
use App\Http\Controllers\admin\Catalog\Direction\SubjectController;
use App\Http\Controllers\admin\Catalog\Direction\SubjectTypeController;
@ -53,6 +54,8 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
Route::resource('/subject_types', SubjectTypeController::class)
->scoped(['subject_type' => 'slug']);
Route::resource('/entrance_examinations', EntranceExaminationController::class);
Route::resources([
'/documents' => DocumentController::class,
'/users' => UserController::class,

View File

@ -7,7 +7,11 @@ use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\EntranceExamination;
use App\Models\ExaminationType;
use App\Models\Faculty;
use App\Models\Subject;
use App\Models\SubjectType;
use App\Models\User;
use Tests\TestCase;
@ -15,7 +19,9 @@ class DirectionTest extends TestCase
{
private User $user;
private Direction $direction;
private EntranceExamination $entranceExamination;
private array $data;
protected function setUp(): void
{
parent::setUp();
@ -26,6 +32,12 @@ class DirectionTest extends TestCase
EducationForm::factory()->create();
$this->direction = Direction::factory()->create();
ExaminationType::factory()->create();
Subject::factory()->create();
SubjectType::factory()->create();
$this->entranceExamination = EntranceExamination::factory()->create();
$this->data = Direction::factory()->make()->only([
'position',
'name',
@ -104,6 +116,7 @@ class DirectionTest extends TestCase
public function testDestroyDirection(): void
{
$this->entranceExamination->delete();
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('directions.destroy', $this->direction));
@ -112,4 +125,27 @@ class DirectionTest extends TestCase
$this->assertDatabaseMissing('directions', $this->direction->toArray());
}
public function testNotDestroyDirectionWithEntranceExamination(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('directions.destroy', $this->direction));
$response->assertStatus(302);
$this->assertDatabaseHas(
'directions',
$this->direction->only([
'position',
'name',
'description',
'code',
'slug',
'education_level_id',
'education_form_id',
'department_id',
])
);
}
}

View File

@ -0,0 +1,123 @@
<?php
namespace Tests\Feature\admin\catalog\direction;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\EntranceExamination;
use App\Models\ExaminationType;
use App\Models\Faculty;
use App\Models\Subject;
use App\Models\SubjectType;
use App\Models\User;
use Tests\TestCase;
class EntranceExaminationTest extends TestCase
{
private User $user;
private EntranceExamination $entranceExamination;
private array $data;
protected function setUp(): void
{
parent::setUp();
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
EducationLevel::factory()->create();
EducationForm::factory()->create();
Direction::factory()->create();
ExaminationType::factory()->create();
Subject::factory()->create();
SubjectType::factory()->create();
$this->entranceExamination = EntranceExamination::factory()->create();
$this->data = EntranceExamination::factory()->make()->only([
'direction_id',
'examination_type_id',
'subject_id',
'subject_type_id',
'scores',
'position',
]);
$this->user = User::factory()->create([
'name' => 'admin',
'email' => 'test@example.com',
'password' => 123456
]);
}
public function testIndexEntranceExaminationsPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.index'));
$response->assertOk();
}
public function testCreateEntranceExaminationPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.create'));
$response->assertOk();
}
public function testStoreEntranceExamination(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->post(route('entrance_examinations.store', $this->data));
$response->assertRedirect(route('entrance_examinations.index'));
$this->assertDatabaseHas('entrance_examinations', $this->data);
}
public function testShowEntranceExaminationPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.show', $this->entranceExamination));
$response->assertOk();
}
public function testEditEntranceExaminationPage(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->get(route('entrance_examinations.edit', $this->entranceExamination));
$response->assertOk();
}
public function testUpdateEntranceExamination(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->patch(route('entrance_examinations.update', $this->entranceExamination), $this->data);
$response->assertRedirect(route('entrance_examinations.index'));
$this->assertDatabaseHas('entrance_examinations', $this->data);
}
public function testEntranceExaminationDirection(): void
{
$response = $this->actingAs($this->user)
->withSession(['banned' => false])
->delete(route('entrance_examinations.destroy', $this->entranceExamination));
$response->assertRedirect(route('entrance_examinations.index'));
$this->assertDatabaseMissing('entrance_examinations', $this->entranceExamination->toArray());
}
}