From: Vincent Vanwaelscappel Date: Thu, 19 Oct 2023 07:00:15 +0000 (+0200) Subject: wait #6427 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=14f9d87329d5b6176a96a8ab610e7332ed04ab03;p=fluidbook-toolbox.git wait #6427 @0.5 --- diff --git a/app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php b/app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php index 0f5f47712..3b7b807d6 100644 --- a/app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php +++ b/app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php @@ -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();