]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 27 May 2019 15:19:45 +0000 (17:19 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 27 May 2019 15:19:45 +0000 (17:19 +0200)
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Models/CubistMagicModelAbstract.php
src/resources/cubistmagic/Controller.stub

index 4d2d2df15fa9937a80c1b41064663a953c6ec1fd..8573a5731c5173cf0767b70940989bbbf2471523 100644 (file)
@@ -3,21 +3,23 @@
 
 namespace Cubist\Backpack\app\Magic\Controllers;
 
-use Backpack\CRUD\app\Http\Controllers\CrudController;
 use Backpack\CRUD\CrudTrait;
 use Cubist\Backpack\app\Magic\Fields\Field;
 use Cubist\Backpack\app\Magic\Models\CubistMagicModelAbstract;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicStoreRequest;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
+use Webfactor\Laravel\Backpack\NestedModels\Controllers\NestedModelsCrudController;
+use Webfactor\Laravel\Backpack\NestedModels\Traits\NestedModelTrait;
 
-class CubistMagicController extends CrudController
+class CubistMagicController extends NestedModelsCrudController
 {
-    use CrudTrait;
+    use CrudTrait, NestedModelTrait;
 
     protected $_modelNamespace;
     protected $_routeURL;
     protected $_singular;
     protected $_plural;
+    protected $_nested = false;
 
     protected $_storeRequest;
     protected $_updateRequest;
@@ -37,6 +39,9 @@ class CubistMagicController extends CrudController
         |--------------------------------------------------------------------------
         */
         $this->crud->setModel($this->_modelNamespace);
+        if ($this->_nested) {
+            $this->treeSetup();
+        }
         $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
         $this->crud->setEntityNameStrings($this->_singular, $this->_plural);
 
index 4113b874447d4c3ec7139ca913b722b75adcf23c..8338b3c842ac6ca55526498a5283890b564c151a 100644 (file)
@@ -13,15 +13,17 @@ use Doctrine\DBAL\Schema\Table;
 use Illuminate\Database\Eloquent\Model;
 use Cubist\Backpack\app\Magic\CubistMagicAttribute;
 use Illuminate\Support\Str;
+use Webfactor\Laravel\Backpack\NestedModels\Traits\NestedModelTrait;
 
 class CubistMagicModelAbstract extends Model
 {
     use CubistMagicAttribute;
-    use CrudTrait;
+    use CrudTrait, NestedModelTrait;
     use Sluggable, SluggableScopeHelpers;
 
     protected static $_doctrineTypesMapping = ['int' => 'integer'];
 
+    protected $nested = false;
     protected $primaryKey = 'id';
     public $timestamps = true;
 
@@ -135,7 +137,8 @@ class CubistMagicModelAbstract extends Model
             'ROUTEURL' => $this->getOption('name'),
             'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
             'PLURAL' => $this->getOption('plural', ''),
-            'MODELNAMESPACE' => get_class($this)
+            'MODELNAMESPACE' => get_class($this),
+            'NESTED' => $this->nested ? 'true' : 'false',
         ];
 
         $res = file_get_contents($stub);
@@ -174,6 +177,16 @@ class CubistMagicModelAbstract extends Model
             $field->defineDbColumn($table);
         }
 
+        if ($this->nested) {
+            $table->addColumn('parent_id', 'integer', ['unsigned' => true, 'notnull' => false]);
+            $table->addIndex(['parent_id']);
+            $table->addColumn('lft', 'integer', ['unsigned' => true, 'default' => 0]);
+            $table->addIndex(['lft']);
+            $table->addColumn('rgt', 'integer', ['unsigned' => true, 'default' => 0]);
+            $table->addIndex(['rgt']);
+            $table->addColumn('depth', 'integer', ['unsigned' => true, 'default' => 0]);
+        }
+
         if ($this->timestamps) {
             $options = ['notnull' => false];
             $table->addColumn(static::CREATED_AT, 'date', $options);
index 8d405832121870efa48345cb92951bedf4675489..d7d0a2f1225cea805a3702148c5daf9a18e9e1b1 100644 (file)
@@ -10,4 +10,5 @@ class _CONTROLLERCLASS_ extends CubistMagicController
     protected $_routeURL = '_ROUTEURL_';
     protected $_singular = '_SINGULAR_';
     protected $_plural = '_PLURAL_';
+    protected $_nested = _NESTED_;
 }