bug fixes and new functionality
This commit is contained in:
parent
4cf46bd449
commit
f985bfedd3
@ -14,7 +14,8 @@ class Form extends Model
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
public $incrementing = false;
|
||||
protected $keyType = 'string';
|
||||
protected $appends = ['media_url'];
|
||||
|
||||
/**
|
||||
|
@ -470,29 +470,36 @@ class FormDataController extends Controller
|
||||
public function show($form_id, Request $request)
|
||||
{
|
||||
$user_id = $request->user()->id;
|
||||
|
||||
|
||||
$form = Form::findOrFail($form_id);
|
||||
$data = FormData::query()
|
||||
->where('form_id', $form_id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get()
|
||||
->filter(function (FormData $formData) use ($request) {
|
||||
$date = null;
|
||||
if (is_array($formData->data)) {
|
||||
$date = strtotime(
|
||||
array_values(
|
||||
array_filter($formData->data, fn($item) => is_string($item) && strtotime($item))
|
||||
)[0]
|
||||
);
|
||||
$dates = array_filter($formData->data, function ($item) {
|
||||
return is_string($item) && strtotime($item);
|
||||
});
|
||||
if (!empty($dates)) {
|
||||
$firstDate = reset($dates);
|
||||
$date = strtotime($firstDate);
|
||||
}
|
||||
}
|
||||
|
||||
$date = Carbon::createFromTimestamp($date)->toDateString();
|
||||
$isValidStartDate = $request->filled('start_date') ?
|
||||
$request->get('start_date') <= $date :
|
||||
Carbon::now()->subDays(7)->toDateString() <= $date;
|
||||
$isValidEndDate = $request->filled('end_date') ?
|
||||
$request->get('end_date') >= $date :
|
||||
Carbon::now()->toDateString() >= $date;
|
||||
|
||||
|
||||
if (!$date) {
|
||||
return false; // Skip entries without valid dates
|
||||
}
|
||||
|
||||
$dateStr = Carbon::createFromTimestamp($date)->toDateString();
|
||||
$isValidStartDate = $request->filled('start_date')
|
||||
? $request->get('start_date') <= $dateStr
|
||||
: Carbon::now()->subDays(7)->toDateString() <= $dateStr;
|
||||
$isValidEndDate = $request->filled('end_date')
|
||||
? $request->get('end_date') >= $dateStr
|
||||
: Carbon::now()->toDateString() >= $dateStr;
|
||||
|
||||
return $isValidStartDate && $isValidEndDate;
|
||||
});
|
||||
|
||||
@ -532,7 +539,7 @@ class FormDataController extends Controller
|
||||
}
|
||||
|
||||
return view('form_data.show')
|
||||
->with(compact('form', 'data'));
|
||||
->with(compact('form', 'data', 'has_permission')); // Добавьте has_permission
|
||||
}
|
||||
|
||||
public function viewData($id)
|
||||
|
@ -82,10 +82,8 @@
|
||||
<table class="table" id="submitted_data_table" style="width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
@if(auth()->user()->hasRole([\App\Enums\User\RoleEnum::SUPERVISOR->value, \App\Enums\User\RoleEnum::ADMIN->value], 'web'))
|
||||
<th>@lang('messages.action')</th>
|
||||
@endif
|
||||
|
||||
|
||||
@if($is_enabled_sub_ref_no)
|
||||
<th>@lang('messages.submission_numbering')</th>
|
||||
@endif
|
||||
@ -104,16 +102,19 @@
|
||||
<tbody>
|
||||
@foreach($data as $k => $row)
|
||||
<tr>
|
||||
@if(auth()->user()->hasRole([\App\Enums\User\RoleEnum::SUPERVISOR->value, \App\Enums\User\RoleEnum::ADMIN->value], 'web'))
|
||||
<td>
|
||||
@if(in_array('view', $btn_enabled))
|
||||
<button type="button" class="btn btn-info btn-sm view_form_data m-1"
|
||||
data-href="{{action([\App\Http\Controllers\FormDataController::class, 'viewData'], [$row->id])}}"
|
||||
data-toggle="modal">
|
||||
<i class="fa fa-eye" aria-hidden="true"></i>
|
||||
@lang('messages.view')
|
||||
</button>
|
||||
@endif
|
||||
<td>
|
||||
{{-- Кнопка просмотра для всех, у кого есть права --}}
|
||||
@if(in_array('view', $btn_enabled) && $has_permission)
|
||||
<button type="button" class="btn btn-info btn-sm view_form_data m-1"
|
||||
data-href="{{action([\App\Http\Controllers\FormDataController::class, 'viewData'], [$row->id])}}"
|
||||
data-toggle="modal">
|
||||
<i class="fa fa-eye" aria-hidden="true"></i>
|
||||
@lang('messages.view')
|
||||
</button>
|
||||
@endif
|
||||
|
||||
{{-- Кнопки только для админов/супервайзеров --}}
|
||||
@if(auth()->user()->hasRole([\App\Enums\User\RoleEnum::SUPERVISOR->value, \App\Enums\User\RoleEnum::ADMIN->value], 'web'))
|
||||
@if(in_array('delete', $btn_enabled))
|
||||
<button type="button"
|
||||
class="btn btn-danger btn-sm delete_form_data m-1"
|
||||
@ -122,16 +123,17 @@
|
||||
@lang('messages.delete')
|
||||
</button>
|
||||
@endif
|
||||
|
||||
@php
|
||||
$form_id = !empty($form->slug) ? $form->slug : $form->id;
|
||||
@endphp
|
||||
<a class="btn btn-dark btn-sm m-1"
|
||||
href="{{action([\App\Http\Controllers\FormDataController::class, 'getEditformData'], ['slug' => $form_id,'id' => $row->id])}}">
|
||||
href="{{action([\App\Http\Controllers\FormDataController::class, 'getEditformData'], ['slug' => $form_id,'id' => $row->id])}}">
|
||||
<i class="far fa-edit" aria-hidden="true"></i>
|
||||
@lang('messages.edit')
|
||||
</a>
|
||||
</td>
|
||||
@endif
|
||||
@endif
|
||||
</td>
|
||||
|
||||
@if($is_enabled_sub_ref_no)
|
||||
<td>
|
||||
|
Loading…
Reference in New Issue
Block a user