]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 27 May 2019 17:03:02 +0000 (19:03 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 27 May 2019 17:03:02 +0000 (19:03 +0200)
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Controllers/CubistMagicControllerTrait.php [new file with mode: 0644]
src/app/Magic/Controllers/CubistNestedMagicController.php [new file with mode: 0644]
src/app/Magic/Models/CubistMagicModelAbstract.php
src/resources/cubistmagic/Controller.stub

index 9c58e31933ed92b7ec33a50e3b7cbb8ae79f3f81..5910a08d23bea63f06b58abb1043170b0762ada1 100644 (file)
@@ -3,95 +3,15 @@
 
 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;
 
-class CubistMagicController extends NestedModelsCrudController
+class CubistMagicController extends CrudController
 {
-    use CrudTrait;
+    use CrudTrait,CubistMagicControllerTrait;
 
     protected $_modelNamespace;
     protected $_routeURL;
     protected $_singular;
     protected $_plural;
-    protected $_nested = false;
-
-    protected $_storeRequest;
-    protected $_updateRequest;
-
-    public function setup()
-    {
-        if (!$this->_routeURL) {
-            $this->_routeURL = $this->_singular;
-        }
-        if (!$this->_plural) {
-            $this->_plural = $this->_singular . 's';
-        }
-
-        /*
-        |--------------------------------------------------------------------------
-        | CrudPanel Basic Information
-        |--------------------------------------------------------------------------
-        */
-        $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);
-
-
-        /*
-        |--------------------------------------------------------------------------
-        | CrudPanel Configuration
-        |--------------------------------------------------------------------------
-        */
-        foreach ($this->getModelInstance()->getFields() as $field) {
-            $this->addField($field);
-        }
-
-    }
-
-    public function addField($field)
-    {
-        if (is_array($field)) {
-            $field = Field::getInstance($field);
-        }
-        /** @var $field Field */
-        if ($field->isDisplayColumn()) {
-            $this->crud->addColumn($field->getColumnData());
-        }
-        $this->crud->addField($field->getDefinition(), $field->getCRUDForm());
-    }
-
-    /**
-     * @return CubistMagicModelAbstract
-     */
-    public function getModelInstance()
-    {
-        return $this->crud->getModel();
-    }
-
-
-    public function store(CubistMagicStoreRequest $request)
-    {
-        // your additional operations before save here
-        $redirect_location = parent::storeCrud($request);
-        // your additional operations after save here
-        // use $this->data['entry'] or $this->crud->entry
-        return $redirect_location;
-    }
-
-    public function update(CubistMagicUpdateRequest $request)
-    {
-        // your additional operations before save here
-        $redirect_location = parent::updateCrud($request);
-        // your additional operations after save here
-        // use $this->data['entry'] or $this->crud->entry
-        return $redirect_location;
-    }
 }
diff --git a/src/app/Magic/Controllers/CubistMagicControllerTrait.php b/src/app/Magic/Controllers/CubistMagicControllerTrait.php
new file mode 100644 (file)
index 0000000..d44f414
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+
+namespace Cubist\Backpack\app\Magic\Controllers;
+
+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;
+
+trait CubistMagicControllerTrait
+{
+    public function setup()
+    {
+        if (!$this->_routeURL) {
+            $this->_routeURL = $this->_singular;
+        }
+        if (!$this->_plural) {
+            $this->_plural = $this->_singular . 's';
+        }
+
+        /*
+        |--------------------------------------------------------------------------
+        | CrudPanel Basic Information
+        |--------------------------------------------------------------------------
+        */
+        $this->crud->setModel($this->_modelNamespace);
+        $this->_afterSetModel();
+        $this->crud->setRoute(config('backpack.base.route_prefix') . '/' . $this->_routeURL);
+        $this->crud->setEntityNameStrings($this->_singular, $this->_plural);
+
+
+        /*
+        |--------------------------------------------------------------------------
+        | CrudPanel Configuration
+        |--------------------------------------------------------------------------
+        */
+        foreach ($this->getModelInstance()->getFields() as $field) {
+            $this->addField($field);
+        }
+
+    }
+
+    public function addField($field)
+    {
+        if (is_array($field)) {
+            $field = Field::getInstance($field);
+        }
+        /** @var $field Field */
+        if ($field->isDisplayColumn()) {
+            $this->crud->addColumn($field->getColumnData());
+        }
+        $this->crud->addField($field->getDefinition(), $field->getCRUDForm());
+    }
+
+    /**
+     * @return CubistMagicModelAbstract
+     */
+    public function getModelInstance()
+    {
+        return $this->crud->getModel();
+    }
+
+
+    public function store(CubistMagicStoreRequest $request)
+    {
+        // your additional operations before save here
+        $redirect_location = parent::storeCrud($request);
+        // your additional operations after save here
+        // use $this->data['entry'] or $this->crud->entry
+        return $redirect_location;
+    }
+
+    public function update(CubistMagicUpdateRequest $request)
+    {
+        // your additional operations before save here
+        $redirect_location = parent::updateCrud($request);
+        // your additional operations after save here
+        // use $this->data['entry'] or $this->crud->entry
+        return $redirect_location;
+    }
+
+
+}
diff --git a/src/app/Magic/Controllers/CubistNestedMagicController.php b/src/app/Magic/Controllers/CubistNestedMagicController.php
new file mode 100644 (file)
index 0000000..b2e86ab
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Controllers;
+
+use Backpack\CRUD\CrudTrait;
+use Webfactor\Laravel\Backpack\NestedModels\Controllers\NestedModelsCrudController;
+
+class CubistNestedMagicController extends NestedModelsCrudController
+{
+    use CrudTrait, CubistMagicControllerTrait;
+
+    protected $_modelNamespace;
+    protected $_routeURL;
+    protected $_singular;
+    protected $_plural;
+
+    public function _afterSetModel(){
+        $this->treeSetup();
+    }
+}
index 0ae20ce785e4c55830c85680958d94c754a50a78..8840436228720d2c255379fa33d2c4519dae68f3 100644 (file)
@@ -3,6 +3,7 @@
 
 namespace Cubist\Backpack\app\Magic\Models;
 
+use Backpack\CRUD\CrudTrait;
 use Cubist\Backpack\app\Magic\Fields\Field;
 use Cubist\Backpack\app\Magic\Util;
 use Cviebrock\EloquentSluggable\Sluggable;
@@ -17,6 +18,7 @@ class CubistMagicModelAbstract extends Model
 {
     use CubistMagicAttribute;
     use SluggableScopeHelpers;
+    use CrudTrait;
     use NestedModelTrait {
         replicate as private replicateNodeTrait;
     }
@@ -141,7 +143,7 @@ class CubistMagicModelAbstract extends Model
             'SINGULAR' => $this->getOption('singular', $this->getOption('name')),
             'PLURAL' => $this->getOption('plural', ''),
             'MODELNAMESPACE' => get_class($this),
-            'NESTED' => $this->nested ? 'true' : 'false',
+            'EXTENDS' => $this->nested ? 'CubistNestedMagicController' : 'CubistMagicController',
         ];
 
         $res = file_get_contents($stub);
index d7d0a2f1225cea805a3702148c5daf9a18e9e1b1..e0e025ab79ef21cc07886c05d67db67f751e760e 100644 (file)
@@ -2,13 +2,12 @@
 
 namespace App\Http\Controllers\Admin;
 
-use Cubist\Backpack\app\Magic\Controllers\CubistMagicController;
+use Cubist\Backpack\app\Magic\Controllers\*;
 
-class _CONTROLLERCLASS_ extends CubistMagicController
+class _CONTROLLERCLASS_ extends _EXTENDS_
 {
     protected $_modelNamespace = '_MODELNAMESPACE_';
     protected $_routeURL = '_ROUTEURL_';
     protected $_singular = '_SINGULAR_';
     protected $_plural = '_PLURAL_';
-    protected $_nested = _NESTED_;
 }