]> _ Git - cubist_cms-back.git/commitdiff
#2810
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Jun 2019 12:35:30 +0000 (14:35 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 12 Jun 2019 12:35:30 +0000 (14:35 +0200)
src/app/Console/Commands/MigrateCommand.php
src/app/Magic/Fields/Model.php
src/app/Magic/Fields/SelectFromModel.php
src/app/Magic/Fields/SelectFromModelMultiple.php

index 735cab9a3540c0d0f9b46b1c9497ce8a53dcf3dd..0fc1f451d57b3ba74a7b515540e82daba4e8fca1 100644 (file)
@@ -70,7 +70,7 @@ class MigrateCommand extends CubistCommand
         $this->line('Handling ' . get_class($model));
         $res=$model->setSchema($this->_schema);
         if(null!==$res) {
-            $this->line($res);
+            $this->line(print_r($res,true));
         }
     }
 }
index 9027522110d6bfe82f3273501fd67b7d6aff4c6f..11d8774842aad65c7f25678300402626e41507aa 100644 (file)
@@ -3,13 +3,14 @@
 
 namespace Cubist\Backpack\app\Magic\Fields;
 
+use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel;
+
 class Model extends Field
 {
     public function getColumnData()
     {
         $res = parent::getColumnData();
         $res['model'] = $this->getAttribute('model');
-        $res['entity'] = $this->getAttribute('entity');
         $res['attribute'] = $this->getAttribute('attribute');
         return $res;
     }
@@ -19,12 +20,17 @@ class Model extends Field
         return array_merge(parent::getDefaultAttributes(), ['attribute' => 'name', 'allow_null' => false, 'allow_multiples' => $this->_multiple]);
     }
 
-    protected function _postSetAttributes()
+    protected function _getOptions()
     {
-        $this->setAttributeIfNotSet('entity', $this->_getEntityPrefix() . $this->getAttribute('name'));
-    }
+        $modelClass = $this->getAttribute('model');
+        /** @var CubistMagicAbstractModel[] $items */
+        $items = $modelClass::all();
+        $options = [];
 
-    protected function _getEntityPrefix(){
-        return 'entity_';
+        $name = $this->getAttribute('attribute');
+        foreach ($items as $item) {
+            $options[$item->getPrimaryKey()] = $item->{$name};
+        }
+        return $options;
     }
 }
index ea3c9ea11b0661097559626f2c8318b4901344ad..4db6a3db3edd07e1d84d628b126a89029f1f2004 100644 (file)
@@ -6,13 +6,14 @@ namespace Cubist\Backpack\app\Magic\Fields;
 
 class SelectFromModel extends Model
 {
-    protected $_adminType = 'select2';
+    protected $_adminType = 'select2_from_array';
+    protected $_columnType = 'select_from_array';
     protected $_databaseType = 'text';
-    protected $_columnType = 'select';
     protected $_multiple = false;
 
-    public function getRelationship()
+    public function _postSetAttributes()
     {
-        return 'belongsTo';
+        parent::_postSetAttributes();
+        $this->setAttribute('options', $this->_getOptions());
     }
 }
index 0cffde1a797067d21c6f38796bf5b838ec185512..7187d09611de35129ab53c0dd4f75e69a5283a16 100644 (file)
@@ -6,19 +6,5 @@ namespace Cubist\Backpack\app\Magic\Fields;
 
 class SelectFromModelMultiple extends SelectFromModel
 {
-    protected $_adminType = 'select2_multiple';
-
-    public function getRelationship()
-    {
-        return 'belongsToMany';
-    }
-
-    public function getDefaultAttributes()
-    {
-        return array_merge(parent::getDefaultAttributes(), ['fillable' => false, 'pivot' => true]);
-    }
-
-    protected function _getEntityPrefix(){
-        return '';
-    }
+    protected $_multiple = true;
 }