From: Vincent Vanwaelscappel Date: Thu, 4 Jul 2019 18:25:23 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=329b5af841bec4680c21d416823f167569c5b8c0;p=cubist_cms-back.git #2843 --- diff --git a/src/app/Http/Controllers/CubistPageCrudController.php b/src/app/Http/Controllers/CubistPageCrudController.php deleted file mode 100644 index 817acc0..0000000 --- a/src/app/Http/Controllers/CubistPageCrudController.php +++ /dev/null @@ -1,108 +0,0 @@ -getTemplates(); - - // set the default template - if ($template_name == false) { - $template_name = $templates[0]->getSlug(); - } - // actually use the template - if ($template_name) { - foreach ($templates as $template) { - if ($template->getSlug() == $template_name) { - $template->use($this->crud); - } - } - } - } - - // ----------------------------------------------- - // Methods that are particular to the PageManager. - // ----------------------------------------------- - - /** - * Populate the create/update forms with basic fields, that all pages need. - * - * @param string $template The name of the template that should be used in the current form. - */ - public function addDefaultPageFields($template = false) - { - $this->crud->addField([ - 'name' => 'template', - 'label' => trans('backpack::pagemanager.template'), - 'type' => 'select_page_template', - 'view_namespace' => 'pagemanager::fields', - 'options' => $this->getTemplatesArray(), - 'value' => $template, - 'allows_null' => false, - 'wrapperAttributes' => [ - 'class' => 'form-group col-md-6', - ], - 'tab' => 'General', - ]); - } - - - /** - * Get all defined template as an array. - * - * Used to populate the template dropdown in the create/update forms. - */ - public function getTemplatesArray() - { - $templates_array = []; - - $templates = $this->getTemplates(); - foreach ($templates as $template) { - if ($template->showInDropDown()) { - $slug = $template->getSlug(); - $name = $template->getName(); - $templates_array[$slug] = str_replace('_', ' ', Str::title($name)); - } - } - - return $templates_array; - } -} diff --git a/src/app/Magic/Models/CMSPage.php b/src/app/Magic/Models/CMSPage.php index 9a13b09..909a13f 100644 --- a/src/app/Magic/Models/CMSPage.php +++ b/src/app/Magic/Models/CMSPage.php @@ -91,8 +91,7 @@ class CMSPage extends CubistMagicNestedModel $template = request('template'); // if the template in the GET parameter is missing, figure it out from the db if ($template == false) { - $entry = self::findOrFail($id); - $template = $entry->template; + $template = self::getTemplatesById()[$id]; } $this->useTemplateIfNotSet($template); @@ -148,6 +147,15 @@ class CMSPage extends CubistMagicNestedModel } } + + public static function getTemplatesById() + { + if (null === self::$_templatesById) { + self::$_templatesById = DB::table(self::$_table)->get()->pluck('template', 'id'); + } + return self::$_templatesById; + } + /** * @param $schema Schema * @return Table @@ -178,7 +186,6 @@ class CMSPage extends CubistMagicNestedModel return parent::update($attributes, $options); } - public function setRawAttributes(array $attributes, $sync = false) { if (isset($attributes['template']) && null === $this->_usedTemplate) { @@ -196,4 +203,9 @@ class CMSPage extends CubistMagicNestedModel } return static::$_pagesList; } + + public function addFakes($columns = ['extras']) + { + return parent::addFakes($columns); + } } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 0c7df5c..5c420f0 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -192,10 +192,17 @@ class CubistMagicAbstractModel extends Model implements HasMedia if (!in_array($name, $this->fillable)) { $this->fillable[] = $name; } - $this->casts[$store_in] = 'array'; - if ($field->getAttribute('translatable') && !in_array($store_in, $this->translatable)) { - $this->translatable[] = $store_in; + // do not enable it again !! + // $this->casts[$store_in] = 'array'; + if ($field->getAttribute('translatable')) { + if (!in_array($store_in, $this->translatable)) { + $this->translatable[] = $store_in; + } + if (!in_array($name, $this->translatable)) { + $this->translatable[] = $name; + } } + if (!in_array($store_in, $this->fakeColumns)) { $this->fakeColumns[] = $store_in; } @@ -343,67 +350,67 @@ class CubistMagicAbstractModel extends Model implements HasMedia $table->addColumn('deleted_at', 'datetime', $options); } - public function __call($method, $parameters) - { - - // Set mutators - if (preg_match('/^set([a-zA-Z0-9]+)Attribute$/', $method, $matches)) { - $attr = Str::snake($matches[1]); - - if (isset($this->_fields[$attr])) { - $callback = [$this->_fields[$attr], 'setMutator']; - if (is_callable($callback)) { - return call_user_func_array($callback, $parameters); - } - } - } - - // magic call of relationships - foreach ($this->_relationships as $relationship) { - /** @var $relationship Field */ - if ($method == $relationship->getAttribute('entity')) { - return $this->relationship($relationship); - } - } - - return parent::__call($method, $parameters); - } - - /** - * @param $field Field|string - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\BelongsToMany - */ - public function relationship($field) - { - if (is_string($field)) { - foreach ($this->_fields as $f) { - if ($f->getAttribute('entity') == $field) { - $field = $f; - break; - } - } - } - switch ($field->getRelationship()) { - case 'belongsTo': - return $this->belongsTo($field->getAttribute('model'), $field->getAttribute('name')); - case 'belongsToMany': - return $this->belongsToMany($field->getAttribute('model'), $this->getRelationShipTable($field)); - } - } - - /** - * @param $field Field - * @return string - */ - public function getRelationShipTable($field) - { - /** @var Model $foreignEntity */ - $foreignEntity = self::_toModel($field->getAttribute('model')); - - if ($field->getRelationship() == 'belongsToMany') { - return $this->getTable() . '_' . $field->getAttribute('name') . '_rel_btm'; - } - } +// public function __call($method, $parameters) +// { +// +// // Set mutators +// if (preg_match('/^set([a-zA-Z0-9]+)Attribute$/', $method, $matches)) { +// $attr = Str::snake($matches[1]); +// +// if (isset($this->_fields[$attr])) { +// $callback = [$this->_fields[$attr], 'setMutator']; +// if (is_callable($callback)) { +// return call_user_func_array($callback, $parameters); +// } +// } +// } +// +// // magic call of relationships +// foreach ($this->_relationships as $relationship) { +// /** @var $relationship Field */ +// if ($method == $relationship->getAttribute('entity')) { +// return $this->relationship($relationship); +// } +// } +// +// return parent::__call($method, $parameters); +// } +// +// /** +// * @param $field Field|string +// * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|\Illuminate\Database\Eloquent\Relations\BelongsToMany +// */ +// public function relationship($field) +// { +// if (is_string($field)) { +// foreach ($this->_fields as $f) { +// if ($f->getAttribute('entity') == $field) { +// $field = $f; +// break; +// } +// } +// } +// switch ($field->getRelationship()) { +// case 'belongsTo': +// return $this->belongsTo($field->getAttribute('model'), $field->getAttribute('name')); +// case 'belongsToMany': +// return $this->belongsToMany($field->getAttribute('model'), $this->getRelationShipTable($field)); +// } +// } +// +// /** +// * @param $field Field +// * @return string +// */ +// public function getRelationShipTable($field) +// { +// /** @var Model $foreignEntity */ +// $foreignEntity = self::_toModel($field->getAttribute('model')); +// +// if ($field->getRelationship() == 'belongsToMany') { +// return $this->getTable() . '_' . $field->getAttribute('name') . '_rel_btm'; +// } +// } /** * @param $class Model|string