]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6427 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Oct 2023 07:00:15 +0000 (09:00 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Oct 2023 07:00:15 +0000 (09:00 +0200)
app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php

index 0f5f4771290a1f6ab797793e390d7ee1499a22da..3b7b807d6e9921397aff27914c8862d6863c5aa3 100644 (file)
@@ -38,26 +38,42 @@ trait FluidbookReferencesURL
     {
         ksort(self::$_db);
 
+
         $form = new Form(backpack_url('tools/dofluidbookrefurl'));
         $form->setEnctype('multipart/form-data');
         $form->setTitle(__('Importer une base de données de références Fluidbook'));
         $form->setSubmitLabel(__('Importer'));
         $form->setSubmitIcon('las la-link');
         $form->addField('file', StandardFile::class, __('Base de données'), ['accept' => '.xlsx;.csv', 'hint' => __('Feuille Excel ou CSV contenant deux colonnes.') . ' ' . __('Colonne A : Référence') . ', ' . __('Colonne B : URL')]);
-        $form->addField('type', SelectFromArray::class, __('Importer dans'), ['default' => '10doigts', 'allows_null' => false, 'options' => self::$_db]);
+        $form->addField('type', SelectFromArray::class, __('Importer dans'), ['default' => '10doigts', 'free' => true, 'allows_null' => false, 'options' => $this->_getOptions(), 'hint' => __('Si la base de données n\'existe pas encore, taper dans ce champ le nom du code pour en créer une nouvelle')]);
 
         return view('tools.form', ['form' => $form]);
 
     }
 
+    protected function _getOptions()
+    {
+        $keys = array_keys(self::$_db);
+        $res = self::$_db;
+        foreach (FluidbookReference::whereNotIn('type', $keys)->get() as $item) {
+            if (isset($res[$item->type])) {
+                continue;
+            }
+            $res[$item->type] = $item->type;
+        }
+        return $res;
+    }
+
+    protected static function _normalizeType($type)
+    {
+        return mb_strtolower(\Cubist\Util\Text::str2URL($type, ''));
+    }
+
 
     public function dofluidbookrefurl()
     {
         $file = request()->file('file');
-        $type = request('type');
-        if (!isset(self::$_db[$type])) {
-            abort(404, 'DB type not found');
-        }
+        $type = self::_normalizeType(request('type'));
 
         if (strtolower($file->getClientOriginalExtension()) === 'xlsx') {
             $reader = new Xlsx();