]> _ Git - pmi.git/commitdiff
wait #7116 @0:10 nettoyage
authorsoufiane <soufiane@cubedesigners.com>
Mon, 14 Oct 2024 16:05:53 +0000 (18:05 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 14 Oct 2024 16:05:53 +0000 (18:05 +0200)
app/SubForms/News.php

index 137ea0a788c4d7fba9d3f9d279fe5a2f27c6a50b..d15498f7ca5233e0b6e304c8a246018b1e42e629 100644 (file)
@@ -46,7 +46,7 @@ class News extends SubForm
         $this->addField(['name' => 'page_product',
             'label' => 'Page produit',
             'type' => 'SelectFromArray',
-            'options' => self::products(request()->query('locale') ?? $this->defaultLang),
+            'options' => self::getDataByModel('catalog_products'),
             'multiple' => false,
             'default' => ''
         ]);
@@ -54,27 +54,24 @@ class News extends SubForm
         $this->addField(['name' => 'page_page',
             'label' => 'Page generale',
             'type' => 'SelectFromArray',
-            'options' => self::pages(request()->query('locale') ?? $this->defaultLang),
+            'options' => self::getDataByModel('cubist_cms_pages'),
             'multiple' => false,
         ]);
 
         $this->addField(['name' => 'page_news',
             'label' => 'Page actualités',
             'type' => 'SelectFromArray',
-            'options' => self::news(request()->query('locale') ?? $this->defaultLang),
+            'options' => self::getDataByModel('cubist_news'),
             'multiple' => false,
         ]);
     }
 
-    public function news($local) {
-        return DB::table('cubist_news')->whereNotNull("title->$local")->pluck("title->$local AS title",'id');
-    }
+    public function getDataByModel($table) {
+        $column = 'title';
+        $local = request()->query('locale') ?? $this->defaultLang;
 
-    public function products($local) {
-        return DB::table('catalog_products')->whereNotNull("name->$local")->pluck("name->$local AS name",'id');
-    }
+        if($table === 'catalog_products') $column = 'name';
 
-    public function pages($local) {
-        return DB::table('cubist_cms_pages')->whereNotNull("title->$local")->pluck("title->$local AS title",'id');
+        return DB::table($table)->whereNotNull("$column->$local")->pluck("$column->$local AS $column",'id');
     }
 }