Skip to content

Commit 78fae3e

Browse files
committed
Merge branch '1.x'
2 parents e9141ae + 87a5ebc commit 78fae3e

4 files changed

Lines changed: 93 additions & 86 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"illuminate/config": "5.*|6.*|7.*|8.*|9.*|10.*|11.*|12.*|13.*|14.*|15.*|16.*|17.*|18.*|19.*|20.*",
2525
"intervention/image": "^3.9.1",
2626
"kolossal-io/laravel-multiplex": "^1.5.2",
27-
"livewire/livewire": "^4.0@beta",
27+
"livewire/livewire": "^4.0",
2828
"secondnetwork/blade-tabler-icons": "^3.22.0",
2929
"spatie/laravel-permission": "^6.10.1",
3030
"spatie/laravel-activitylog": "^4.9.1",

resources/views/livewire/settings.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class="px-1 py-4 text-sm font-medium whitespace-nowrap border-b-2">{{ $tab }}</a
109109
</div> --}}
110110
<div x-show="asidenav === 'global'" x-cloak>
111111

112-
<div class="border-gray-200 whitespace-nowrap flex gap-8 justify-between items-center">
112+
<div class="border-gray-200 whitespace-nowrap flex gap-8 justify-between items-center mb-4">
113113

114114
<div class="my-3">
115115
<h3 class="text-2xl font-bold">{{ __('Global Settings') }}</h3>

src/Livewire/PagesTable.php

Lines changed: 30 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function addPage()
131131
{
132132
$this->validate();
133133

134-
$slugNameURL = Str::slug($this->title, '-', 'de'); //Convert Input to Str Slug
134+
$slugNameURL = Str::slug($this->title, '-', 'de'); // Convert Input to Str Slug
135135

136136
$placeObj = new Page;
137137

@@ -144,12 +144,12 @@ public function addPage()
144144
$newSlug = Str::slug($newSlug, '-', 'de');
145145
$checkSlug = $placeObj->whereSlug($newSlug)->exists();
146146
if (! $checkSlug) {
147-
$newpageslug = $newSlug; //New Slug
147+
$newpageslug = $newSlug; // New Slug
148148
break;
149149
}
150150
}
151151
} else {
152-
//Slug do not exists. Just use the selected Slug.
152+
// Slug do not exists. Just use the selected Slug.
153153
$newpageslug = $slugNameURL;
154154
}
155155

@@ -172,7 +172,7 @@ public function clone($id)
172172
{
173173
$pagemodel = Page::find($id);
174174

175-
$slugNameURL = $pagemodel['slug']; //Convert Input to Str Slug
175+
$slugNameURL = $pagemodel['slug']; // Convert Input to Str Slug
176176

177177
$placeObj = new Page;
178178

@@ -185,12 +185,12 @@ public function clone($id)
185185
$newSlug = Str::slug($newSlug, '-', 'de');
186186
$checkSlug = $placeObj->whereSlug($newSlug)->exists();
187187
if (! $checkSlug) {
188-
$clonepageslug = $newSlug; //New Slug
188+
$clonepageslug = $newSlug; // New Slug
189189
break;
190190
}
191191
}
192192
} else {
193-
//Slug do not exists. Just use the selected Slug.
193+
// Slug do not exists. Just use the selected Slug.
194194
$clonepageslug = $slugNameURL;
195195
}
196196

@@ -229,74 +229,46 @@ public function clone($id)
229229
}
230230
}
231231

232-
foreach ($blockcopy->datafield as $itemdata) {
232+
foreach ($item->datafield as $itemdata) {
233233
$copydatablock = $itemdata->replicate();
234234
$copydatablock->block_id = $blockcopy->id;
235235
$copydatablock->push();
236236
}
237237

238-
foreach ($blockcopy->children as $subgroup) {
239-
240-
$copygroup = $subgroup->replicate();
241-
$copygroup->blockable_id = $clone->id;
242-
$copygroup->subgroup = $blockcopy->id;
243-
$copygroup->push();
244-
245-
if ($itemMeta = $subgroup->allMeta) {
246-
$mod = Block::find($copygroup->id);
247-
248-
foreach ($itemMeta as $value) {
249-
$mod->saveMeta([
250-
$value->key => $value->value,
251-
]);
252-
}
253-
}
254-
255-
foreach ($subgroup->datafield as $itemdata) {
256-
$copydatablock = $itemdata->replicate();
257-
$copydatablock->block_id = $copygroup->id;
258-
$copydatablock->push();
259-
}
260-
}
261-
262-
self::cloneTree($blockcopy->children, $blocksclone, $clone->id, $copygroup->id);
238+
$children = $blocksclone->where('subgroup', $item->id);
239+
$this->cloneTree($children, $blocksclone, $clone->id, $blockcopy->id);
263240
}
264241

265242
$this->resetpage();
266243
}
267244

268-
public function cloneTree($categories, $allCategories, $cloneid, $blockid)
245+
public function cloneTree($categories, $allCategories, $cloneid, $parentId)
269246
{
270247
foreach ($categories as $item) {
248+
$copy = $item->replicate();
249+
$copy->blockable_id = $cloneid;
250+
$copy->subgroup = $parentId;
251+
$copy->push();
271252

272-
$item->children = $allCategories->where('subgroup', $item->id);
273-
274-
if ($item->children->isNotEmpty()) {
275-
foreach ($item->children as $subgroup) {
276-
277-
$copygroup = $subgroup->replicate();
278-
$copygroup->blockable_id = $cloneid;
279-
$copygroup->subgroup = $blockid;
280-
$copygroup->push();
281-
282-
if ($itemMeta = $subgroup->allMeta) {
283-
$mod = Block::find($copygroup->id);
284-
285-
foreach ($itemMeta as $value) {
286-
$mod->saveMeta([
287-
$value->key => $value->value,
288-
]);
289-
}
290-
}
253+
if ($itemMeta = $item->allMeta) {
254+
$mod = Block::find($copy->id);
291255

292-
foreach ($subgroup->datafield as $itemdata) {
293-
$copydatablock = $itemdata->replicate();
294-
$copydatablock->block_id = $copygroup->id;
295-
$copydatablock->push();
296-
}
256+
foreach ($itemMeta as $value) {
257+
$mod->saveMeta([
258+
$value->key => $value->value,
259+
]);
297260
}
261+
}
262+
263+
foreach ($item->datafield as $itemdata) {
264+
$copydatablock = $itemdata->replicate();
265+
$copydatablock->block_id = $copy->id;
266+
$copydatablock->push();
267+
}
298268

299-
self::cloneTree($item->children, $allCategories, $cloneid, $copygroup->id);
269+
$children = $allCategories->where('subgroup', $item->id);
270+
if ($children->isNotEmpty()) {
271+
$this->cloneTree($children, $allCategories, $cloneid, $copy->id);
300272
}
301273
}
302274
}

src/Livewire/PostsTable.php

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Livewire\Component;
99
use Livewire\WithPagination;
1010
use Secondnetwork\Kompass\Models\Block;
11-
use Secondnetwork\Kompass\Models\Datafield;
1211
use Secondnetwork\Kompass\Models\Post;
1312

1413
class PostsTable extends Component
@@ -93,7 +92,7 @@ public function mount()
9392

9493
public function resetpost()
9594
{
96-
$this->mount($this->post_id);
95+
$this->resetpage();
9796
}
9897

9998
private function resultDate()
@@ -140,7 +139,7 @@ public function addPost()
140139
{
141140
$this->validate();
142141

143-
$slugNameURL = Str::slug($this->title, '-', 'de'); //Convert Input to Str Slug
142+
$slugNameURL = Str::slug($this->title, '-', 'de'); // Convert Input to Str Slug
144143

145144
$placeObj = new Post;
146145

@@ -153,12 +152,12 @@ public function addPost()
153152
$newSlug = Str::slug($newSlug, '-', 'de');
154153
$checkSlug = $placeObj->whereSlug($newSlug)->exists();
155154
if (! $checkSlug) {
156-
$newpostslug = $newSlug; //New Slug
155+
$newpostslug = $newSlug; // New Slug
157156
break;
158157
}
159158
}
160159
} else {
161-
//Slug do not exists. Just use the selected Slug.
160+
// Slug do not exists. Just use the selected Slug.
162161
$newpostslug = $slugNameURL;
163162
}
164163

@@ -182,7 +181,7 @@ public function clone($id)
182181

183182
$newpost = $post->replicate();
184183

185-
$slugNameURL = Str::slug($newpost['title'], '-', 'de'); //Convert Input to Str Slug
184+
$slugNameURL = Str::slug($newpost['title'], '-', 'de'); // Convert Input to Str Slug
186185

187186
$placeObj = new Post;
188187

@@ -195,44 +194,80 @@ public function clone($id)
195194
$newSlug = Str::slug($newSlug, '-', 'de');
196195
$checkSlug = $placeObj->whereSlug($newSlug)->exists();
197196
if (! $checkSlug) {
198-
$newpost->slug = $newSlug; //New Slug
197+
$newpost->slug = $newSlug; // New Slug
199198
break;
200199
}
201200
}
202201
} else {
203-
//Slug do not exists. Just use the selected Slug.
202+
// Slug do not exists. Just use the selected Slug.
204203
$newpost->slug = $slugNameURL;
205204
}
206205
$newpost->status = 'draft';
207206
$newpost->created_at = Carbon::now();
208207

209208
$newpost->push();
210209

211-
$blocksclone = Block::where('post_id', $id)->orderBy('order', 'asc')->where('subgroup', null)->with('children')->get();
210+
$relationships = ['datafield', 'meta', 'children'];
211+
$blocksclone = Block::where('blockable_id', $id)->where('blockable_type', 'post')->with($relationships)->get();
212212

213-
$blocksclone->each(function ($item, $key) use ($newpost): void {
214-
$altID = $item->id;
213+
$rootblock = $blocksclone->whereNull('subgroup');
215214

215+
foreach ($rootblock as $item) {
216+
$blockcopy = $item->replicate();
217+
$blockcopy->blockable_id = $newpost->id;
218+
$blockcopy->push();
219+
220+
if ($itemMeta = $item->allMeta) {
221+
$mod = Block::find($blockcopy->id);
222+
foreach ($itemMeta as $value) {
223+
$mod->saveMeta([
224+
$value->key => $value->value,
225+
]);
226+
}
227+
}
228+
229+
foreach ($item->datafield as $itemdata) {
230+
$copydatablock = $itemdata->replicate();
231+
$copydatablock->block_id = $blockcopy->id;
232+
$copydatablock->push();
233+
}
234+
235+
$children = $blocksclone->where('subgroup', $item->id);
236+
$this->cloneTree($children, $blocksclone, $newpost->id, $blockcopy->id);
237+
}
238+
239+
$this->resetpage();
240+
}
241+
242+
public function cloneTree($categories, $allCategories, $cloneid, $parentId)
243+
{
244+
foreach ($categories as $item) {
216245
$copy = $item->replicate();
246+
$copy->blockable_id = $cloneid;
247+
$copy->subgroup = $parentId;
248+
$copy->push();
249+
250+
if ($itemMeta = $item->allMeta) {
251+
$mod = Block::find($copy->id);
217252

218-
$copy->post_id = $newpost->id;
219-
$copy->save();
220-
if ($copy->children) {
221-
foreach ($copy->children as $subgroup) {
222-
$copygroup = $subgroup->replicate();
223-
$copygroup->post_id = $newpost->id;
224-
$copygroup->subgroup = $copy->id;
225-
$copygroup->save();
253+
foreach ($itemMeta as $value) {
254+
$mod->saveMeta([
255+
$value->key => $value->value,
256+
]);
226257
}
227258
}
228259

229-
$fields = Datafield::where('block_id', $altID)->get();
230-
$fields->each(function ($item, $key) use ($copy): void {
231-
$copyitem = $item->replicate();
232-
$copyitem->block_id = $copy->id;
233-
$copyitem->save();
234-
}, );
235-
}, );
260+
foreach ($item->datafield as $itemdata) {
261+
$copydatablock = $itemdata->replicate();
262+
$copydatablock->block_id = $copy->id;
263+
$copydatablock->push();
264+
}
265+
266+
$children = $allCategories->where('subgroup', $item->id);
267+
if ($children->isNotEmpty()) {
268+
$this->cloneTree($children, $allCategories, $cloneid, $copy->id);
269+
}
270+
}
236271
}
237272

238273
public function delete()

0 commit comments

Comments
 (0)