]> _ Git - cubist_cms-back.git/commitdiff
#2783
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 31 May 2019 14:48:55 +0000 (16:48 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 31 May 2019 14:48:55 +0000 (16:48 +0200)
src/app/Magic/CubistMagicAttribute.php
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/Model.php [new file with mode: 0644]
src/app/Magic/Fields/SelectFromModel.php [new file with mode: 0644]
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/CubistMagicNestedModel.php

index ae426779e2f584ee293e0599763b6439ac33783e..210df98ac2301ad85021738a58a013f03e9f6226 100644 (file)
@@ -8,9 +8,19 @@ trait CubistMagicAttribute
 {
     public function getAttribute($key, $default = null)
     {
-        if (isset($this->_attributes[$key])) {
+        if ($this->hasAttribute($key)) {
             return $this->_attributes[$key];
         }
         return $default;
     }
+
+    public function hasAttribute($key)
+    {
+        return isset($this->_attributes[$key]);
+    }
+
+    public function setAttribute($key, $value)
+    {
+        $this->_attributes[$key] = $value;
+    }
 }
index 31e2d1e3af92776d75db6546e3c65f3cf9ef1f71..afae70c74729a7f8e33493295888993c895f434f 100644 (file)
@@ -69,6 +69,7 @@ class Field
     public function __construct($attributes)
     {
         $this->_attributes = array_merge($this->getDefaultAttributes(), $attributes);
+        $this->_postSetAttributes();
         $this->init();
     }
 
diff --git a/src/app/Magic/Fields/Model.php b/src/app/Magic/Fields/Model.php
new file mode 100644 (file)
index 0000000..3ebc11a
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+
+use Illuminate\Support\Str;
+
+class Model extends Field
+{
+    public function __construct($attributes)
+    {
+        parent::__construct($attributes);
+    }
+
+    public function getDefaultAttributes()
+    {
+        return array_merge(parent::getDefaultAttributes(), ['attribute' => 'name', 'allow_null' => false, 'allow_multiples' => $this->_multiple]);
+    }
+
+    protected function _postSetAttributes()
+    {
+        if (!$this->hasAttribute('entity')) {
+            $this->setAttribute('entity', $this->getAttribute('name'));
+        }
+    }
+}
diff --git a/src/app/Magic/Fields/SelectFromModel.php b/src/app/Magic/Fields/SelectFromModel.php
new file mode 100644 (file)
index 0000000..0040e58
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Fields;
+
+
+class SelectFromModel extends Model
+{
+    protected $_adminType = 'select2';
+    protected $_databaseType = 'string';
+    protected $_multiple = false;
+
+
+}
index 5dc422ec3dd16d8795f5ffa092ecd92468aac3a2..860d31f3592397b0de210d40ebdf07eceea869a1 100644 (file)
@@ -49,6 +49,12 @@ class CubistMagicAbstractModel extends Model
      */
     protected $translatable = [];
 
+
+    /**
+     * @var array
+     */
+    protected $_relationships = [];
+
     public function __construct(array $attributes = [])
     {
         $this->setFields();
@@ -121,11 +127,16 @@ class CubistMagicAbstractModel extends Model
      */
     public function addField($attributes)
     {
+
+
         /** @var Field $field */
         $field = Field::getInstance($attributes);
+        if (isset($attributes['relationship'])) {
+            $this->_addRelationship($field, $attributes['relationship']);
+        }
+
         $name = $field->getAttribute('name');
         $this->_fields[$name] = $field;
-
         if ($field->getAttribute('fillable')) {
             $this->fillable[] = $name;
         }
@@ -140,6 +151,11 @@ class CubistMagicAbstractModel extends Model
         }
     }
 
+    protected function _addRelationship($field, $relationship)
+    {
+        $this->_relationships[] = ['field' => $field, 'relationship' => $relationship];
+    }
+
     public function generateCode()
     {
         $this->_generateControllerCode();
@@ -224,6 +240,13 @@ class CubistMagicAbstractModel extends Model
         $this->replicateSluggable($except);
     }
 
+    public function __call($method, $parameters)
+    {
+        if (stristr())
+
+            return parent::__call($method, $parameters);
+    }
+
     public static function toDoctrineType($type)
     {
         if (isset(self::$_doctrineTypesMapping[$type])) {
@@ -231,6 +254,4 @@ class CubistMagicAbstractModel extends Model
         }
         return $type;
     }
-
-
 }
index 73a767e25a43137b7020b17f778db95d2748c468..b5f806848384e11ed864981785c33e27bb4a8356 100644 (file)
@@ -35,8 +35,8 @@ class CubistMagicNestedModel extends CubistMagicModel
     /**
      * @return string
      */
-    protected function _getBaseController(){
+    protected function _getBaseController()
+    {
         return 'CubistMagicNestedController';
     }
-
 }