From: Vincent Vanwaelscappel Date: Mon, 11 Sep 2023 14:54:19 +0000 (+0200) Subject: wait #6266 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=31b43d76011d8baa3b7860b94acb736cf9fe7407;p=fluidbook-toolbox.git wait #6266 @1 --- diff --git a/app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php b/app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php new file mode 100644 index 000000000..f4ecee353 --- /dev/null +++ b/app/Http/Controllers/Admin/Operations/Tools/FluidbookReferencesURL.php @@ -0,0 +1,112 @@ + '10 doigts', + 'ascocelda' => 'Asco & Celda', + 'wesco' => 'Wesco', + 'mopec' => 'Mopec', + 'intex' => 'Intex', + 'grosfillex' => 'Grosfillex']; + + public function fluidbookrefurl() + { + 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]); + + return view('tools.form', ['form' => $form]); + + } + + + public function dofluidbookrefurl() + { + global $core; + + + $file = request()->file('file'); + $type = request('type'); + if (!isset(self::$_db[$type])) { + abort(404, 'DB type not found'); + } + + if (strtolower($file->getClientOriginalExtension()) === 'xlsx') { + $reader = new Xlsx(); + } else if (strtolower($file->getClientOriginalExtension()) === 'csv') { + $reader = new Csv(); + $reader->setDelimiter(';'); + } + $xls = $reader->load($file->getPathname()); + $sheet = $xls->getSheet(0); + $maxRow = $sheet->getHighestRow('A'); + + $updated = 0; + + $add = []; + + for ($i = 1; $i <= $maxRow; $i++) { + $acell = $sheet->getCell('A' . $i); + $bcell = $sheet->getCell('B' . $i); + $ref = trim($acell->getOldCalculatedValue()) ?: trim($acell->getFormattedValue()); + $url = trim($bcell->getOldCalculatedValue()) ?: trim($bcell->getFormattedValue()); + + if ($url == '' || $ref == '') { + continue; + } + + $fref = self::_formatWsReferenceRef($ref, $type); + $furl = self::_formatWsReferenceUrl($url, $type); + + $add[$fref] = $furl; + } + + FluidbookReference::withoutGlobalScopes()->whereIn('ref', array_keys($add))->whereType($type)->forceDelete(); + + foreach ($add as $fref => $furl) { + $i = new FluidbookReference(['ref' => $fref, 'url' => $furl, 'type' => $type]); + $i->saveQuietly(); + $updated++; + } + return $this->_success(__(':updated liens insérés ou mis à jour', ['updated' => $updated])); + } + + public static function _formatWsReferenceRef($ref, $type) + { + if ($type === '10doigts') { + if (stripos($ref, 'ic') === 0) { + return 'C' . substr($ref, 2); + } + } + return $ref; + } + + public static function _formatWsReferenceUrl($url, $type) + { + return $url; + } + +} diff --git a/app/Http/Controllers/Admin/ToolsController.php b/app/Http/Controllers/Admin/ToolsController.php index afa953bc6..e8d9a027b 100644 --- a/app/Http/Controllers/Admin/ToolsController.php +++ b/app/Http/Controllers/Admin/ToolsController.php @@ -11,10 +11,10 @@ use App\Http\Controllers\Admin\Operations\Tools\FluidbookAssetsDownloader; use App\Http\Controllers\Admin\Operations\Tools\FluidbookBranchCreate; use App\Http\Controllers\Admin\Operations\Tools\FluidbookBranchRemove; use App\Http\Controllers\Admin\Operations\Tools\FluidbookCopyLinks; +use App\Http\Controllers\Admin\Operations\Tools\FluidbookReferencesURL; use App\Http\Controllers\Admin\Operations\Tools\GitReposCreate; use App\Http\Controllers\Admin\Operations\Tools\ImagesResizer; use App\Http\Controllers\Admin\Operations\Tools\JSON2Excel; -use App\Http\Controllers\Admin\Operations\Tools\PDF2SVGOperation; use App\Http\Controllers\Admin\Operations\Tools\SVGCleaner; use App\Http\Controllers\Admin\Operations\Tools\TextToSpeech; use App\Http\Controllers\Controller; @@ -33,6 +33,8 @@ class ToolsController extends Controller use ImagesResizer; use FluidbookCopyLinks; use SVGCleaner; + use FluidbookReferencesURL; + protected function index($tool, $args = '') { diff --git a/app/Models/FluidbookReference.php b/app/Models/FluidbookReference.php new file mode 100644 index 000000000..09173daae --- /dev/null +++ b/app/Models/FluidbookReference.php @@ -0,0 +1,25 @@ + 'fluidbook-reference-url', + 'singular' => 'référence', + 'plural' => 'références']; + + static $_permissionBase = 'fluidbook-reference-url'; + + public function setFields() + { + parent::setFields(); + $this->addField('ref', Text::class, __("Référence")); + $this->addField('type', Text::class, __("Type")); + $this->addField('url', URL::class, __('URL')); + } +} diff --git a/resources/views/tools/sidebar.blade.php b/resources/views/tools/sidebar.blade.php index 49507f3ee..dbeddf03d 100644 --- a/resources/views/tools/sidebar.blade.php +++ b/resources/views/tools/sidebar.blade.php @@ -33,6 +33,9 @@ +