]> _ Git - cubist_cms-back.git/commitdiff
#2810
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Jun 2019 10:24:02 +0000 (12:24 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Jun 2019 10:24:02 +0000 (12:24 +0200)
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Controllers/CubistMagicControllerTrait.php
src/app/Magic/Controllers/CubistMagicNestedController.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/resources/cubistmagic/Controller.stub

index 3cb4f25cd3bf4473e49c9002fdd5c535ad033509..b7ac7307c9548da3ca373865bcd44decc3d4c142 100644 (file)
@@ -8,14 +8,16 @@ use Backpack\CRUD\CrudTrait;
 
 class CubistMagicController extends CrudController
 {
-    use CrudTrait,CubistMagicControllerTrait;
+    use CrudTrait, CubistMagicControllerTrait;
 
     protected $_modelNamespace;
     protected $_routeURL;
     protected $_singular;
     protected $_plural;
+    protected $_bulk;
 
-    public function _postSetModel(){
+    public function _postSetModel()
+    {
 
     }
 }
index ede1b0c25419ddda43e2dcc36e48f0205224ab0e..d90ccc37828535d7f93d11e60c50f06083a1f9c2 100644 (file)
@@ -21,6 +21,7 @@ trait CubistMagicControllerTrait
             $this->crud->allowAccess('clone');
         }
 
+
         /*
         |--------------------------------------------------------------------------
         | CrudPanel Basic Information
@@ -28,6 +29,9 @@ trait CubistMagicControllerTrait
         */
         $this->crud->setModel($this->_modelNamespace);
         $this->_postSetModel();
+        if($this->_bulk) {
+            $this->crud->enableBulkActions();
+        }
         $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
         $this->crud->setEntityNameStrings($this->_singular, $this->_plural);
 
index 367ad89f9706f31b6e637dc0542c09a4ab29e73f..101fdbd7043d579870fa1963df3944849a0564b8 100644 (file)
@@ -14,6 +14,7 @@ class CubistMagicNestedController extends NestedModelsCrudController
     protected $_routeURL;
     protected $_singular;
     protected $_plural;
+    protected $_bulk;
 
     public function _postSetModel(){
         $this->treeSetup();
index ed8d54fc59effee559d7ec9f57f9b29c9db7ea31..7d2534315d2eef6205604b975fd3593c32052933 100644 (file)
@@ -50,6 +50,11 @@ class CubistMagicAbstractModel extends Model
      */
     protected $translatable = [];
 
+    /**
+     * @var array
+     */
+    protected $fakeColumns = [];
+
 
     /**
      * @var Field[]
@@ -163,20 +168,34 @@ class CubistMagicAbstractModel extends Model
 
         $name = $field->getAttribute('name');
         $this->_fields[$name] = $field;
-        if ($field->getAttribute('fillable')) {
-            $this->fillable[] = $name;
-        }
-        if ($field->getAttribute('guarded')) {
-            $this->guarded[] = $name;
-        }
-        if ($field->getAttribute('hidden')) {
-            $this->hidden[] = $name;
-        }
-        if ($field->getAttribute('translatable')) {
-            $this->translatable[] = $name;
-        }
-        if ($field->getAttribute('cast', false) !== false) {
-            $this->casts[$field->getAttribute('name')] = $field->getAttribute('name');
+
+        if ($field->getAttribute('fake', false) === true) {
+            $store_in = $field->getAttribute('store_in');
+            if (!in_array($store_in, $this->fillable)) {
+                $this->fillable[] = $store_in;
+            }
+            if (!isset($this->casts[$store_in])) {
+                $this->casts[$store_in] = 'array';
+            }
+            if (!in_array($store_in, $this->fakeColumns)) {
+                $this->fakeColumns[] = $store_in;
+            }
+        } else {
+            if ($field->getAttribute('fillable')) {
+                $this->fillable[] = $name;
+            }
+            if ($field->getAttribute('guarded')) {
+                $this->guarded[] = $name;
+            }
+            if ($field->getAttribute('hidden')) {
+                $this->hidden[] = $name;
+            }
+            if ($field->getAttribute('translatable')) {
+                $this->translatable[] = $name;
+            }
+            if ($field->getAttribute('cast', false) !== false) {
+                $this->casts[$field->getAttribute('name')] = $field->getAttribute('name');
+            }
         }
 
 
@@ -222,7 +241,8 @@ class CubistMagicAbstractModel extends Model
             'PLURAL' => $this->getOption('plural', ''),
             'MODELNAMESPACE' => get_class($this),
             'EXTENDS' => $this->_getBaseController(),
-            'CLONABLE' => $this->clonable ? 'true' : 'false'
+            'CLONABLE' => $this->clonable ? 'true' : 'false',
+            'BULK' => $this->getOption('bulk', true) ? 'true' : 'false'
         ];
 
         $res = file_get_contents($stub);
index ca89dd3ca802fc8ac828ce25f94543eabadf0e60..555c9578bbf4612c5cbe1fc1e69231207e46384a 100644 (file)
@@ -11,4 +11,5 @@ class _CONTROLLERCLASS_ extends _EXTENDS_
     protected $_singular = '_SINGULAR_';
     protected $_plural = '_PLURAL_';
     protected $_clonable = _CLONABLE_;
+    protected $_bulk = _BULK_;
 }