Fixed api issue
This commit is contained in:
@@ -302,39 +302,39 @@ class BylawApiController extends Controller
|
|||||||
return $this->success($results, 'Success', 'Pager Window Details');
|
return $this->success($results, 'Success', 'Pager Window Details');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isLockedForCurrentUser($item): bool
|
||||||
|
{
|
||||||
|
if (auth()->check() && auth()->user() && method_exists(auth()->user(), 'isSubscriber')) {
|
||||||
|
return !auth()->user()->isSubscriber() && (bool) ($item->is_locked ?? false);
|
||||||
|
}
|
||||||
|
return (bool) ($item->is_locked ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* COMPLETELY REWRITTEN - BULLETPROOF DIRECT QUERY
|
* اجرای مستقیم SQL برای دور زدن باگهای فیلتر و مدل در لاراول
|
||||||
*/
|
*/
|
||||||
private function formatBylaw($item)
|
private function formatBylaw($item)
|
||||||
{
|
{
|
||||||
// 1. Direct, undeniable raw query to the database for this specific document's nodes
|
$isLocked = $this->isLockedForCurrentUser($item);
|
||||||
$nodes = DB::table('bylaw_nodes')
|
|
||||||
->where('document_id', $item->id)
|
// واکشی خام با دستور استاندارد SQL (کاملاً تضمینی)
|
||||||
->orderBy('sort_order', 'asc')
|
$rawNodes = DB::select("SELECT node_content FROM bylaw_nodes WHERE document_id = ? ORDER BY sort_order ASC", [$item->id]);
|
||||||
->get();
|
|
||||||
|
|
||||||
$extractedTexts = [];
|
$extractedTexts = [];
|
||||||
foreach ($nodes as $node) {
|
foreach ($rawNodes as $node) {
|
||||||
$text = trim((string) $node->node_content);
|
// حذف فضاهای خالی اضافی بدون حذف محتوای اصلی
|
||||||
if (!empty($text)) {
|
$text = trim($node->node_content);
|
||||||
|
if ($text !== '' && $text !== null) {
|
||||||
$extractedTexts[] = $text;
|
$extractedTexts[] = $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Combine all node_content into the final string
|
// چسباندن تمام تکه متنها به یکدیگر
|
||||||
$nodeContentAsDescription = implode("\n\n", $extractedTexts);
|
$finalNodeContent = implode("\n\n", $extractedTexts);
|
||||||
|
|
||||||
// 3. Fallback ONLY if the database row is literally missing nodes
|
// بکآپ نهایی (اگر به طرز عجیبی واقعاً دیتابیس برای این آیدی هیچ پاسخی نداد)
|
||||||
if (empty($nodeContentAsDescription)) {
|
if (empty($finalNodeContent)) {
|
||||||
$nodeContentAsDescription = $item->description;
|
$finalNodeContent = $item->description;
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Safe Lock Check (prevents "call to member function on null" if user isn't logged in)
|
|
||||||
$isLocked = false;
|
|
||||||
if (auth()->check() && auth()->user() && method_exists(auth()->user(), 'isSubscriber')) {
|
|
||||||
$isLocked = !auth()->user()->isSubscriber() && (bool) ($item->is_locked ?? false);
|
|
||||||
} else {
|
|
||||||
$isLocked = (bool) ($item->is_locked ?? false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -355,7 +355,10 @@ class BylawApiController extends Controller
|
|||||||
'bylaw_type' => $item->bylaw_type,
|
'bylaw_type' => $item->bylaw_type,
|
||||||
'global_status' => $item->global_status,
|
'global_status' => $item->global_status,
|
||||||
'pdf_file_url' => $isLocked ? null : ($item->pdf_file_path ? asset('storage/' . $item->pdf_file_path) : null),
|
'pdf_file_url' => $isLocked ? null : ($item->pdf_file_path ? asset('storage/' . $item->pdf_file_path) : null),
|
||||||
'description' => $isLocked ? null : $nodeContentAsDescription, // DIRECT NODE_CONTENT HERE
|
|
||||||
|
// نتیجه استخراج مستقیم SQL در این متغیر قرار گرفته است:
|
||||||
|
'description' => $isLocked ? null : $finalNodeContent,
|
||||||
|
|
||||||
'is_locked' => $isLocked,
|
'is_locked' => $isLocked,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user