]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7782 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Oct 2025 17:24:15 +0000 (19:24 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Oct 2025 17:24:15 +0000 (19:24 +0200)
app/Fluidbook/SearchIndex.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/LinksOperation.php
app/Models/FluidbookPublication.php

index d5c3e67f951a3fe6d3fc94d6871abb73670c8792..819c1ba2e78e6c041749c9835b925691399c933f 100644 (file)
@@ -4,6 +4,7 @@ namespace App\Fluidbook;
 
 use App\Fluidbook\Compiler\Compiler;
 use App\Models\FluidbookDocument;
+use App\Models\FluidbookPublication;
 use Cubist\Util\Gzip;
 use Cubist\Util\PHP;
 
@@ -67,14 +68,25 @@ class SearchIndex
     }
 
     /**
-     * @param $compiler Compiler
+     * @param $compiler Compiler|FluidbookPublication
      * @return array
      */
     public static function makeHighlightIndex($compiler): array
     {
+
+        if ($compiler instanceof Compiler) {
+            $pages = $compiler->pages;
+            $fluidbook = $compiler->getFluidbook();
+        } else if ($compiler instanceof FluidbookPublication) {
+            $fluidbook = $compiler;
+            $pages = $fluidbook->getComposition();
+        }else{
+            return [];
+        }
+
         $res = [];
-        foreach ($compiler->pages as $page => $infos) {
-            $fby = $compiler->getFluidbook()->getHightlightFile($page);
+        foreach ($pages as $page => $infos) {
+            $fby = $fluidbook->getHightlightFile($page);
             $words = json_decode(Gzip::file_get_contents($fby), true);
 
             if (is_array($words)) {
index d22bc05b0729d9e8fa35abe701b110fc4cef0c94..90a5af34cdb0b30e6482eaefaeca1649e0f651d7 100644 (file)
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin\Operations\FluidbookPublication;
 
 // __('!!Paramètres des fluidbooks')
 
+use App\Fluidbook\Compiler\Compiler;
 use App\Fluidbook\Link\LinksData;
 use App\Http\Middleware\VerifyCsrfToken;
 use App\Models\FluidbookPublication;
@@ -289,6 +290,9 @@ trait LinksOperation
         $target = '_blank';
         $toPrefix = '';
         $toSuffix = '';
+        $skipFirst = true;
+        $vPadding = 0;
+        $hPadding = 0;
         switch ($rules) {
             case 'cart':
                 $type = \Fluidbook\Tools\Links\Link::CART;
@@ -296,16 +300,47 @@ trait LinksOperation
             case 'steelite':
                 $toSuffix = '?embed';
                 $target = '_popupiframe';
+                $hPadding = 2;
+                $vPadding = 4;
             case 'web':
             default:
                 break;
         }
 
         ExcelToArray::setCache(Files::mkdir('/tmp/exceltoarray'));
-        $excel = ExcelToArray::excelToAssoc($uploadedFile->getPathname());
-        dd($type, $target, $toSuffix, $excel);
+        $excel = ExcelToArray::excelToArrayKeyVal($uploadedFile->getPathname());
+        /** @var FluidbookPublication $fluidbook */
+        $fluidbook = FluidbookPublication::withoutGlobalScopes()->find($fluidbook_id);
+        $highlights = $fluidbook->getHightlightData();
+        $links = [];
+
+        foreach ($excel as $search => $url) {
+            if ($skipFirst) {
+                $skipFirst = false;
+                continue;
+            }
+
+            $search = mb_strtolower($search);
+
+            if (isset($highlights[$search])) {
+                foreach ($highlights[$search] as $o) {
+                    $uid = LinksData::generateUID();
+                    $links[$uid] = [
+                        'uid' => $uid,
+                        'page' => $o['page'],
+                        'left' => $o['x'] - $hPadding,
+                        'top' => $o['y'] - $o['height'] - $vPadding,
+                        'width' => $o['width'] + $hPadding * 2,
+                        'height' => $o['height'] + $vPadding * 2,
+                        'type' => $type,
+                        'target' => $target,
+                        'to' => $toPrefix . $url . $toSuffix,
+                    ];
+                }
+            }
+        }
 
-        LinksData::saveLinksInFile($fluidbook_id, backpack_user()->id, __("Ajouter des liens automatiques à partir du fichier :file", ['file' => $uploadedFile->getClientOriginalName()]) . ' ', $links, $rulers, [], []);
+        LinksData::saveLinksInFile($fluidbook_id, backpack_user()->id, __("Ajouter des liens automatiques à partir du fichier :file (règles :rule)", ['file' => $uploadedFile->getClientOriginalName(),'rule'=>$rules]) . ' ', $links, $rulers, [], []);
         return response()->json(['success' => 'ok']);
     }
 
index ea43c581b3817d2de3297bec7dc5aa5ba06f7e73..89b73061f7c3a661ec1316f75cb1049f18904693 100644 (file)
@@ -16,6 +16,7 @@ use App\Fluidbook\Farm;
 use App\Fluidbook\Link\Link;
 use App\Fluidbook\Link\LinksData;
 use App\Fluidbook\Region;
+use App\Fluidbook\SearchIndex;
 use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
 use App\Http\Controllers\Admin\Operations\ChangestatusOperation;
 use App\Http\Controllers\Admin\Operations\FluidbookPublication\AuditOperation;
@@ -456,6 +457,11 @@ class FluidbookPublication extends ToolboxStatusModel
         return self::_getDocument($compo[0])->getTextFile($compo[1], $type, $mode ?? $this->search_mode ?: 'standard', $this->textExtraction, $this->ignoreSearchSeparators);
     }
 
+    public function getHightlightData(): array
+    {
+        return SearchIndex::makeHighlightIndex($this);
+    }
+
     public function getHightlightFile($page)
     {
         $compo = $this->getComposition()[$page];