]> _ Git - cubist_cms-back.git/commitdiff
wip #3756 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 26 Nov 2020 13:08:12 +0000 (14:08 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 26 Nov 2020 13:08:12 +0000 (14:08 +0100)
src/app/Http/Controllers/CubistCrudController.php
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index 53d556ea084e04532ceae73d0d663a51b8d68023..7855d9163c4855eb350b892ce4b61107af7ef91e 100644 (file)
@@ -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;
 }
index ffc71d9ef446577ebcb4c4d220a63acd5460cd89..7104806ceff1078db2be2251c37e77edee08cf2b 100644 (file)
@@ -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) {
 
         }
     }
index 73c913730bcb31d4ff6c17c33250b39399453b2a..8feedf899f03402fd335d3eb357117dd1bf3e04b 100644 (file)
@@ -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()];