Updated VolumController.php
This commit is contained in:
@@ -58,8 +58,8 @@ class VolumController extends Controller
|
|||||||
|
|
||||||
$perPage = $request->per_page ?? 10;
|
$perPage = $request->per_page ?? 10;
|
||||||
if ($bookId) {
|
if ($bookId) {
|
||||||
|
// ترتیب درست اعمال شد
|
||||||
$book = Book::with(['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
|
$book = Book::with(['divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])
|
||||||
->find($bookId);
|
->find($bookId);
|
||||||
|
|
||||||
if (! $book) {
|
if (! $book) {
|
||||||
@@ -68,7 +68,7 @@ class VolumController extends Controller
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$foundRelation = false;
|
$foundRelation = false;
|
||||||
foreach (['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'] as $relation) {
|
foreach (['divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'] as $relation) {
|
||||||
if ($book->{$relation}->count() > 0) {
|
if ($book->{$relation}->count() > 0) {
|
||||||
$foundRelation = true;
|
$foundRelation = true;
|
||||||
$items = $book->{$relation}()->paginate($perPage);
|
$items = $book->{$relation}()->paginate($perPage);
|
||||||
@@ -96,7 +96,7 @@ class VolumController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($division_id) {
|
if ($division_id) {
|
||||||
$division = Division::with(['sections', 'chapters', 'parts', 'gate', 'branch', 'art'])
|
$division = Division::with(['sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])
|
||||||
->find($division_id);
|
->find($division_id);
|
||||||
|
|
||||||
if (! $division) {
|
if (! $division) {
|
||||||
@@ -105,7 +105,7 @@ class VolumController extends Controller
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$foundRelation = false;
|
$foundRelation = false;
|
||||||
foreach (['sections', 'chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
|
foreach (['sections', 'chapters', 'parts', 'gates', 'branchs', 'art'] as $relation) {
|
||||||
if ($division->{$relation}->count() > 0) {
|
if ($division->{$relation}->count() > 0) {
|
||||||
$foundRelation = true;
|
$foundRelation = true;
|
||||||
$items = $division->{$relation}()->paginate($perPage);
|
$items = $division->{$relation}()->paginate($perPage);
|
||||||
@@ -130,7 +130,7 @@ class VolumController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($section_id) {
|
if ($section_id) {
|
||||||
$section = Section::with(['chapters', 'parts', 'gate', 'branch', 'art'])
|
$section = Section::with(['chapters', 'parts', 'gates', 'branchs', 'art'])
|
||||||
->find($section_id);
|
->find($section_id);
|
||||||
|
|
||||||
if (! $section) {
|
if (! $section) {
|
||||||
@@ -139,7 +139,7 @@ class VolumController extends Controller
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$foundRelation = false;
|
$foundRelation = false;
|
||||||
foreach (['chapters', 'parts', 'gate', 'branch', 'art'] as $relation) {
|
foreach (['chapters', 'parts', 'gates', 'branchs', 'art'] as $relation) {
|
||||||
if ($section->{$relation}->count() > 0) {
|
if ($section->{$relation}->count() > 0) {
|
||||||
$foundRelation = true;
|
$foundRelation = true;
|
||||||
$items = $section->{$relation}()->paginate($perPage);
|
$items = $section->{$relation}()->paginate($perPage);
|
||||||
@@ -164,7 +164,7 @@ class VolumController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($volumeId) {
|
if ($volumeId) {
|
||||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])
|
$volume = Volum::with(['book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])
|
||||||
->find($volumeId);
|
->find($volumeId);
|
||||||
if (! $volume) {
|
if (! $volume) {
|
||||||
return $this->success([], 'Volume not found');
|
return $this->success([], 'Volume not found');
|
||||||
@@ -196,8 +196,42 @@ class VolumController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($chapter_id) {
|
||||||
|
$chapter = Chapter::with(['parts', 'gates', 'branchs', 'art'])
|
||||||
|
->find($chapter_id);
|
||||||
|
|
||||||
|
if (! $chapter) {
|
||||||
|
return $this->success([], 'Chapter not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$foundRelation = false;
|
||||||
|
foreach (['parts', 'gates', 'branchs', 'art'] as $relation) {
|
||||||
|
if ($chapter->{$relation}->count() > 0) {
|
||||||
|
$foundRelation = true;
|
||||||
|
$items = $chapter->{$relation}()->paginate($perPage);
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$data[] = [
|
||||||
|
'id' => $item->id,
|
||||||
|
'title' => $item->title,
|
||||||
|
'number' => $item->number,
|
||||||
|
'type' => $relation,
|
||||||
|
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($foundRelation) {
|
||||||
|
return $this->success($data, 'Success');
|
||||||
|
} else {
|
||||||
|
return $this->success([], 'No relations found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($part_id) {
|
if ($part_id) {
|
||||||
$part = Part::with(['gate', 'branch', 'art'])
|
$part = Part::with(['gates', 'branchs', 'art'])
|
||||||
->find($part_id);
|
->find($part_id);
|
||||||
|
|
||||||
if (! $part) {
|
if (! $part) {
|
||||||
@@ -206,7 +240,7 @@ class VolumController extends Controller
|
|||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$foundRelation = false;
|
$foundRelation = false;
|
||||||
foreach (['gate', 'branch', 'art'] as $relation) {
|
foreach (['gates', 'branchs', 'art'] as $relation) {
|
||||||
if ($part->{$relation}->count() > 0) {
|
if ($part->{$relation}->count() > 0) {
|
||||||
$foundRelation = true;
|
$foundRelation = true;
|
||||||
$items = $part->{$relation}()->paginate($perPage);
|
$items = $part->{$relation}()->paginate($perPage);
|
||||||
@@ -230,20 +264,20 @@ class VolumController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($chapter_id) {
|
if ($gate_id) {
|
||||||
$chapter = Chapter::with(['parts', 'gate', 'branch', 'art'])
|
$gate = Gate::with(['branchs', 'art'])
|
||||||
->find($chapter_id);
|
->find($gate_id);
|
||||||
|
|
||||||
if (! $chapter) {
|
if (! $gate) {
|
||||||
return $this->success([], 'Chapter not found');
|
return $this->success([], 'Gate not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
$foundRelation = false;
|
$foundRelation = false;
|
||||||
foreach (['parts', 'gate', 'branch', 'art'] as $relation) {
|
foreach (['branchs', 'art'] as $relation) {
|
||||||
if ($chapter->{$relation}->count() > 0) {
|
if ($gate->{$relation}->count() > 0) {
|
||||||
$foundRelation = true;
|
$foundRelation = true;
|
||||||
$items = $chapter->{$relation}()->paginate($perPage);
|
$items = $gate->{$relation}()->paginate($perPage);
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$data[] = [
|
$data[] = [
|
||||||
'id' => $item->id,
|
'id' => $item->id,
|
||||||
@@ -298,74 +332,6 @@ class VolumController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($gate_id) {
|
|
||||||
$gate = Gate::with(['branch', 'art'])
|
|
||||||
->find($gate_id);
|
|
||||||
|
|
||||||
if (! $gate) {
|
|
||||||
return $this->success([], 'Gate not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = [];
|
|
||||||
$foundRelation = false;
|
|
||||||
foreach (['branch', 'art'] as $relation) {
|
|
||||||
if ($gate->{$relation}->count() > 0) {
|
|
||||||
$foundRelation = true;
|
|
||||||
$items = $gate->{$relation}()->paginate($perPage);
|
|
||||||
foreach ($items as $item) {
|
|
||||||
$data[] = [
|
|
||||||
'id' => $item->id,
|
|
||||||
'title' => $item->title,
|
|
||||||
'number' => $item->number,
|
|
||||||
'type' => $relation,
|
|
||||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($foundRelation) {
|
|
||||||
return $this->success($data, 'Success');
|
|
||||||
} else {
|
|
||||||
return $this->success([], 'No relations found');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($volumeId) {
|
|
||||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs'])
|
|
||||||
->find($volumeId);
|
|
||||||
|
|
||||||
if (! $volume) {
|
|
||||||
return $this->success([], 'Volume not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = [];
|
|
||||||
$foundRelation = false;
|
|
||||||
foreach (['book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs'] as $relation) {
|
|
||||||
if ($volume->{$relation}->count() > 0) {
|
|
||||||
$foundRelation = true;
|
|
||||||
$items = $volume->{$relation}()->paginate($perPage);
|
|
||||||
foreach ($items as $item) {
|
|
||||||
$data[] = [
|
|
||||||
'id' => $item->id,
|
|
||||||
'title' => $item->title,
|
|
||||||
'number' => $item->number,
|
|
||||||
'type' => $relation,
|
|
||||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : Law::where('id', $item->law_id)->first()?->is_locked,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($foundRelation) {
|
|
||||||
return $this->success($data, 'Success');
|
|
||||||
} else {
|
|
||||||
return $this->success([], 'No relations found');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($law_Id) {
|
if ($law_Id) {
|
||||||
$law = Law::find($law_Id);
|
$law = Law::find($law_Id);
|
||||||
|
|
||||||
@@ -579,12 +545,12 @@ class VolumController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($lawId) {
|
if ($lawId) {
|
||||||
$law = Law::with(['volums', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'arts'])->find($lawId);
|
$law = Law::with(['volums', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'arts'])->find($lawId);
|
||||||
if (! $law) {
|
if (! $law) {
|
||||||
return $this->success([], 'Law not found');
|
return $this->success([], 'Law not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->checkRelations($law, ['volums', 'book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'arts'], $perPage);
|
$data = $this->checkRelations($law, ['volums', 'book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'arts'], $perPage);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->success($data, 'Success');
|
return $this->success($data, 'Success');
|
||||||
}
|
}
|
||||||
@@ -592,27 +558,13 @@ class VolumController extends Controller
|
|||||||
return $this->success([], 'No related records found in the law');
|
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) {
|
|
||||||
return $this->success([], 'Book not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->checkRelations($book, ['divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
|
|
||||||
if ($data) {
|
|
||||||
return $this->success($data, 'Success');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->success([], 'No related records found in the book');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($volumeId) {
|
if ($volumeId) {
|
||||||
$volume = Volum::with(['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'])->find($volumeId);
|
$volume = Volum::with(['book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])->find($volumeId);
|
||||||
if (! $volume) {
|
if (! $volume) {
|
||||||
return $this->success([], 'Volume not found');
|
return $this->success([], 'Volume not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->checkRelations($volume, ['book', 'divisions', 'sections', 'gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
|
$data = $this->checkRelations($volume, ['book', 'divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'], $perPage);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->success($data, 'Success');
|
return $this->success($data, 'Success');
|
||||||
}
|
}
|
||||||
@@ -620,27 +572,27 @@ class VolumController extends Controller
|
|||||||
return $this->success([], 'No related records found in the volume');
|
return $this->success([], 'No related records found in the volume');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sectionId) {
|
if ($bookId) {
|
||||||
$section = Section::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($sectionId);
|
$book = Book::with(['divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])->find($bookId);
|
||||||
if (! $section) {
|
if (! $book) {
|
||||||
return $this->success([], 'Section not found');
|
return $this->success([], 'Book not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->checkRelations($section, ['gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
|
$data = $this->checkRelations($book, ['divisions', 'sections', 'chapters', 'parts', 'gates', 'branchs', 'art'], $perPage);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->success($data, 'Success');
|
return $this->success($data, 'Success');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success([], 'No related records found in the section');
|
return $this->success([], 'No related records found in the book');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($divisionId) {
|
if ($divisionId) {
|
||||||
$division = Division::with(['gates', 'parts', 'chapters', 'branchs', 'art'])->find($divisionId);
|
$division = Division::with(['sections', 'chapters', 'parts', 'gates', 'branchs', 'art'])->find($divisionId);
|
||||||
if (! $division) {
|
if (! $division) {
|
||||||
return $this->success([], 'Division not found');
|
return $this->success([], 'Division not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->checkRelations($division, ['gates', 'parts', 'chapters', 'branchs', 'art'], $perPage);
|
$data = $this->checkRelations($division, ['sections', 'chapters', 'parts', 'gates', 'branchs', 'art'], $perPage);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->success($data, 'Success');
|
return $this->success($data, 'Success');
|
||||||
}
|
}
|
||||||
@@ -648,41 +600,27 @@ class VolumController extends Controller
|
|||||||
return $this->success([], 'No related records found in the division');
|
return $this->success([], 'No related records found in the division');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($partId) {
|
if ($sectionId) {
|
||||||
$part = Part::with(['gates', 'art'])->find($partId);
|
$section = Section::with(['chapters', 'parts', 'gates', 'branchs', 'art'])->find($sectionId);
|
||||||
if (! $part) {
|
if (! $section) {
|
||||||
return $this->success([], 'Part not found');
|
return $this->success([], 'Section not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->checkRelations($part, ['gates', 'art'], $perPage);
|
$data = $this->checkRelations($section, ['chapters', 'parts', 'gates', 'branchs', 'art'], $perPage);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->success($data, 'Success');
|
return $this->success($data, 'Success');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->success([], 'No related records found in the part');
|
return $this->success([], 'No related records found in the section');
|
||||||
}
|
|
||||||
|
|
||||||
if ($branchId) {
|
|
||||||
$branch = Branch::with(['gates', 'chapters', 'art'])->find($branchId);
|
|
||||||
if (! $branch) {
|
|
||||||
return $this->success([], 'Branch not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $this->checkRelations($branch, ['gates', 'chapters', 'art'], $perPage);
|
|
||||||
if ($data) {
|
|
||||||
return $this->success($data, 'Success');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->success([], 'No related records found in the branch');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($chapterId) {
|
if ($chapterId) {
|
||||||
$chapter = Chapter::with(['gate', 'parts', 'art'])->find($chapterId);
|
$chapter = Chapter::with(['parts', 'gates', 'branchs', 'art'])->find($chapterId);
|
||||||
if (! $chapter) {
|
if (! $chapter) {
|
||||||
return $this->success([], 'Chapter not found');
|
return $this->success([], 'Chapter not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->checkRelations($chapter, ['gate', 'parts', 'art'], $perPage);
|
$data = $this->checkRelations($chapter, ['parts', 'gates', 'branchs', 'art'], $perPage);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->success($data, 'Success');
|
return $this->success($data, 'Success');
|
||||||
}
|
}
|
||||||
@@ -690,13 +628,27 @@ class VolumController extends Controller
|
|||||||
return $this->success([], 'No related records found in the chapter');
|
return $this->success([], 'No related records found in the chapter');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($partId) {
|
||||||
|
$part = Part::with(['gates', 'branchs', 'art'])->find($partId);
|
||||||
|
if (! $part) {
|
||||||
|
return $this->success([], 'Part not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->checkRelations($part, ['gates', 'branchs', 'art'], $perPage);
|
||||||
|
if ($data) {
|
||||||
|
return $this->success($data, 'Success');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success([], 'No related records found in the part');
|
||||||
|
}
|
||||||
|
|
||||||
if ($gateId) {
|
if ($gateId) {
|
||||||
$gate = Gate::with(['art'])->find($gateId);
|
$gate = Gate::with(['branchs', 'art'])->find($gateId);
|
||||||
if (! $gate) {
|
if (! $gate) {
|
||||||
return $this->success([], 'Gate not found');
|
return $this->success([], 'Gate not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->checkRelations($gate, ['art'], $perPage);
|
$data = $this->checkRelations($gate, ['branchs', 'art'], $perPage);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->success($data, 'Success');
|
return $this->success($data, 'Success');
|
||||||
}
|
}
|
||||||
@@ -704,6 +656,20 @@ class VolumController extends Controller
|
|||||||
return $this->success([], 'No related records found in the gate');
|
return $this->success([], 'No related records found in the gate');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($branchId) {
|
||||||
|
$branch = Branch::with(['art'])->find($branchId);
|
||||||
|
if (! $branch) {
|
||||||
|
return $this->success([], 'Branch not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $this->checkRelations($branch, ['art'], $perPage);
|
||||||
|
if ($data) {
|
||||||
|
return $this->success($data, 'Success');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success([], 'No related records found in the branch');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->success([], 'No valid filter specified');
|
return $this->success([], 'No valid filter specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -857,4 +823,5 @@ class VolumController extends Controller
|
|||||||
|
|
||||||
return array_values($route);
|
return array_values($route);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user