]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5721 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Feb 2023 13:44:26 +0000 (14:44 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 10 Feb 2023 13:44:26 +0000 (14:44 +0100)
app/Fluidbook/Links.php
app/Jobs/FluidbookDocumentUpload.php
composer.lock

index 8943c5a8459cdbcbd72da64634ecd5dc0de32a75..c94a86f8e63030ce96e1445718dace5e54c4bd7d 100644 (file)
@@ -2,11 +2,13 @@
 
 namespace App\Fluidbook;
 
+use App\Models\FluidbookPublication;
 use App\Models\User;
 use App\Util\wsDAOBook;
 use App\Util\wsDocument;
 use Cubist\Util\ArrayUtil;
 use Cubist\Util\Files\Files;
+use Cubist\Util\Gzip;
 use Cubist\Util\Str;
 use Fluidbook\Tools\Links\Link;
 use PhpOffice\PhpSpreadsheet\Cell\DataType;
@@ -388,28 +390,18 @@ class Links
 
     public static function addLinksFromPDF($book_id)
     {
-        global $core;
-
-        $daoBook = new wsDAOBook($core->con);
-        $pages = $daoBook->getPagesOfBook($book_id);
+        /** @var FluidbookPublication $book */
+        $book = FluidbookPublication::withoutGlobalScopes()->find($book_id);
 
         $booleans = array('video_loop', 'video_auto_start', 'video_controls', 'video_sound_on');
         $numbers = ['left', 'top', 'width', 'height'];
 
         $links = [];
 
-        foreach ($pages as $page => $info) {
-            $csv = wsDocument::getDir($info['document_id']) . '/p' . $info['document_page'] . '.csv';
-            if (!file_exists($csv) && file_exists($csv . '.gz')) {
-                $csv = 'compress.zlib://' . $csv . '.gz';
-            } elseif (!file_exists($csv)) {
-                continue;
-            }
-
-            $newformat = (filemtime($csv) > 1363685416);
-
-            $fp = fopen($csv, 'rb');
+        $pages = $book->getComposition();
 
+        foreach ($pages as $page => $doc) {
+            $fp = Gzip::fopen($book->getDocument($doc[0])->path('p' . $doc[1] . '.csv'));
             while (true) {
                 $line = fgetcsv($fp, 512, ';', '"');
                 // End of file
@@ -423,13 +415,7 @@ class Links
                 }
 
                 $link = [];
-                if ($newformat) {
-                    $cols = array('page' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'type' => '', 'to' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical', "inline" => true);
-                } else {
-                    $cols = array('page' => '', 'type' => '', 'to' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical');
-                }
-
-
+                $cols = array('page' => '', 'left' => '', 'top' => '', 'width' => '', 'height' => '', 'type' => '', 'to' => '', 'target' => '_blank', 'video_loop' => true, 'video_auto_start' => true, 'video_controls' => true, 'video_sound_on' => true, 'infobulle' => '', 'numerotation' => 'physical', "inline" => true);
                 $k = 0;
                 foreach ($cols as $col => $default) {
                     if (isset($line[$k])) {
@@ -438,7 +424,7 @@ class Links
                         } else if (in_array($k, $booleans)) {
                             $link[$col] = ($line[$k] == '1');
                         } else {
-                            $link[$col] = utf8_encode($line[$k]);
+                            $link[$col] = $line[$k];
                         }
                     } else {
                         $link[$col] = $default;
@@ -453,12 +439,13 @@ class Links
 
                 $link['display_area'] = '1';
                 $link['page'] = $page;
+                $link['uid'] = self::generateUID();
                 $links[] = $link;
             }
-
+            fclose($fp);
         }
 
-        self::saveLinksInFile($book_id, $core->user->utilisateur_id, 'Links imported from PDF', $links, []);
+        self::saveLinksInFile($book_id, backpack_user()->id, 'Links imported from PDF', $links);
     }
 
     public static function getLinksAndRulersFromExcelFile($path, &$links, &$rulers)
index 09a02826286caafb9fdd6e6fe52d63de5f065755..e66790bdb5f33f1659eafd53c7c5bb867d8632e6 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Jobs;
 
+use App\Fluidbook\Links;
 use App\Models\FluidbookDocument;
 use App\Models\User;
 use Illuminate\Support\Facades\Cache;
@@ -39,6 +40,7 @@ class FluidbookDocumentUpload extends Base
         try {
             FluidbookDocumentUpload::updateProgression($this->uploadID, $this->document->id, __('Début du traitement du document'), 1.25);
             $this->document->processUpload($this->uploadID, $sync);
+            Links::addLinksFromPDF($this->fluidbook_id);
         } catch (\Exception $e) {
             error_log($e);
         }
index 6dae228e0ad27884b5d2d82e819e53105f4844fd..9d2e41d644a966fdc2593da959641059b315f37e 100644 (file)
             "source": {
                 "type": "git",
                 "url": "git://git.cubedesigners.com/cubist_util.git",
-                "reference": "8ca0e77316c93612593605ede9b457208fe1ae1f"
+                "reference": "9c379ada28a41672fdaeae328c5d4ab1d1579ddc"
             },
             "dist": {
                 "type": "tar",
-                "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-dc542c.tar",
-                "reference": "8ca0e77316c93612593605ede9b457208fe1ae1f",
-                "shasum": "e61ff95f8167d578a732deeae83f8117cdbe11a6"
+                "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-54b85e.tar",
+                "reference": "9c379ada28a41672fdaeae328c5d4ab1d1579ddc",
+                "shasum": "8c7bf70c044f4493e179137292b0f59d79d57fcd"
             },
             "require": {
                 "cubist/net": "dev-master",
                 }
             ],
             "description": "Utilities class",
-            "time": "2023-01-30T10:26:43+00:00"
+            "time": "2023-02-10T13:34:52+00:00"
         },
         {
             "name": "cviebrock/eloquent-sluggable",