]> _ Git - cubist_cms-back.git/commitdiff
wip #2941 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Aug 2019 15:43:13 +0000 (17:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Aug 2019 15:43:13 +0000 (17:43 +0200)
src/app/Magic/Fields/Field.php
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Magic/Models/News.php

index 4c9ca0ef6e1b76947f3c656763bb1cb361ee044d..ccbc3c2351d3db1fa07e1396ff51d8e7d8ef370b 100644 (file)
@@ -28,6 +28,10 @@ class Field implements \ArrayAccess
     protected $_cast = false;
     protected $_translatable = false;
 
+    protected $_elastic = false;
+    protected $_elasticType = 'string';
+    protected $_elasticAnalyser = 'standard';
+
     /**
      * @var CubistMagicAbstractModel
      */
@@ -98,8 +102,9 @@ class Field implements \ArrayAccess
         return ['type' => $this->_adminType, 'view_namespace' => $this->_viewNamespace, 'column' => false, 'form' => 'both', 'rules' => '',
             'fillable' => true, 'guarded' => false, 'hidden' => false, 'translatable' => $this->_translatable,
             'column_type' => $this->_columnType, 'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
+            'elastic' => $this->_elastic, 'elastic_type' => $this->_elasticType, 'elastic_analyser' => $this->_elasticAnalyser,
             'allow_null' => true,
-            'fake' => false, 'store_in' => 'extras', 'attributes' => [],];
+            'fake' => false, 'store_in' => 'extras', 'attributes' => []];
     }
 
     public function __construct($attributes)
@@ -182,6 +187,19 @@ class Field implements \ArrayAccess
         }
     }
 
+    public function getElasticMapping()
+    {
+        if (!$this->getAttribute('elastic', false)) {
+            return [];
+        }
+        return [$this->getAttribute('name') =>
+            [
+                'type' => $this->getAttribute('elastic_type'),
+                'analyser' => $this->getAttribute('elastic_analyser')
+            ]
+        ];
+    }
+
     /**
      * @return null|string
      */
index dc0e906c832596db396dddb963af89d93c186013..e631923b40572d632f322afff3d21cadc3f24175 100644 (file)
@@ -21,6 +21,7 @@ use Spatie\MediaLibrary\HasMedia\HasMedia;
 use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
 use Spatie\MediaLibrary\Models\Media;
 use Venturecraft\Revisionable\RevisionableTrait;
+use Elasticquent\ElasticquentTrait;
 
 class CubistMagicAbstractModel extends Model implements HasMedia
 {
@@ -36,6 +37,7 @@ class CubistMagicAbstractModel extends Model implements HasMedia
     use BunchOfFields {
         addField as protected bunchAddField;
     }
+    use ElasticquentTrait;
 
     protected static $_doctrineTypesMapping = ['int' => 'integer'];
 
@@ -75,6 +77,11 @@ class CubistMagicAbstractModel extends Model implements HasMedia
      */
     protected $varSetBeforeOperations = [];
 
+    /**
+     * @var array
+     */
+    protected $mappingProperties = [];
+
     public static function boot()
     {
         parent::boot();
@@ -220,6 +227,9 @@ class CubistMagicAbstractModel extends Model implements HasMedia
                 $this->translatable[] = $name;
             }
         }
+
+        $this->mappingProperties += $field->getElasticMapping();
+
         return $field;
     }
 
index e8667fca96282caaa646e7c05f3be59805ca4bfe..4ddf5924e960283ef26eeabdff4cbe8eb92be4c3 100644 (file)
@@ -20,7 +20,8 @@ class News extends CubistMagicModel
         $this->addField(['name' => 'title',
             'label' => 'Titre',
             'type' => 'Text',
-            'column' => true]);
+            'column' => true,
+            'elastic' => true,]);
 
         $this->addField(['name' => 'slug',
             'type' => 'Slug',
@@ -54,13 +55,15 @@ class News extends CubistMagicModel
             'type' => 'Text',
             'label' => 'Lieu de l\'événement',
             'when' => ['type' => ['event']],
+            'elastic' => true,
         ]);
 
         $this->addField(['name' => 'chapo',
             'type' => 'Textarea',
             'label' => 'Chapo',
             'hint' => 'Texte court affiché sur le listing des actualités',
-            'when' => ['type' => ['news']]
+            'when' => ['type' => ['news']],
+            'elastic' => true,
         ]);
 
         $this->addField(['name' => 'image',
@@ -69,7 +72,8 @@ class News extends CubistMagicModel
 
         $this->addField(['name' => 'content',
             'type' => 'Markdown',
-            'label' => 'Contenu'
+            'label' => 'Contenu',
+            'elastic' => true,
         ]);
 
         $this->addField(['name' => 'status',