]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7784 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 9 Oct 2025 15:58:28 +0000 (17:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 9 Oct 2025 15:58:28 +0000 (17:58 +0200)
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
app/Models/Traits/PublicationSettings.php
resources/views/fluidbook_publication/link_editor.blade.php

index 867ac489f66a3400f9f6ba6eb82b778846189b3e..d22bc05b0729d9e8fa35abe701b110fc4cef0c94 100644 (file)
@@ -9,6 +9,7 @@ use App\Http\Middleware\VerifyCsrfToken;
 use App\Models\FluidbookPublication;
 use App\Models\User;
 use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
+use Cubist\Excel\ExcelToArray;
 use Cubist\Util\Files\Files;
 use Fluidbook\Tools\FluidbookFontToWoff;
 use Illuminate\Http\UploadedFile;
@@ -32,6 +33,7 @@ trait LinksOperation
         Route::match(['get'], $segment . '/{id}/edit/links/versions', $controller . '@getLinkVersions');
         Route::match(['get'], $segment . '/{id}/edit/links/versions/export/{version}', $controller . '@exportLinks');
         Route::match(['post'], $segment . '/{id}/edit/links/import/merge', $controller . '@importLinksMerge');
+        Route::match(['post'], $segment . '/{id}/edit/links/import/automatic', $controller . '@automaticLinks');
         Route::match(['post'], $segment . '/{id}/edit/links/import/replace', $controller . '@importLinks');
         Route::match(['get'], $segment . '/{id}/edit/links/import/pdf', $controller . '@importLinksFromPDF');
         Route::match(['post'], $segment . '/{id}/edit/links/move', $controller . '@moveLinks');
@@ -271,6 +273,42 @@ trait LinksOperation
         return response()->json(['success' => 'ok']);
     }
 
+    protected function automaticLinks($fluidbook_id)
+    {
+        if (!FluidbookPublication::hasPermission($fluidbook_id)) {
+            abort(401);
+        }
+
+        /** @var UploadedFile $uploadedFile */
+        $uploadedFile = request()->file('file');
+        LinksData::getLinksAndRulers($fluidbook_id, $links, $rulers);
+
+        $rules = FluidbookPublication::withoutGlobalScopes()->find($fluidbook_id)->autolinkRule;
+
+        $type = $type = \Fluidbook\Tools\Links\Link::WEB;
+        $target = '_blank';
+        $toPrefix = '';
+        $toSuffix = '';
+        switch ($rules) {
+            case 'cart':
+                $type = \Fluidbook\Tools\Links\Link::CART;
+                $target = '';
+            case 'steelite':
+                $toSuffix = '?embed';
+                $target = '_popupiframe';
+            case 'web':
+            default:
+                break;
+        }
+
+        ExcelToArray::setCache(Files::mkdir('/tmp/exceltoarray'));
+        $excel = ExcelToArray::excelToAssoc($uploadedFile->getPathname());
+        dd($type, $target, $toSuffix, $excel);
+
+        LinksData::saveLinksInFile($fluidbook_id, backpack_user()->id, __("Ajouter des liens automatiques à partir du fichier :file", ['file' => $uploadedFile->getClientOriginalName()]) . ' ', $links, $rulers, [], []);
+        return response()->json(['success' => 'ok']);
+    }
+
     protected function importLinksMerge($fluidbook_id)
     {
         if (!FluidbookPublication::hasPermission($fluidbook_id)) {
index b899eeeb55573b72709c77bfcccac0e7c4ed0170..ef550eaa5ab6fadc8233c6ed6d4cde81bf0c77f1 100644 (file)
@@ -1088,7 +1088,7 @@ trait PublicationSettings
         $this->_addSettingField('', FormSeparator::class);
         $this->_addSettingField('linkFilePrefix', LongText::class, $this->__('Préfixer les liens de téléchargement'));
         $this->_addSettingField('', FormSeparator::class);
-        $this->_addSettingField('autolinkRule', SelectFromArray::class, $this->__('Règle pour l\'ajout des liens via excel'), ['options' => ['web' => 'Lien web', 'cart' => __('Lien panier'), 'steelite' => 'Steelite']]);
+        $this->_addSettingField('autolinkRule', SelectFromArray::class, $this->__('Règle pour l\'ajout des liens via excel'), ["default" => "web", 'options' => ['web' => 'Lien web', 'cart' => __('Lien panier'), 'steelite' => 'Steelite']]);
     }
 
     protected function _multimedia()
index 3588bd199b15fa3ae103dfb135463cc1b2dfe9f1..d1e08186dbd1d80c44cbbbef38789ab342fd3f6c 100644 (file)
@@ -81,6 +81,7 @@
         'upload_save_message'=>__("Après l'upload d'un fichier"),
         'restore_version_tooltip'=>__('Restaurer cette version'),
         'export_version_tooltip'=>__('Exporter les liens au format xlsx'),
+        'automatic_links_from_excel'=>__('Détecter des liens à partir d\'un excel'),
         'delete_link'=>__('Supprimer le lien'),
         'edit_image_link'=>__('Editer les liens de l\'image'),
         'delete_selection'=>__('Supprimer la sélection'),
                     </div>
                     <a href="#" data-icon="import-links-pdf" data-action="links.importFromPDF"
                        data-tooltip="{{__('Importer les liens du PDF')}}"></a>
+                    <div data-icon="automatic-links"
+                         data-tooltip="{{__('Ajouter automatique des liens à partir d\'un excel')}}">
+                        <form class="importExcel"
+                              data-save-before-submit="{{__("Sauvegarde avant l'ajout automatique à partir d'un excel")}}"
+                              action="/fluidbook-publication/{{$fbdata['id']}}/edit/links/import/automatic" method="post"
+                              enctype="multipart/form-data">
+                            <input type="file"
+                                   accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
+                                   name="file"/>
+                        </form>
+                    </div>
                     <a id="linkeditor-export-latest" download="links_{{$fbdata['id']}}.xlsx"
                        href="/fluidbook-publication/{{$fbdata['id']}}/edit/links/versions/export/latest"
                        data-icon="export-links" data-tooltip="Exporter les liens"></a>