From 3d5b1d7020a0cc296d86df26aea59ece94722050 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 26 Nov 2020 14:08:12 +0100 Subject: [PATCH] wip #3756 @0.5 --- .../Http/Controllers/CubistCrudController.php | 8 --- .../Controllers/CubistMagicController.php | 5 +- .../Magic/Models/CubistMagicAbstractModel.php | 51 +++++++++++++++++-- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/app/Http/Controllers/CubistCrudController.php b/src/app/Http/Controllers/CubistCrudController.php index 53d556e..7855d91 100644 --- a/src/app/Http/Controllers/CubistCrudController.php +++ b/src/app/Http/Controllers/CubistCrudController.php @@ -19,13 +19,5 @@ use Cubist\Backpack\app\Http\Controllers\Operations\MediaOperation; class CubistCrudController extends CrudController { use ListOperation; - use CreateOperation; - use UpdateOperation; - use DeleteOperation; - use BulkDeleteOperation; - use CloneOperation; - use BulkCloneOperation; - use ReviseOperation; - use BulkPublishOperation; use MediaOperation; } diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index ffc71d9..7104806 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -63,9 +63,6 @@ class CubistMagicController extends CubistCrudController $this->crud->denyAccess(['create', 'delete']); } else { $this->crud->setCreateView('cubist_back::create'); - if ($this->_clonable) { - $this->crud->allowAccess('clone'); - } $this->crud->enableExportButtons(); $this->crud->enablePersistentTable(); } @@ -229,7 +226,7 @@ class CubistMagicController extends CubistCrudController { try { $this->getModelInstance()->flushCache([Menu::CACHE_TAG]); - }catch (\Exception $e){ + } catch (\Exception $e) { } } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 73c9137..8feedf8 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -2,8 +2,16 @@ namespace Cubist\Backpack\app\Magic\Models; +use Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation; +use Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation; +use Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation; +use Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; +use Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; use Backpack\CRUD\app\Library\CrudPanel\CrudPanel; use Backpack\CRUD\app\Models\Traits\CrudTrait; +use Backpack\ReviseOperation\ReviseOperation; +use Composer\DependencyResolver\Operation\UpdateOperation; +use Cubist\Backpack\app\Http\Controllers\Operations\BulkPublishOperation; use Cubist\Backpack\app\Magic\BunchOfFields; use Cubist\Backpack\app\Magic\Controllers\CubistMagicController; use Cubist\Backpack\app\Magic\EntityData; @@ -41,7 +49,14 @@ class CubistMagicAbstractModel extends Model implements HasMedia protected $primaryKey = 'id'; protected $_operations = []; public $timestamps = true; - public $clonable = true; + + protected $_enableClone = true; + protected $_enableDeletion = true; + protected $_enableEdition = true; + protected $_enableCreation = true; + protected $_enableRevisions = true; + protected $_enableBulk = true; + protected $_syncDbSchema = true; protected $_baseController = CubistMagicController::class; @@ -305,7 +320,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia } /** - * @return string + * @return stringx */ protected function _getBaseController() { @@ -315,9 +330,36 @@ class CubistMagicAbstractModel extends Model implements HasMedia protected function _getUse() { $res = ''; - foreach ($this->_operations as $operation) { - $res .= 'use ' . $operation . ';' . "\n"; + $ops = $this->_operations; + if ($this->_enableCreation) { + $ops[] = CreateOperation::class; + } + if ($this->_enableEdition) { + $ops[] = UpdateOperation::class; + if ($this->_enableBulk) { + $ops[] = BulkPublishOperation::class; + } + } + if ($this->_enableClone) { + $ops[] = CloneOperation::class; + if ($this->_enableBulk) { + $ops[] = BulkCloneOperation::class; + } + } + if ($this->_enableDeletion) { + $ops[] = DeleteOperation::class; + if ($this->_enableBulk) { + $ops[] = BulkDeleteOperation::class; + } + } + if ($this->_enableRevisions) { + $ops[] = ReviseOperation::class; + } + + foreach ($ops as $operation) { + $res .= 'use \\' . $operation . ';' . "\n\t"; } + $res .= "\n"; return $res; } @@ -329,7 +371,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia 'PLURAL' => $this->getOption('plural', ''), 'MODELNAMESPACE' => get_class($this), 'EXTENDS' => '\\' . $this->_getBaseController(), - 'CLONABLE' => $this->clonable ? 'true' : 'false', 'BULK' => $this->getOption('bulk', true) ? 'true' : 'false', 'ONEINSTANCE' => $this->getOption('oneinstance', false) ? 'true' : 'false', 'USE' => $this->_getUse()]; -- 2.39.5