updated apis
This commit is contained in:
@@ -79,7 +79,6 @@ class BylawApiController extends Controller
|
||||
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
|
||||
$paginator = $query->paginate($perPage);
|
||||
|
||||
// واکشی دستهجمعی و ایمنِ گرهها با استفاده از Eloquent
|
||||
$docIds = collect($paginator->items())->pluck('id')->map(fn($id) => (int)$id)->toArray();
|
||||
$nodesByDoc = collect();
|
||||
|
||||
@@ -121,6 +120,12 @@ class BylawApiController extends Controller
|
||||
|
||||
$formatted = $this->formatBylaw($bylaw);
|
||||
|
||||
// --- FETCH NOTE EXACTLY LIKE ART CONTROLLER ---
|
||||
$formatted['note'] = \App\Models\BylawNote::select('id', 'note', 'color_code', 'created_at')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('bylaw_document_id', $bylaw->id)
|
||||
->get();
|
||||
|
||||
if (!$formatted['is_locked']) {
|
||||
$eloquentNodes = BylawNode::with('type')
|
||||
->where('document_id', $bylaw->id)
|
||||
@@ -340,7 +345,15 @@ class BylawApiController extends Controller
|
||||
|
||||
$results = collect($itemsToFormat)->map(function($item) use ($nodesByDoc) {
|
||||
$itemNodes = $nodesByDoc->get((int)$item->id, collect());
|
||||
return $this->formatBylaw($item, $itemNodes);
|
||||
$formatted = $this->formatBylaw($item, $itemNodes);
|
||||
|
||||
// --- FETCH NOTE EXACTLY LIKE ART CONTROLLER ---
|
||||
$formatted['note'] = \App\Models\BylawNote::select('id', 'note', 'color_code', 'created_at')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->where('bylaw_document_id', $item->id)
|
||||
->get();
|
||||
|
||||
return $formatted;
|
||||
})->values()->toArray();
|
||||
|
||||
return $this->success($results, 'Success', 'Pager Window Details');
|
||||
@@ -354,22 +367,16 @@ class BylawApiController extends Controller
|
||||
return (bool) ($item->is_locked ?? false);
|
||||
}
|
||||
|
||||
/**
|
||||
* متد قدرتمند برای استخراج ایمن متون
|
||||
*/
|
||||
private function formatBylaw($item, $itemNodes = null)
|
||||
{
|
||||
$isLocked = $this->isLockedForCurrentUser($item);
|
||||
|
||||
// واکشی در صورت خالی بودن کالکشن
|
||||
if ($itemNodes === null) {
|
||||
$itemNodes = BylawNode::where('document_id', $item->id)->orderBy('sort_order', 'asc')->get();
|
||||
}
|
||||
|
||||
// استخراج محتوا و تبدیل امنِ Encoding (ضد باگِ JSON Encode لاراول)
|
||||
$nodeContentAsDescription = $itemNodes->pluck('node_content')
|
||||
$nodeContentAsDescription = collect($itemNodes)->pluck('node_content')
|
||||
->map(function ($text) {
|
||||
// اطمینان از حذف فاصلهها و اعمال انکودینگ استاندارد برای جلوگیری از باگهای نامرئی
|
||||
$safeText = trim((string)$text);
|
||||
return mb_convert_encoding($safeText, 'UTF-8', 'UTF-8');
|
||||
})
|
||||
@@ -378,7 +385,6 @@ class BylawApiController extends Controller
|
||||
})
|
||||
->implode("\n\n");
|
||||
|
||||
// اگر همچنان خالی ماند (فقط در صورتی که دیتابیس واقعاً رکورد نداشته باشد)
|
||||
if (empty($nodeContentAsDescription)) {
|
||||
$nodeContentAsDescription = mb_convert_encoding(trim((string)$item->description), 'UTF-8', 'UTF-8');
|
||||
}
|
||||
@@ -401,13 +407,8 @@ class BylawApiController extends Controller
|
||||
'bylaw_type' => $item->bylaw_type,
|
||||
'global_status' => $item->global_status,
|
||||
'pdf_file_url' => $isLocked ? null : ($item->pdf_file_path ? asset('storage/' . $item->pdf_file_path) : null),
|
||||
|
||||
// نتیجه استخراج ۱۰۰٪ در اینجا مینشیند
|
||||
'description' => $isLocked ? null : $nodeContentAsDescription,
|
||||
|
||||
// 🚨 پارامتر عیبیابی: این عدد نشان میدهد چند گره متصل به این فایل در دیتابیس پیدا شد
|
||||
'debug_node_count' => $itemNodes->count(),
|
||||
|
||||
'debug_node_count' => collect($itemNodes)->count(),
|
||||
'is_locked' => $isLocked,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user