changes
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\SubSections;
|
||||
|
||||
use App\Containers\AppStructure\Models\SubSection;
|
||||
|
||||
class AttachSubSectionToMainSectionAction
|
||||
{
|
||||
public function run(SubSection $subSection, int $mainSectionId): SubSection
|
||||
{
|
||||
$subSection->update(['main_section_id' => $mainSectionId]);
|
||||
|
||||
return $subSection->fresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\SubSections;
|
||||
|
||||
use App\Containers\AppStructure\Models\SubSection;
|
||||
|
||||
class CreateSubSectionAction
|
||||
{
|
||||
public function run(array $data): SubSection
|
||||
{
|
||||
return SubSection::create([
|
||||
'title' => $data['title'],
|
||||
'slug' => $data['slug'],
|
||||
'main_section_id' => $data['main_section_id'] ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\SubSections;
|
||||
|
||||
use App\Containers\AppStructure\Models\SubSection;
|
||||
|
||||
class DeleteSubSectionAction
|
||||
{
|
||||
public function run(SubSection $subSection): bool
|
||||
{
|
||||
return $subSection->delete();
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\SubSections;
|
||||
|
||||
use App\Containers\AppStructure\Models\SubSection;
|
||||
|
||||
class DetachSubSectionFromMainSectionAction
|
||||
{
|
||||
public function run(SubSection $subSection): SubSection
|
||||
{
|
||||
$subSection->update(['main_section_id' => null]);
|
||||
|
||||
return $subSection->fresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\SubSections;
|
||||
|
||||
use App\Containers\AppStructure\Models\SubSection;
|
||||
|
||||
class ListSubSectionsAction
|
||||
{
|
||||
public function run(array $filters): array
|
||||
{
|
||||
$query = SubSection::query()->with(['mainSection', 'pages']);
|
||||
|
||||
if (!empty($filters['search'])) {
|
||||
$query->where('title', 'like', '%' . $filters['search'] . '%');
|
||||
}
|
||||
|
||||
if (!empty($filters['main_section_id'])) {
|
||||
$query->where('main_section_id', $filters['main_section_id']);
|
||||
}
|
||||
|
||||
$subSections = $query->orderBy('sort')->paginate(15);
|
||||
|
||||
return [
|
||||
'subSections' => $subSections,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\Dashboard\Actions\SubSections;
|
||||
|
||||
use App\Containers\AppStructure\Models\Page;
|
||||
use App\Containers\AppStructure\Models\SubSection;
|
||||
|
||||
class UpdateSubSectionAction
|
||||
{
|
||||
public function run(SubSection $subSection, array $data): SubSection
|
||||
{
|
||||
$subSection->update([
|
||||
'title' => $data['title'],
|
||||
'slug' => $data['slug'],
|
||||
]);
|
||||
|
||||
if (isset($data['page_ids'])) {
|
||||
$this->syncPages($subSection, $data['page_ids']);
|
||||
}
|
||||
|
||||
return $subSection->fresh();
|
||||
}
|
||||
|
||||
private function syncPages(SubSection $subSection, array $pageIds): void
|
||||
{
|
||||
Page::query()->where('sub_section_id', '=', $subSection->id)->update(['sub_section_id' => null]);
|
||||
Page::whereIn('id', $pageIds)->update(['sub_section_id' => $subSection->id]);
|
||||
|
||||
$pages = Page::where('is_url', '=', false)
|
||||
->where('sub_section_id', '=', $subSection->id)
|
||||
->get();
|
||||
|
||||
if ($pages->isEmpty() || !$subSection->mainSection) {
|
||||
return;
|
||||
}
|
||||
|
||||
$mainSectionSlug = $pages->first()->section->mainSection->slug;
|
||||
|
||||
foreach ($pages as $page) {
|
||||
if ($page->is_registered != true) {
|
||||
$page->update(['path' => $mainSectionSlug . '/' . $subSection->slug . '/' . $page->slug]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user