]> _ Git - fluidbook-toolbox.git/commitdiff
wait #6013 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 12 Jun 2023 11:57:52 +0000 (13:57 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 12 Jun 2023 11:57:52 +0000 (13:57 +0200)
app/Fluidbook/Compiler/Links.php
app/Fluidbook/Stats.php
app/Models/FluidbookPublication.php
resources/views/fluidbook_stats/loader.blade.php
resources/views/fluidbook_stats/summary.blade.php

index c08b8cac4f2c30aeec549538f1ce45023c3a8f67..ecc5b7215622ffb6294b2ce64b1591d510c823cb 100644 (file)
@@ -135,7 +135,7 @@ trait Links
 
 
         foreach ($linksCopy as $k => $linkData) {
-            if ($this->fluidbookSettings->PDFRendererIframe === 'svg' && (($linkData['type'] == Link::IFRAME && stristr($linkData['to'], '.pdf')) || ($linkData['type'] == Link::MULTIMEDIA && stristr($linkData['alternative'], '.pdf')))) {
+            if ($this->fluidbookSettings->PDFRendererIframe === 'svg' && (($linkData['type'] == Link::IFRAME && stristr($linkData['to'], '.pdf')) || ($linkData['type'] == Link::MULTIMEDIA && stristr($linkData['to'], '.pdf')))) {
                 $ofile = $this->wdir . '/' . $linkData['to'];
                 $dfile = $this->wdir . '/' . $linkData['to'] . '.svg';
                 if (!file_exists($dfile) || filemtime($dfile) < filemtime($ofile)) {
index dbc1e60c154c0e4615eeb03b955d3ec6ce5eb9ab..f90763346807129d165aca749cfc79260117c2a2 100644 (file)
@@ -265,8 +265,8 @@ class Stats extends Reporting
             [
                 'label' => __('Visites'),
                 'backgroundColor' => '#f54d00', // Could make bars semi-transparent if desired
-                'borderColor'=> '#000000',
-                'borderWidth'=> .75,
+                'borderColor' => '#000000',
+                'borderWidth' => .75,
                 'data' => $this->_pagesByPeriod->pluck('nb_visits')->toArray(),
                 'order' => 1,
                 'bar_offset' => -5, // Negative offset shifts bar to left
@@ -275,8 +275,8 @@ class Stats extends Reporting
             [
                 'label' => __('Pages vues'),
                 'backgroundColor' => '#514e49',
-                'borderColor'=> '#000000',
-                'borderWidth'=> .75,
+                'borderColor' => '#000000',
+                'borderWidth' => .75,
                 'data' => $this->_pagesByPeriod->pluck('nb_hits')->toArray(),
                 'order' => 2,
                 'bar_offset' => 5, // Positive offset shifts bar to right
@@ -290,8 +290,8 @@ class Stats extends Reporting
                 [
                     'label' => __('Visiteurs uniques'),
                     'backgroundColor' => 'hsl(72 100% 38% / 100%)',
-                    'borderColor'=> '#000000',
-                    'borderWidth'=> .75,
+                    'borderColor' => '#000000',
+                    'borderWidth' => .75,
                     'data' => $this->_pagesByPeriod->pluck('nb_uniq_visitors')->toArray(),
                     'order' => 1,
                     'bar_offset' => -8, // Negative offset shifts bar to left
@@ -528,9 +528,13 @@ class Stats extends Reporting
         $pageUrls = collect($this->getPageUrls(['period' => 'range', 'flat' => 1]))
             ->keyBy('label');
 
+        $pagesAlises = $this->fluidbook->getPagesAliases();
+
         //=== Group and combine page stats with related data
         $res = [];
         for ($page_number = 0; $page_number <= $this->fluidbook->getPagesNumber(); $page_number++) {
+            $aliases = $pagesAlises[$page_number] ?? [];
+
             if ($this->fluidbook->isOnePage()) {
                 $page_group = $page_number;
             } else {
@@ -550,6 +554,7 @@ class Stats extends Reporting
 
             $single_page_data = [
                 'page_group' => $page_group,
+                'page_aliases' => $aliases,
                 'page_number' => $page_number, // Used by table column sorter
                 'nb_pageviews' => $pageUrls["/page/$page_number"]['nb_hits'] ?? 0,
                 'nb_zooms' => data_get($this->_eventsByPage, "zoom.subtable.$page_number.nb_events", 0),
@@ -572,12 +577,18 @@ class Stats extends Reporting
         $res = [];
         foreach (func_get_args() as $array) {
             foreach ($array as $k => $v) {
-                if (!isset($res[$k])) {
-                    $res[$k] = 0;
-                }
-                if (is_numeric($v) && !in_array($k, $exclude)) {
+
+                if (is_array($v)) {
+                    if (!isset($res[$k])) {
+                        $res[$k] = [];
+                    }
+                    $res[$k] = array_unique(array_merge($res[$k], $v));
+                } else if (is_numeric($v) && !in_array($k, $exclude)) {
+                    if (!isset($res[$k])) {
+                        $res[$k] = 0;
+                    }
                     $res[$k] += $v;
-                } else {
+                } else if (!isset($res[$k])) {
                     $res[$k] = $v;
                 }
             }
index 5caf1c97915d41b1e92bc86d16dee73adcfc3ccc..8b2003c55aac16455a7565c2841d86a051c296ee 100644 (file)
@@ -11,6 +11,7 @@ use App\Fields\FluidbookStatus;
 use App\Fields\User;
 use App\Fluidbook\Compiler\Compiler;
 use App\Fluidbook\Farm;
+use App\Fluidbook\Link\Link;
 use App\Fluidbook\Link\LinksData;
 use App\Http\Controllers\Admin\Operations\ChangeownerOperation;
 use App\Http\Controllers\Admin\Operations\FluidbookPublication\CloneOperation;
@@ -778,4 +779,30 @@ class FluidbookPublication extends ToolboxSettingsModel
     {
         return !isset($this->assetsDir) || !$this->assetsDir ? $this->id : trim($this->assetsDir);
     }
+
+    /**
+     * @return array[]
+     */
+    public function getPagesAliases()
+    {
+        $res = [];
+        for ($i = 1; $i <= $this->getPagesNumber(); $i++) {
+            $res[$i] = [];
+        }
+        $this->getLinksAndRulers($links, $rulers);
+        foreach ($links as $link) {
+            if ($link['type'] !== Link::ANCHOR && $link['type'] !== Link::PAGE_LABEL) {
+                continue;
+            }
+            if (!isset($res[$link['page']])) {
+                continue;
+            }
+            $res[$link['page']][] = $link['to'];
+        }
+        return $res;
+    }
+
+    public function getPreviewURL(){
+        return route('fluidbook_preview',['version'=>'online','id'=>$this->id,'hash'=>$this->hash]);
+    }
 }
index c3a580f439155b2b422651da1593a2490bfc7177..268b82e76f9f661edb144da9b9e41111745254c6 100644 (file)
@@ -42,8 +42,8 @@
             background-color: #fafafa;
         }
 
-        table.stats-details thead th{
-            border-bottom: medium solid rgba(0,40,100,.12);
+        table.stats-details thead th {
+            border-bottom: medium solid rgba(0, 40, 100, .12);
         }
 
         [data-name="formatted_date"] {
             white-space: nowrap;
         }
 
+        .with-aliases .number {
+            font-size: 75%;
+            display: block;
+            font-style: italic;
+            margin-top: -2px;
+        }
+        .with-aliases .alias:after{
+            content:', ';
+        }
+        .with-aliases .alias:last-of-type:after{
+            content:'';
+        }
     </style>
 @endsection
 
index 163a5c73ee736f8ae7ad25609f9c2e7b7541871d..c5b830247a10e973e11c18b9239d963ec5cd4cb3 100644 (file)
@@ -4,6 +4,7 @@
 
 @php
     $tableClasses='stats-details sortable bg-white table table-striped table-hover nowrap rounded shadow-xs border-xs mt-2 dataTable dtr-inline';
+    $fluidbookBaseURL=$fluidbook->getPreviewURL();
 @endphp
 
 <h2 class="mt-4">
                 @foreach (array_keys($table_map['per-page']) as $summary_key)
                     <td data-name="{{ $summary_key }}"
                         @if($summary_key === 'page_group')sorttable_customkey="{{ $page_data['page_number'] }}"@endif>
-                        {!! is_int($page_data[$summary_key]) ? $formatter->format($page_data[$summary_key]) : $page_data[$summary_key] !!}
+                        @if($summary_key === 'page_group')
+                            @if(count($page_data['page_aliases'])>0)
+                                <div class="with-aliases">
+                                    @foreach($page_data['page_aliases'] as $alias)
+                                        <span class="alias"><a target="_blank"
+                                           href="{!! $fluidbookBaseURL !!}#/page/{{\Fluidbook\Tools\Links\AnchorLink::normalizeAnchor($alias)}}">{{$alias}}</a></span>
+                                    @endforeach
+                                    @endif
+                                    <a class="number" target="_blank"
+                                       href="{!! $fluidbookBaseURL !!}#/page/{{ $page_data['page_number'] }}">{{$page_data[$summary_key]}}</a>
+                                    @if(count($page_data['page_aliases'])>0)
+                                </div>
+                            @endif
+                        @else
+                            {!! is_int($page_data[$summary_key]) ? $formatter->format($page_data[$summary_key]) : $page_data[$summary_key] !!}
+                        @endif
                     </td>
                 @endforeach
             </tr>