feat: add bylaw management features including documents, legal authorities, subject categories, and nodes
This commit is contained in:
@@ -14,7 +14,6 @@ use App\Models\Chapter;
|
||||
use App\Models\Division;
|
||||
use App\Models\Gate;
|
||||
use App\Models\Law;
|
||||
use App\Models\Order;
|
||||
use App\Models\Part;
|
||||
use App\Models\RecentArt;
|
||||
use App\Models\Section;
|
||||
@@ -35,7 +34,7 @@ class VolumController extends Controller
|
||||
|
||||
$volumes->getCollection()->transform(function ($volume) {
|
||||
$volume['has_book'] = Book::where('volum_id', $volume->id)->exists();
|
||||
$volume['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $volume['law_id'])->first()?->is_locked;
|
||||
$volume['is_locked'] = auth()->user()->isSubscriber() !== false ? false : Law::where('id', $volume['law_id'])->first()?->is_locked;
|
||||
|
||||
unset($volume['law_id']);
|
||||
|
||||
@@ -63,7 +62,7 @@ class VolumController extends Controller
|
||||
$book = Book::with(['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
|
||||
->find($bookId);
|
||||
|
||||
if (!$book) {
|
||||
if (! $book) {
|
||||
return $this->success([], 'Book not found');
|
||||
}
|
||||
|
||||
@@ -79,7 +78,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
$paginationData = [
|
||||
@@ -100,11 +99,10 @@ class VolumController extends Controller
|
||||
$division = Division::with(['sections', 'chapters', 'parts', 'gate', 'branch', 'art'])
|
||||
->find($division_id);
|
||||
|
||||
if (!$division) {
|
||||
if (! $division) {
|
||||
return $this->success([], 'Division not found');
|
||||
}
|
||||
|
||||
|
||||
$data = [];
|
||||
$foundRelation = false;
|
||||
foreach (['sections', 'chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
|
||||
@@ -117,7 +115,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -135,7 +133,7 @@ class VolumController extends Controller
|
||||
$section = Section::with(['chapters', 'parts', 'gate', 'branch', 'art'])
|
||||
->find($section_id);
|
||||
|
||||
if (!$section) {
|
||||
if (! $section) {
|
||||
return $this->success([], 'Section not found');
|
||||
}
|
||||
|
||||
@@ -151,7 +149,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -168,7 +166,7 @@ class VolumController extends Controller
|
||||
if ($volumeId) {
|
||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
|
||||
->find($volumeId);
|
||||
if (!$volume) {
|
||||
if (! $volume) {
|
||||
return $this->success([], 'Volume not found');
|
||||
}
|
||||
|
||||
@@ -184,7 +182,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -202,7 +200,7 @@ class VolumController extends Controller
|
||||
$part = Part::with(['gate', 'branch', 'art'])
|
||||
->find($part_id);
|
||||
|
||||
if (!$part) {
|
||||
if (! $part) {
|
||||
return $this->success([], 'Part not found');
|
||||
}
|
||||
|
||||
@@ -218,7 +216,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -236,7 +234,7 @@ class VolumController extends Controller
|
||||
$chapter = Chapter::with(['parts', 'gate', 'branch', 'art'])
|
||||
->find($chapter_id);
|
||||
|
||||
if (!$chapter) {
|
||||
if (! $chapter) {
|
||||
return $this->success([], 'Chapter not found');
|
||||
}
|
||||
|
||||
@@ -252,7 +250,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -270,7 +268,7 @@ class VolumController extends Controller
|
||||
$branch = Branch::with(['art'])
|
||||
->find($branch_id);
|
||||
|
||||
if (!$branch) {
|
||||
if (! $branch) {
|
||||
return $this->success([], 'Branch not found');
|
||||
}
|
||||
|
||||
@@ -286,7 +284,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -300,12 +298,11 @@ class VolumController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($gate_id) {
|
||||
$gate = Gate::with(['branch', 'art'])
|
||||
->find($gate_id);
|
||||
|
||||
if (!$gate) {
|
||||
if (! $gate) {
|
||||
return $this->success([], 'Gate not found');
|
||||
}
|
||||
|
||||
@@ -321,7 +318,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -339,7 +336,7 @@ class VolumController extends Controller
|
||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs'])
|
||||
->find($volumeId);
|
||||
|
||||
if (!$volume) {
|
||||
if (! $volume) {
|
||||
return $this->success([], 'Volume not found');
|
||||
}
|
||||
|
||||
@@ -355,7 +352,7 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => $relation,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
break;
|
||||
@@ -372,7 +369,7 @@ class VolumController extends Controller
|
||||
if ($law_Id) {
|
||||
$law = Law::find($law_Id);
|
||||
|
||||
if (!$law) {
|
||||
if (! $law) {
|
||||
return $this->success([], 'Law not found');
|
||||
}
|
||||
|
||||
@@ -380,16 +377,14 @@ class VolumController extends Controller
|
||||
->where('law_id', $law->id)
|
||||
->get();
|
||||
|
||||
|
||||
RecentArt::query()->updateOrCreate([
|
||||
'user_id' => auth()->user()->id,
|
||||
'law_id' => $law_Id
|
||||
'law_id' => $law_Id,
|
||||
], [
|
||||
'user_id' => auth()->user()->id,
|
||||
'law_id' => $law_Id
|
||||
'law_id' => $law_Id,
|
||||
]);
|
||||
|
||||
|
||||
$data = [];
|
||||
|
||||
if (count($arts) > 0) {
|
||||
@@ -399,9 +394,10 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => 'volume',
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success($data, 'Success');
|
||||
}
|
||||
|
||||
@@ -423,9 +419,10 @@ class VolumController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => 'art',
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $law->id)->first()?->is_locked,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->success($data, 'Success');
|
||||
}
|
||||
|
||||
@@ -504,8 +501,8 @@ class VolumController extends Controller
|
||||
'foreign_key' => 'branch_id',
|
||||
'type' => (new Art)->getTable(),
|
||||
'check_mode' => Art::class,
|
||||
'check_key' => 'branch_id'
|
||||
]
|
||||
'check_key' => 'branch_id',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($filters as $filterKey => $filterInfo) {
|
||||
@@ -533,7 +530,7 @@ class VolumController extends Controller
|
||||
'title' => $item?->title,
|
||||
'number' => $item?->number,
|
||||
'type' => $type,
|
||||
'is_end' => $check_model::where($check_key, $item?->id)->count() !== 0 ? false : true
|
||||
'is_end' => $check_model::where($check_key, $item?->id)->count() !== 0 ? false : true,
|
||||
];
|
||||
});
|
||||
|
||||
@@ -544,7 +541,6 @@ class VolumController extends Controller
|
||||
return $this->success([], 'No law or book or volume specified');
|
||||
}
|
||||
|
||||
|
||||
public function check_filter_with_art(CheckBookFilterRequest $request)
|
||||
{
|
||||
$lawId = $request->law_id;
|
||||
@@ -584,7 +580,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($lawId) {
|
||||
$law = Law::with(['volums', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'arts'])->find($lawId);
|
||||
if (!$law) {
|
||||
if (! $law) {
|
||||
return $this->success([], 'Law not found');
|
||||
}
|
||||
|
||||
@@ -596,10 +592,9 @@ class VolumController extends Controller
|
||||
return $this->success([], 'No related records found in the law');
|
||||
}
|
||||
|
||||
|
||||
if ($bookId) {
|
||||
$book = Book::with(['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])->find($bookId);
|
||||
if (!$book) {
|
||||
if (! $book) {
|
||||
return $this->success([], 'Book not found');
|
||||
}
|
||||
|
||||
@@ -613,7 +608,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($volumeId) {
|
||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])->find($volumeId);
|
||||
if (!$volume) {
|
||||
if (! $volume) {
|
||||
return $this->success([], 'Volume not found');
|
||||
}
|
||||
|
||||
@@ -627,7 +622,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($sectionId) {
|
||||
$section = Section::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($sectionId);
|
||||
if (!$section) {
|
||||
if (! $section) {
|
||||
return $this->success([], 'Section not found');
|
||||
}
|
||||
|
||||
@@ -641,7 +636,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($divisionId) {
|
||||
$division = Division::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($divisionId);
|
||||
if (!$division) {
|
||||
if (! $division) {
|
||||
return $this->success([], 'Division not found');
|
||||
}
|
||||
|
||||
@@ -655,7 +650,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($partId) {
|
||||
$part = Part::with(['gates', 'art'])->find($partId);
|
||||
if (!$part) {
|
||||
if (! $part) {
|
||||
return $this->success([], 'Part not found');
|
||||
}
|
||||
|
||||
@@ -669,7 +664,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($branchId) {
|
||||
$branch = Branch::with(['gates', 'chapters', 'art'])->find($branchId);
|
||||
if (!$branch) {
|
||||
if (! $branch) {
|
||||
return $this->success([], 'Branch not found');
|
||||
}
|
||||
|
||||
@@ -683,7 +678,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($chapterId) {
|
||||
$chapter = Chapter::with(['gate', 'parts', 'art'])->find($chapterId);
|
||||
if (!$chapter) {
|
||||
if (! $chapter) {
|
||||
return $this->success([], 'Chapter not found');
|
||||
}
|
||||
|
||||
@@ -697,7 +692,7 @@ class VolumController extends Controller
|
||||
|
||||
if ($gateId) {
|
||||
$gate = Gate::with(['art'])->find($gateId);
|
||||
if (!$gate) {
|
||||
if (! $gate) {
|
||||
return $this->success([], 'Gate not found');
|
||||
}
|
||||
|
||||
@@ -712,7 +707,6 @@ class VolumController extends Controller
|
||||
return $this->success([], 'No valid filter specified');
|
||||
}
|
||||
|
||||
|
||||
private function prepareItemsData($items, $type)
|
||||
{
|
||||
$data = [];
|
||||
@@ -724,14 +718,15 @@ class VolumController extends Controller
|
||||
'number' => $item->number,
|
||||
'type' => $type,
|
||||
'route' => $this->route($item, $item),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||
'law' => $law?->title,
|
||||
'image' => $law?->image,
|
||||
'count_art' => $law?->arts?->count() ?? 0,
|
||||
'count_art' => $law?->arts?->count() ?? 0,
|
||||
'count_volums' => $law?->volums?->count() ?? 0,
|
||||
'price' => $law?->price,
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -740,13 +735,14 @@ class VolumController extends Controller
|
||||
foreach ($relations as $relation) {
|
||||
if ($model->{$relation} && $model->{$relation}->count() > 0) {
|
||||
$items = $model->{$relation}()->paginate($perPage);
|
||||
|
||||
return $this->prepareItemsData($items, $relation);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private function convertValueTo($var)
|
||||
{
|
||||
switch ($var) {
|
||||
@@ -769,13 +765,13 @@ class VolumController extends Controller
|
||||
switch ((new $modelClass)->getTable()) {
|
||||
case 'laws':
|
||||
$route = array_filter([
|
||||
Law::find($query->id)?->title
|
||||
Law::find($query->id)?->title,
|
||||
]);
|
||||
break;
|
||||
case 'volums':
|
||||
$route = array_filter([
|
||||
Law::find($query->law_id)?->title,
|
||||
Volum::find($query->id)?->title
|
||||
Volum::find($query->id)?->title,
|
||||
]);
|
||||
break;
|
||||
case 'books':
|
||||
|
||||
Reference in New Issue
Block a user