From: Vincent Vanwaelscappel Date: Tue, 25 Jun 2019 14:30:38 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=926538c86f16b2db3d424cf44e4c0b18973364ba;p=cubist_cms-back.git #2843 --- diff --git a/src/app/Magic/Controllers/CubistMagicController.php b/src/app/Magic/Controllers/CubistMagicController.php index 457a24f..742562e 100644 --- a/src/app/Magic/Controllers/CubistMagicController.php +++ b/src/app/Magic/Controllers/CubistMagicController.php @@ -16,6 +16,7 @@ class CubistMagicController extends CubistCrudController protected $_singular; protected $_plural; protected $_bulk; + protected $_oneInstance; public function __construct() { diff --git a/src/app/Magic/Controllers/CubistMagicControllerTrait.php b/src/app/Magic/Controllers/CubistMagicControllerTrait.php index b8a5ae0..6e46b1b 100644 --- a/src/app/Magic/Controllers/CubistMagicControllerTrait.php +++ b/src/app/Magic/Controllers/CubistMagicControllerTrait.php @@ -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; } /** diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 1460251..25fbb31 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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) { diff --git a/src/app/Magic/Models/Settings.php b/src/app/Magic/Models/Settings.php index 54a697c..dabbaaf 100644 --- a/src/app/Magic/Models/Settings.php +++ b/src/app/Magic/Models/Settings.php @@ -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() { diff --git a/src/resources/cubistmagic/Controller.stub b/src/resources/cubistmagic/Controller.stub index 555c957..0c75b9c 100644 --- a/src/resources/cubistmagic/Controller.stub +++ b/src/resources/cubistmagic/Controller.stub @@ -12,4 +12,5 @@ class _CONTROLLERCLASS_ extends _EXTENDS_ protected $_plural = '_PLURAL_'; protected $_clonable = _CLONABLE_; protected $_bulk = _BULK_; + protected $_oneInstance= _ONEINSTANCE_; }