From: Vincent Vanwaelscappel Date: Fri, 31 May 2019 14:48:55 +0000 (+0200) Subject: #2783 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9811ecdf510e0b50c7ce79a7b0b54f9b87fb4fc7;p=cubist_cms-back.git #2783 --- diff --git a/src/app/Magic/CubistMagicAttribute.php b/src/app/Magic/CubistMagicAttribute.php index ae42677..210df98 100644 --- a/src/app/Magic/CubistMagicAttribute.php +++ b/src/app/Magic/CubistMagicAttribute.php @@ -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; + } } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index 31e2d1e..afae70c 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -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 index 0000000..3ebc11a --- /dev/null +++ b/src/app/Magic/Fields/Model.php @@ -0,0 +1,27 @@ + '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 index 0000000..0040e58 --- /dev/null +++ b/src/app/Magic/Fields/SelectFromModel.php @@ -0,0 +1,14 @@ +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; } - - } diff --git a/src/app/Magic/Models/CubistMagicNestedModel.php b/src/app/Magic/Models/CubistMagicNestedModel.php index 73a767e..b5f8068 100644 --- a/src/app/Magic/Models/CubistMagicNestedModel.php +++ b/src/app/Magic/Models/CubistMagicNestedModel.php @@ -35,8 +35,8 @@ class CubistMagicNestedModel extends CubistMagicModel /** * @return string */ - protected function _getBaseController(){ + protected function _getBaseController() + { return 'CubistMagicNestedController'; } - }