From 8327eaf2d5a79a69bc13909eb834913ea9cb5d6c Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 6 Jun 2019 12:24:02 +0200 Subject: [PATCH] #2810 --- .../Controllers/CubistMagicController.php | 6 ++- .../CubistMagicControllerTrait.php | 4 ++ .../CubistMagicNestedController.php | 1 + .../Magic/Models/CubistMagicAbstractModel.php | 50 +++++++++++++------ src/resources/cubistmagic/Controller.stub | 1 + 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index 3cb4f25..b7ac730 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -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() + { } } diff --git a/src/app/Magic/Controllers/CubistMagicControllerTrait.php b/src/app/Magic/Controllers/CubistMagicControllerTrait.php index ede1b0c..d90ccc3 100644 --- a/src/app/Magic/Controllers/CubistMagicControllerTrait.php +++ b/src/app/Magic/Controllers/CubistMagicControllerTrait.php @@ -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); diff --git a/src/app/Magic/Controllers/CubistMagicNestedController.php b/src/app/Magic/Controllers/CubistMagicNestedController.php index 367ad89..101fdbd 100644 --- a/src/app/Magic/Controllers/CubistMagicNestedController.php +++ b/src/app/Magic/Controllers/CubistMagicNestedController.php @@ -14,6 +14,7 @@ class CubistMagicNestedController extends NestedModelsCrudController protected $_routeURL; protected $_singular; protected $_plural; + protected $_bulk; public function _postSetModel(){ $this->treeSetup(); diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index ed8d54f..7d25343 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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); diff --git a/src/resources/cubistmagic/Controller.stub b/src/resources/cubistmagic/Controller.stub index ca89dd3..555c957 100644 --- a/src/resources/cubistmagic/Controller.stub +++ b/src/resources/cubistmagic/Controller.stub @@ -11,4 +11,5 @@ class _CONTROLLERCLASS_ extends _EXTENDS_ protected $_singular = '_SINGULAR_'; protected $_plural = '_PLURAL_'; protected $_clonable = _CLONABLE_; + protected $_bulk = _BULK_; } -- 2.39.5