]> _ Git - cubist_cms-back.git/commitdiff
wip #3080 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Sep 2019 13:49:31 +0000 (15:49 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 25 Sep 2019 13:49:31 +0000 (15:49 +0200)
composer.json
src/app/Magic/Fields/Table.php
src/app/Magic/Menu/Item.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/CubistMagicModel.php [deleted file]
src/app/Magic/Models/CubistMagicPageModel.php
src/app/Magic/Models/CubistMagicTranslatableModel.php [new file with mode: 0644]
src/app/Magic/Models/Locale.php
src/app/Magic/Models/News.php
src/app/Magic/Models/Settings.php
src/app/Magic/Models/Translate.php

index 3c49936523bbc0fbde34224b9c0576e2baece0ed..e71026ece48338bb79eb3822428aab8510a94b4c 100644 (file)
@@ -43,8 +43,8 @@
         "league/commonmark-ext-autolink": "^1.0",
         "cviebrock/laravel-elasticsearch": "^3.6",
         "spatie/laravel-honeypot": "^1.3",
-        "chrisjean/php-ico": "^1.0"
-
+        "chrisjean/php-ico": "^1.0",
+        "ext-json": "*"
     },
     "require-dev": {
         "filp/whoops": "^2.3",
index 12b2503aa7351bb72af063c4be8e6a0435eaf045..87733ad1514633b1effa81d664daf9bcce35df24 100644 (file)
@@ -17,15 +17,21 @@ class Table extends Field
             return '[]';
         }
 
-        $string=is_string($value);
+        $string = is_string($value);
         if ($string) {
             $decoded = json_decode($value, 1);
         } else {
             $decoded = json_decode(json_encode($value), 1);
         }
+        if (null === $decoded) {
+            $decoded = [];
+        }
         $res = [];
 
         foreach ($decoded as $i => $item) {
+            if (is_string($item)) {
+                continue;
+            }
             if (!isset($item['id']) || $item['id'] == '') {
                 $item['id'] = $i;
             }
index 8bc23ee464f70da1f237333de018bbdcf5808d97..e14f8f43f637d34e5319b4edeb92308617c72721 100644 (file)
@@ -248,7 +248,7 @@ class Item
                 return $item;
             }
             /** @var $item PageItem */
-            if (stristr($item->getTemplate(), 'redirection')) {
+            if (stripos($item->getTemplate(), 'redirection') !== false) {
                 continue;
             }
             return $item;
index 26aaec124db2a90d2330f614dfb025205587930e..a6fb6c91c7ca50f928c6bcce6943efd3ab8ca8f6 100644 (file)
@@ -10,10 +10,9 @@ use Cubist\Backpack\app\Magic\Fields\Field;
 use Cubist\Backpack\app\Magic\PageData;
 use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
 use Cubist\Backpack\app\Magic\Util;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
-use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
 use Cubist\Util\Json;
+use Cviebrock\EloquentSluggable\Sluggable;
+use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
 use Doctrine\DBAL\Schema\Schema;
 use Doctrine\DBAL\Schema\Table;
 use Illuminate\Database\Eloquent\Model;
@@ -29,10 +28,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     use Sluggable;
     use SluggableScopeHelpers;
     use HasMediaTrait;
-    use HasTranslations {
-        update as protected updateTranslations;
-        create as protected createTranslations;
-    }
     use RevisionableTrait;
     use BunchOfFields {
         addField as protected bunchAddField;
@@ -59,11 +54,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
      */
     protected $_slugFields = ['slug', 'title', 'name'];
 
-    /**
-     * @var array
-     */
-    protected $translatable = [];
-
     /**
      * @var array
      */
@@ -136,7 +126,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         }
 
         $this->fakeColumns = array_unique($this->fakeColumns);
-        $this->translatable = array_unique($this->translatable);
     }
 
 
@@ -215,12 +204,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             }
             // 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($store_in, $this->fakeColumns)) {
                 $this->fakeColumns[] = $store_in;
             }
@@ -237,9 +220,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             if ($field->getAttribute('cast', false) !== false) {
                 $this->casts[$field->getAttribute('name')] = $field->getAttribute('cast');
             }
-            if ($field->getAttribute('translatable')) {
-                $this->translatable[] = $name;
-            }
         }
 
         return $field;
@@ -316,13 +296,13 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         try {
             $table->addColumn($this->primaryKey, self::toDoctrineType($this->keyType), ['autoincrement' => $this->incrementing, 'unsigned' => true]);
         } catch (\Exception $e) {
-            return $e->getMessage();
+
         }
 
         $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
 
         foreach ($this->_relationships as $relationship) {
-            if ($relationship->getRelationship() == 'belongsToMany') {
+            if ($relationship->getRelationship() === 'belongsToMany') {
 
                 $model = self::_toModel($relationship->getAttribute('model'));
 
@@ -336,7 +316,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         }
 
         foreach ($this->_fields as $field) {
-            if ($field->getRelationship() == 'belongsToMany') {
+            if ($field->getRelationship() === 'belongsToMany') {
                 continue;
             }
             if ($field->getAttribute('fake', false) !== false) {
@@ -477,10 +457,10 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     {
         $res = [];
         foreach ($attributes as $k => $attribute) {
-            if (stristr($k, '___')) {
+            if (strpos($k, '___') !== false) {
                 continue;
             }
-            if (stristr($k, 'bunchmultiple_')) {
+            if (stripos($k, 'bunchmultiple_') !== false) {
                 continue;
             }
             $res[$k] = $attribute;
@@ -488,24 +468,6 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $res;
     }
 
-    public function update(array $attributes = [], array $options = [])
-    {
-        return $this->updateTranslations($this->_prepareData($attributes), $options);
-    }
-
-    public function create(array $attributes = [])
-    {
-        return $this->createTranslations($this->_prepareData($attributes));
-    }
-
-    public function getSlugAttribute($value)
-    {
-        if (!$value) {
-            return Str::slug($this->title);
-        }
-        return $value;
-    }
-
     /**
      * @param $controller CubistMagicController
      */
diff --git a/src/app/Magic/Models/CubistMagicModel.php b/src/app/Magic/Models/CubistMagicModel.php
deleted file mode 100644 (file)
index 8fdb583..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace Cubist\Backpack\app\Magic\Models;
-
-class CubistMagicModel extends CubistMagicAbstractModel
-{
-
-}
index 61617d08c8e56b393fb1075faff8127d9e9a235f..b8f7f33a1849878eda51096b054a89ebcc7f1b0d 100644 (file)
@@ -4,7 +4,7 @@
 namespace Cubist\Backpack\app\Magic\Models;
 
 
-class CubistMagicPageModel extends CubistMagicModel
+class CubistMagicPageModel extends CubistMagicTranslatableModel
 {
     public function setFields()
     {
diff --git a/src/app/Magic/Models/CubistMagicTranslatableModel.php b/src/app/Magic/Models/CubistMagicTranslatableModel.php
new file mode 100644 (file)
index 0000000..71384de
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+
+namespace Cubist\Backpack\app\Magic\Models;
+
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\HasTranslations;
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\Sluggable;
+use Backpack\CRUD\ModelTraits\SpatieTranslatable\SluggableScopeHelpers;
+
+class CubistMagicTranslatableModel extends CubistMagicAbstractModel
+{
+    use Sluggable;
+    use SluggableScopeHelpers;
+    use HasTranslations {
+        update as protected updateTranslations;
+        create as protected createTranslations;
+    }
+
+    /**
+     * @var array
+     */
+    protected $translatable = [];
+
+    public function postSetFields()
+    {
+        parent::postSetFields();
+        $this->translatable = array_unique($this->translatable);
+    }
+
+    public function addField($attributes)
+    {
+        $field = parent::addField($attributes);
+        if ($field->getAttribute('fake', false) === true) {
+            if ($field->getAttribute('translatable')) {
+                if (!in_array($field->getAttribute('store_in'), $this->translatable)) {
+                    $this->translatable[] = $field->getAttribute('store_in');
+                }
+            }
+        } else {
+            if ($field->getAttribute('translatable')) {
+                $this->translatable[] = $field->getAttribute('name');
+            }
+        }
+
+        return $field;
+    }
+
+    public function update(array $attributes = [], array $options = [])
+    {
+        return $this->updateTranslations($this->_prepareData($attributes), $options);
+    }
+
+    public function create(array $attributes = [])
+    {
+        return $this->createTranslations($this->_prepareData($attributes));
+    }
+
+}
index 26ecb328b67b77fb7d3fea8686dc68a20259b31b..2fbe7299b9d7962a31f82aa9b7b577a2cbc0b193 100644 (file)
@@ -4,7 +4,7 @@
 namespace Cubist\Backpack\app\Magic\Models;
 
 
-class Locale extends CubistMagicModel
+class Locale extends CubistMagicAbstractModel
 {
     protected $table = 'cubist_locales';
 
@@ -38,5 +38,12 @@ class Locale extends CubistMagicModel
             'type' => 'Checkbox',
             'label' => 'Par défaut',
             'column' => true]);
+
+        $this->addField(['name' => 'domains',
+            'type' => 'Table',
+            'label' => 'Domaines',
+            'columns' => ['env' => 'Environnement', 'domain' => 'Domaine'],
+            'translatable' => false,
+        ]);
     }
 }
index f49646d4537c8f0c8a167dc53e580956fa745a4f..b96dd338e8b5e26f5f5c7148dac48e55c713739d 100644 (file)
@@ -3,8 +3,7 @@
 
 namespace Cubist\Backpack\app\Magic\Models;
 
-
-class News extends CubistMagicPageModel
+class News extends CubistMagicTranslatableModel
 {
 
     protected $table = 'cubist_news';
index 6981e67ab6b0898982d85a34d0ff52c58e358630..32b1036e772ba3c208ad8a419dd730d80caf1bd0 100644 (file)
@@ -7,7 +7,7 @@ use Cubist\Backpack\app\Http\Controllers\CubistPWAController;
 use Cubist\Backpack\app\Magic\PageData;
 use Spatie\MediaLibrary\Models\Media;
 
-class Settings extends CubistMagicModel
+class Settings extends CubistMagicTranslatableModel
 {
     /** @var PageData|null */
     protected static $_data = null;
index 379c61ff9f632dec8a3360cfcf1b4b6e2f153390..361bab90a7ab7be59c38aa47f4bf78f94d7637e3 100644 (file)
@@ -3,8 +3,7 @@
 
 namespace Cubist\Backpack\app\Magic\Models;
 
-
-class Translate extends CubistMagicModel
+class Translate extends CubistMagicTranslatableModel
 {
     protected $table = 'cubist_translate';