]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Jun 2019 14:30:38 +0000 (16:30 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Jun 2019 14:30:38 +0000 (16:30 +0200)
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Controllers/CubistMagicControllerTrait.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/Settings.php
src/resources/cubistmagic/Controller.stub

index 457a24f0950c9e58715b142e04f093b171e34788..742562ee10f8668829ba5411db072c0045a808a6 100644 (file)
@@ -16,6 +16,7 @@ class CubistMagicController extends CubistCrudController
     protected $_singular;
     protected $_plural;
     protected $_bulk;
+    protected $_oneInstance;
 
     public function __construct()
     {
index b8a5ae020f6e1e283be43b1d38add97422bb8fda..6e46b1b2ce0a5529e082df3ccea205bae3128348 100644 (file)
@@ -11,6 +11,8 @@ use Illuminate\Support\Arr;
 
 trait CubistMagicControllerTrait
 {
+    protected $_fields = [];
+
     public function setup()
     {
         if (!$this->_routeURL) {
@@ -23,11 +25,20 @@ trait CubistMagicControllerTrait
         if ($this->_clonable) {
             $this->crud->allowAccess('clone');
         }
+
+        if($this->_oneInstance){
+            $this->crud->addClause('where', 'id', 1);
+            $this->crud->denyAccess(['create', 'delete']);
+        }else{
+            $this->crud->setCreateView('cubist_back::create');
+        }
+
         $this->crud->allowAccess('revisions');
         $this->crud->enablePersistentTable();
 
-        $this->crud->setCreateView('cubist_back::create');
+
         $this->crud->setEditView('cubist_back::edit');
+        $this->crud->enableExportButtons();
 //        $this->crud->with('revisionHistory');
 
 
@@ -59,7 +70,7 @@ trait CubistMagicControllerTrait
 
         $this->crud->addColumn(['name' => $model->getPrimaryKey(), 'type' => 'number', 'label' => "#", 'searchLogic' => 'text']);
 
-        $this->updateFieldsFromModel();
+        $this->updateFieldsFromModel($model);
 
     }
 
@@ -69,7 +80,7 @@ trait CubistMagicControllerTrait
             $model = $this->getModelInstance();
         }
         foreach ($model->getFields() as $field) {
-            if ($this->crud->hasField($field->getAttribute('name'))) {
+            if (isset($this->_fields[$field->getAttribute('name')])) {
                 continue;
             }
             $this->addField($field);
@@ -87,6 +98,8 @@ trait CubistMagicControllerTrait
             $this->crud->addColumn($field->getColumnData());
         }
         $this->crud->addField($field->getDefinition(), $field->getCRUDForm());
+
+        $this->_fields[$field->getAttribute('name')] = $field;
     }
 
     /**
index 1460251eec321a52b717bc3aa6c85159e6aa89f1..25fbb313cbef624f2b8beec365b3941d2a4e14da 100644 (file)
@@ -283,7 +283,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             'EXTENDS' => $this->_getBaseController(),
             'CLONABLE' => $this->clonable ? 'true' : 'false',
             'BULK' => $this->getOption('bulk', true) ? 'true' : 'false',
-        ];
+            'ONEINSTANCE' => $this->getOption('oneinstance', false) ? 'true' : 'false'];
 
         $res = file_get_contents($stub);
         foreach ($vars as $name => $value) {
index 54a697c2787edd0712f3b9ed223723baa185d60b..dabbaafaac0374e4f5c637c8f04c0df7c2e517e3 100644 (file)
@@ -9,8 +9,9 @@ class Settings extends CubistMagicModel
     protected $table = 'cubist_settings';
 
     protected $_options = ['name' => 'settings',
-        'singular' => 'setting',
-        'plural' => 'settings'];
+        'singular' => 'paramètre',
+        'plural' => 'paramètres',
+        'oneinstance' => true];
 
     public function setFields()
     {
index 555c9578bbf4612c5cbe1fc1e69231207e46384a..0c75b9c9b74992700451b8defbf0ac4e33344176 100644 (file)
@@ -12,4 +12,5 @@ class _CONTROLLERCLASS_ extends _EXTENDS_
     protected $_plural = '_PLURAL_';
     protected $_clonable = _CLONABLE_;
     protected $_bulk = _BULK_;
+    protected $_oneInstance= _ONEINSTANCE_;
 }