prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
4 changed files with 220 additions and 90 deletions
Showing only changes of commit 86597ad075 - Show all commits

View File

@ -110,6 +110,7 @@ class DirectionController extends Controller
$magistracy = $direction $magistracy = $direction
->entranceExaminations ->entranceExaminations
->where('examination_type_id', '=', '3') ->where('examination_type_id', '=', '3')
->sortBy('position')
->pluck('scores', 'subject_id'); ->pluck('scores', 'subject_id');
return view( return view(
@ -152,7 +153,6 @@ class DirectionController extends Controller
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
{ {
$validated = $request->validated(); $validated = $request->validated();
$direction->name = $validated['name']; $direction->name = $validated['name'];
$direction->full_name = "{$validated['code']} {$validated['name']}"; $direction->full_name = "{$validated['code']} {$validated['name']}";
$direction->description = $validated['description']; $direction->description = $validated['description'];
@ -162,8 +162,39 @@ class DirectionController extends Controller
$direction->education_level_id = $validated['education_level_id']; $direction->education_level_id = $validated['education_level_id'];
$direction->education_form_id = $validated['education_form_id']; $direction->education_form_id = $validated['education_form_id'];
$direction->department_id = $validated['department_id']; $direction->department_id = $validated['department_id'];
$direction->budget_places = $validated['budget_places'];
$direction->quota = $validated['quota'];
$direction->paid_places = $validated['paid_places'];
$direction->cost_paid_place = $validated['cost_paid_place'];
$direction->period = $validated['period'];
$direction->save(); $direction->save();
if (array_key_exists('entrance-examination', $validated)) {
foreach ($validated['entrance-examination'] as $id => $data) {
$entranceExamination = EntranceExamination::firstOrNew(['id' => $id]);
$entranceExamination->direction_id = $direction->id;
$entranceExamination->subject_id = $data['subject_id'];
$entranceExamination->scores = $data['scores'];
$entranceExamination->position = $data['position'];
$entranceExamination->subject_type_id = $data['subject_type_id'];
$entranceExamination->examination_type_id = $data['examination_type_id'];
$entranceExamination->save();
}
}
// dd($validated);
if (array_key_exists('delete', $validated)) {
foreach ($validated['delete'] as $id => $value) {
$entranceExamination = EntranceExamination::firstOrNew(['id' => $id]);
$entranceExamination->delete();
}
}
if (array_key_exists('direction_profiles', $validated)) {
$direction->directionProfiles()->sync($validated['direction_profiles']);
}
return redirect()->route('directions.index'); return redirect()->route('directions.index');
} }

View File

@ -15,24 +15,26 @@ class UpdateDirectionRequest extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ return [
'position' => 'required||numeric|int|max:255', 'position' => 'required|int|numeric|max:255',
'description' => 'string',
'department_id' => 'int|required|numeric|max:1000',
'slug' => [
'required',
'string',
'max:255',
"unique:directions,slug,{$this->direction->id}",
],
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'description' => 'string',
'slug' => "required|string|max:255|unique:directions,slug,{$this->direction->id}",
'code' => "required|string|max:255|unique:directions,code,{$this->direction->id}",
'education_level_id' => 'required|int|numeric|max:1000', 'education_level_id' => 'required|int|numeric|max:1000',
'education_form_id' => 'required|int|numeric|max:1000', 'education_form_id' => 'required|int|numeric|max:1000',
'code' => [ 'department_id' => 'required|numeric|int|max:1000',
'required', 'entrance-examination.*.examination_type_id' => 'required|numeric|int|max:1000',
'string', 'entrance-examination.*.subject_id' => 'required|numeric|int|max:1000',
'max:255', 'entrance-examination.*.subject_type_id' => 'required|numeric|int|max:1000',
"unique:directions,code,{$this->direction->id}", 'entrance-examination.*.scores' => 'required|numeric|int|max:1000',
], 'entrance-examination.*.position' => 'required|numeric|int|max:1000',
'budget_places' => 'required|int|numeric|max:255',
'paid_places' => 'required|int|numeric|max:255',
'quota' => 'required|int|numeric|max:255',
'cost_paid_place' => 'required|int|numeric|max:255',
'period' => 'required|string|max:255',
'direction_profiles' => 'nullable|array',
'delete.*' => 'nullable|array'
]; ];
} }
} }

View File

@ -2,7 +2,7 @@
@section('content') @section('content')
@auth() @auth()
<h1 class=""> Создать Направление</h1> <h1 class=""> Создать Направление</h1>
{{ Form::open(['url' => route('directions.store'), 'method' => 'POST', 'class' => '']) }} {{ Form::open(['url' => route('directions.update', $direction), 'method' => 'PATCH', 'class' => 'ffff']) }}
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
@ -110,7 +110,6 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
@ -197,73 +196,79 @@
</div> </div>
</div> </div>
<h4 class="mt-3">Добавить вступительные испытания</h4> <div class="d-flex mt-3">
<h4 class="mt-3 m-2 d-inline-block">Добавить вступительные испытания</h4>
<button type="button" class="btn btn-success m-2 d-inline-block btn-sm" name="add" id="add">Добавить
</button>
</div>
<div class="text-center align-items-center entrance-examination" id="entrance-examination" <div class="text-center align-items-center entrance-examination" id="entrance-examination"
name="entrance-examination"> name="entrance-examination">
<div class="row"> @foreach($direction->entranceExaminations as $entranceExamination)
<div class="row field">
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
{{ Form::label('entrance-examination[0][examination_type_id]', 'Тип экзамена') }} {{ Form::label("entrance-examination[{$entranceExamination->id}][examination_type_id]", 'Тип экзамена') }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::select('entrance-examination[0][examination_type_id]', $examination_types, null, ['class' => 'form-select']) }} {{ Form::select("entrance-examination[{$entranceExamination->id}][examination_type_id]", $examination_types, $entranceExamination->examinationType->id, ['class' => 'form-select']) }}
</div> </div>
<div> <div>
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('entrance-examination[0][examination_type_id]') }} {{ $errors->first("entrance-examination[{$entranceExamination->id}][examination_type_id]") }}
@endif @endif
</div> </div>
</div> </div>
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
{{ Form::label('entrance-examination[0][subject_id]', 'Предмет') }} {{ Form::label("entrance-examination[{$entranceExamination->id}][subject_id]", 'Предмет') }}
</div> </div>
<div class="mt-1 col"> <div class="mt-1 col">
{{ Form::select('entrance-examination[0][subject_id]', $subjects, null, ['class' => 'form-select']) }} {{ Form::select("entrance-examination[{$entranceExamination->id}][subject_id]", $subjects, $entranceExamination->subject->id, ['class' => 'form-select']) }}
</div> </div>
<div> <div>
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('entrance-examination[0][subject_id]') }} {{ $errors->first("entrance-examination[{$entranceExamination->id}][subject_id]") }}
@endif @endif
</div> </div>
</div> </div>
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
{{ Form::label('entrance-examination[0][subject_type_id]', 'Тип предмета') }} {{ Form::label("entrance-examination[{$entranceExamination->id}][subject_type_id]", 'Тип предмета') }}
</div> </div>
<div class="mt-1 col"> <div class="mt-1 col">
{{ Form::select('entrance-examination[0][subject_type_id]', $subjectTypes, null, ['class' => 'form-select']) }} {{ Form::select("entrance-examination[{$entranceExamination->id}][subject_type_id]", $subjectTypes, $entranceExamination->subjectType->id, ['class' => 'form-select']) }}
</div> </div>
<div> <div>
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('entrance-examination[0][subject_type_id]') }} {{ $errors->first("entrance-examination[{$entranceExamination->id}][subject_type_id]") }}
@endif @endif
</div> </div>
</div> </div>
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
{{ Form::label('entrance-examination[0][scores]', 'Кол-во баллов') }} {{ Form::label("entrance-examination[{$entranceExamination->id}][scores]", 'Кол-во баллов') }}
</div> </div>
<div class="mt-1 col"> <div class="mt-1 col">
{{ Form::text('entrance-examination[0][scores]', '', ['class' => 'form-control']) }} {{ Form::text("entrance-examination[{$entranceExamination->id}][scores]", $entranceExamination->scores, ['class' => 'form-control']) }}
</div> </div>
<div> <div>
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('entrance-examination[0][scores]') }} {{ $errors->first("entrance-examination[{$entranceExamination->id}][scores]") }}
@endif @endif
</div> </div>
</div> </div>
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
{{ Form::label('entrance-examination[0][position]', 'Позиция') }} {{ Form::label("entrance-examination[{$entranceExamination->id}][position]", 'Позиция') }}
</div> </div>
<div class="mt-1 col"> <div class="mt-1 col">
{{ Form::text('entrance-examination[0][position]', '', ['class' => 'form-control']) }} {{ Form::text("entrance-examination[{$entranceExamination->id}][position]", $entranceExamination->position, ['class' => 'form-control']) }}
</div> </div>
<div> <div>
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('entrance-examination[0][position]') }} {{ $errors->first("entrance-examination[{$entranceExamination->id}][position]") }}
@endif @endif
</div> </div>
</div> </div>
@ -271,17 +276,20 @@
<div class="mt-3"> <div class="mt-3">
{{ Form::label('btn', 'Действия') }} {{ Form::label('btn', 'Действия') }}
</div> </div>
<button type="button" class="btn btn-success col" name="add" id="add">Добавить</button> <button type="button" class="btn btn-danger col remove-examination-row"
</div> data-id="{{$entranceExamination->id}}">Удалить
</button>
</div> </div>
</div> </div>
@endforeach
</div>
<div class="mt-3 mb-3"> <div class="mt-3 mb-3">
{{ Form::submit('Изменить Направление', ['class' => 'btn btn-primary']) }} {{ Form::submit('Изменить Направление', ['class' => 'btn btn-primary']) }}
</div> </div>
{{ Form::close() }} {{ Form::close() }}
</div> </div>
@include('admin.catalog.direction.script') @include('admin.catalog.direction.edit_script')
@endauth @endauth
@endsection @endsection

View File

@ -0,0 +1,89 @@
<script type="module">
let i = 0;
$('#add').click(function () {
--i;
$('#entrance-examination').append(
`<div class="row field">
<div class="col">
<div class="mt-3">
<label for="entrance-examination[${i}][examination_type_id]">Тип экзамена</label>
</div>
<div class="mt-1">
<select class="form-select" id="entrance-examination[${i}][examination_type_id]"
name="entrance-examination[${i}][examination_type_id]">
@foreach($examination_types as $value => $type)
<option value="{{ $value }}">{{ $type }}</option>
@endforeach
</select>
</div>
<div>
</div>
</div>
<div class="col">
<div class="mt-3">
<label for="entrance-examination[${i}][subject_id]">Предмет</label>
</div>
<div class="mt-1 col">
<select class="form-select" id="entrance-examination[${i}][subject_id]"
name="entrance-examination[${i}][subject_id]">
@foreach($subjects as $value => $subject)
<option value="{{ $value }}">{{ $subject }}</option>
@endforeach
</select>
</div>
<div>
</div>
</div>
<div class="col">
<div class="mt-3">
<label for="entrance-examination[${i}][subject_type_id]">Тип предмета</label>
</div>
<div class="mt-1 col">
<select class="form-select" id="entrance-examination[${i}][subject_type_id]"
name="entrance-examination[${i}][subject_type_id]">
@foreach($subjectTypes as $value => $subjectType)
<option value="{{ $value }}">{{ $subjectType }}</option>
@endforeach
</select>
</div>
<div>
</div>
</div>
<div class="col">
<div class="mt-3">
<label for="entrance-examination[${i}][scores]">Кол-во баллов</label>
</div>
<div class="mt-1 col">
<input class="form-control" name="entrance-examination[${i}][scores]" type="text" value=""
id="entrance-examination[${i}][scores]">
</div>
<div>
</div>
</div>
<div class="col">
<div class="mt-3">
<label for="entrance-examination[${i}][position]">Позиция</label>
</div>
<div class="mt-1 col">
<input class="form-control" name="entrance-examination[${i}][position]" type="text" value=""
id="entrance-examination[${i}][position]">
</div>
<div>
</div>
</div>
<div class="col align-items-end">
<div class="mt-3">
<label for="btn">Действия</label>
</div>
<button type="button" class="btn btn-danger col remove-examination-row" data-id="${i}">Удалить</button>
</div>
</div>`
);
});
$(document).on('click', '.remove-examination-row', function () {
let id=$(this).data('id');
console.log(id);
$('.ffff').append('<input type="hidden" name="delete['+id+']">')
$(this).parents('.field').remove();
});
</script>