Display-Module in der Modulliste duplizieren.
Ermöglicht das Kopieren inklusive aller Inhalte und Einstellungen mit fortlaufender Benennung als „Kopie N - …“. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
bebfa63e87
commit
6c2da9bdac
3 changed files with 116 additions and 0 deletions
|
|
@ -80,6 +80,55 @@ class DisplayVersionList extends Component
|
|||
$version->update(['is_active' => ! $version->is_active]);
|
||||
}
|
||||
|
||||
public function copyVersion(int $id): void
|
||||
{
|
||||
$source = DisplayVersion::query()->with('items')->findOrFail($id);
|
||||
|
||||
$copy = DB::transaction(function () use ($source) {
|
||||
$copy = DisplayVersion::create([
|
||||
'name' => $this->copyNameFor($source->name),
|
||||
'type' => $source->type,
|
||||
'settings' => $source->settings ?? [],
|
||||
'is_active' => $source->is_active,
|
||||
]);
|
||||
|
||||
foreach ($source->items as $item) {
|
||||
$copy->items()->create([
|
||||
'item_type' => $item->item_type,
|
||||
'content' => $item->content,
|
||||
'sort_order' => $item->sort_order,
|
||||
'is_active' => $item->is_active,
|
||||
]);
|
||||
}
|
||||
|
||||
return $copy;
|
||||
});
|
||||
|
||||
session()->flash('success', 'Modul "'.$source->name.'" wurde als "'.$copy->name.'" kopiert!');
|
||||
}
|
||||
|
||||
private function copyNameFor(string $sourceName): string
|
||||
{
|
||||
$baseName = preg_match('/^Kopie \d+ - (.+)$/', $sourceName, $matches) === 1
|
||||
? $matches[1]
|
||||
: $sourceName;
|
||||
|
||||
$maxCopyNumber = 0;
|
||||
|
||||
DisplayVersion::query()
|
||||
->where('name', 'like', 'Kopie % - '.$baseName)
|
||||
->pluck('name')
|
||||
->each(function (string $name) use ($baseName, &$maxCopyNumber): void {
|
||||
if (preg_match('/^Kopie (\d+) - '.preg_quote($baseName, '/').'$/', $name, $matches) !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$maxCopyNumber = max($maxCopyNumber, (int) $matches[1]);
|
||||
});
|
||||
|
||||
return 'Kopie '.($maxCopyNumber + 1).' - '.$baseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue