]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 4 Jul 2019 18:25:23 +0000 (20:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 4 Jul 2019 18:25:23 +0000 (20:25 +0200)
src/app/Http/Controllers/CubistPageCrudController.php [deleted file]
src/app/Magic/Models/CMSPage.php
src/app/Magic/Models/CubistMagicAbstractModel.php

diff --git a/src/app/Http/Controllers/CubistPageCrudController.php b/src/app/Http/Controllers/CubistPageCrudController.php
deleted file mode 100644 (file)
index 817acc0..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\app\Http\Controllers;
-
-use Backpack\PageManager\app\Http\Controllers\Admin\PageCrudController;
-use Cubist\Backpack\app\Template\TemplateAbstract;
-use Illuminate\Support\Str;
-
-class CubistPageCrudController extends PageCrudController
-{
-    protected static $_templates = null;
-
-    /**
-     * Get all defined templates.
-     * @return TemplateAbstract[]
-     */
-    public function getTemplates($template_name = false)
-    {
-        if (null === self::$_templates) {
-            $templates_root = app_path() . '/Templates';
-            $dr = opendir($templates_root);
-            while ($file = readdir($dr)) {
-                if ($file == '.' || $file == '..' || is_dir($templates_root . '/' . $file)) {
-                    continue;
-                }
-                $e = explode('.', $file);
-                $classname = '\\App\\Templates\\' . $e[0];
-                self::$_templates[] = new $classname();
-            }
-
-            if (!count(self::$_templates)) {
-                abort(503, trans('backpack::pagemanager.template_not_found'));
-            }
-        }
-        return self::$_templates;
-    }
-
-    /**
-     * Add the fields defined for a specific template.
-     *
-     * @param string $template_name The name of the template that should be used in the current form.
-     */
-    public function useTemplate($template_name = false)
-    {
-        $templates = $this->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;
-    }
-}
index 9a13b0976bce242c073cbac6fd74fa6a9ca178f0..909a13f9a03d6b3ceaf695e1c7c54889fcb5df8d 100644 (file)
@@ -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);
+    }
 }
index 0c7df5cddf3372dce34150754401f7818f658e8b..5c420f004f531f73093683aff15cbfdc42ad2bd1 100644 (file)
@@ -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