]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6934 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 May 2024 17:06:46 +0000 (19:06 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 23 May 2024 17:06:46 +0000 (19:06 +0200)
app/Fluidbook/Stats.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php
public/packages/fluidbook/toolbox/css/stats.less
resources/views/fluidbook_stats/pagelink.blade.php
resources/views/fluidbook_stats/pagelink_user.blade.php [new file with mode: 0644]
resources/views/fluidbook_stats/stats.blade.php

index 5709850a07c290949da8d45dd9b344fbb733a290..011f8cb43d0b165eb17542ced1a135ee641bc936 100644 (file)
@@ -228,6 +228,7 @@ class Stats extends Reporting
         $this->viewData->countries = $this->_processCountries();
         $this->viewData->multimedia = $this->_processMultimedia();
         $this->viewData->shareDetails = $this->_processShareDetails();
+        $this->viewData->users = $this->_processUsers();
 
         //=== MAIN PERIOD STATISTICS
         // These are the main statistics used to build the chart and the table below it.
@@ -515,10 +516,31 @@ class Stats extends Reporting
         return collect($this->_eventsByPage['link']['subtable'] ?? [])->sortByDesc('nb_events');
     }
 
-    protected function _processMultimedia()
+    protected function _processUsers()
     {
-        $this->setCacheDuration(1);
+        $data = $this->apiCall('UserId.getUsers', ['flat' => 1, 'expanded' => 1, 'period' => 'range']);
+        $res = [];
+        foreach ($data as $u) {
+            $res[$u['label']] = ['userid' => $u['label'], 'nb_visits' => $u['nb_visits'], 'pages' => []];
+            try {
+                $pages = $this->apiCall('Actions.getPageUrls', ['period' => 'range', 'flat' => 1, 'segment' => 'userId==' . $u['label']]);
+                foreach ($pages as $page) {
+                    $e = explode('/', $page['label']);
+                    $pageNr = array_pop($e);
+                    if (!is_numeric($pageNr)) {
+                        continue;
+                    }
+                    $res[$u['label']]['pages'][] = $this->_getPageGroup($pageNr);
+                }
+            } catch (\Exception $e) {
 
+            }
+        }
+        return $res;
+    }
+
+    protected function _processMultimedia()
+    {
         $types = ['slideshow' => ['show'], 'video' => ['play'], 'youtube' => ['play'], 'dailymotion' => ['play'], 'vimeo' => ['show'], 'popup_image' => ['show'], 'popup_multimedia' => ['show']];
         $undefined = ['Nom d\'évènement indéfini'];
 
index de2498027458d013365669e57d3ad5a419433faf..e244358d7455c74cf0c3de7f594c64c69d20a4fe 100644 (file)
@@ -57,7 +57,7 @@ trait StatsOperation
             $u .= '&token_auth=' . rawurlencode($token) . '&cip=' . rawurlencode($_SERVER['HTTP_X_REAL_IP']);
         }
         file_get_contents(html_entity_decode($u));
-        return response('',204);
+        return response('', 204);
     }
 
     protected function setupStatsDefaults()
@@ -171,9 +171,13 @@ trait StatsOperation
                         $text = $td->getAttribute('data-flag');
                     } elseif ($td->getAttribute('sorttable_customkey')) {
                         $text = $td->getAttribute('sorttable_customkey');
+                    } else if ($td->getAttribute('data-excel-content')) {
+                        $text = $td->getAttribute('data-excel-content');
                     }
 
-                    $datas[$k][] = trim(preg_replace('/\s\s+/', ' ', $text));
+                    $text = trim(preg_replace('/\s\s+/', ' ', $text));
+
+                    $datas[$k][] = $text;
                 }
             }
 
index d88ae6f509529f28360e976aa4a7019c261defa9..44abf242424b6187b435f82589c6a4c9e452e471 100644 (file)
@@ -18,6 +18,15 @@ table.stats-details {
         text-overflow: ellipsis;
     }
 
+    .user-pages {
+        .with-aliases {
+            display: inline;
+            a.number {
+                display: inline;
+            }
+        }
+    }
+
     .with-aliases {
         .number {
             font-size: 75%;
@@ -145,7 +154,8 @@ table.stats-details {
 
     span {
         margin-right: 10px;
-        &:last-of-type{
+
+        &:last-of-type {
             margin-right: 0;
         }
     }
index ec7a257a78a23171656ff02b2425475179e7f7f3..e17efd2a54126c9a05efaf4e659e592e47199530 100644 (file)
@@ -4,23 +4,27 @@
     }
 @endphp
 
-<td data-name="page_group" sorttable_customkey="{{ $group['page_number']??0 }}">
-    @if($group)
-        @if(count($group['page_aliases'])>0)
-            <div class="with-aliases">
-                @foreach($group['page_aliases'] as $alias)
-                    <span class="alias">
+@if($td)
+    <td data-name="page_group" sorttable_customkey="{{ $group['page_number']??0 }}">
+        @endif
+        @if($group)
+            @if(count($group['page_aliases'])>0)
+                <div class="with-aliases">
+                    @foreach($group['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/{{ $group['page_number'] }}">{{$group['page_group']}}</a>
-                @if(count($group['page_aliases'])>0)
-            </div>
+                    @endforeach
+                    @endif
+                    <a class="number" target="_blank"
+                       href="{!! $fluidbookBaseURL !!}#/page/{{ $group['page_number'] }}">{{$group['page_group']}}</a>
+                    @if(count($group['page_aliases'])>0)
+                </div>
+            @endif
         @endif
-    @endif
-</td>
+        @if($td)
+    </td>
+@endif
diff --git a/resources/views/fluidbook_stats/pagelink_user.blade.php b/resources/views/fluidbook_stats/pagelink_user.blade.php
new file mode 100644 (file)
index 0000000..e17efd2
--- /dev/null
@@ -0,0 +1,30 @@
+@php
+    if($group && (is_string($group) || is_int($group))){
+        $group=$pages[$group];
+    }
+@endphp
+
+@if($td)
+    <td data-name="page_group" sorttable_customkey="{{ $group['page_number']??0 }}">
+        @endif
+        @if($group)
+            @if(count($group['page_aliases'])>0)
+                <div class="with-aliases">
+                    @foreach($group['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/{{ $group['page_number'] }}">{{$group['page_group']}}</a>
+                    @if(count($group['page_aliases'])>0)
+                </div>
+            @endif
+        @endif
+        @if($td)
+    </td>
+@endif
index 61fb07434cce3db4d27dbaba5e79b036c5ef95d2..0fcaa1ef35653ae99cd61215a3d0f8818c83ac11 100644 (file)
                             {{ $period_title['singular'] }}
                         </a>
                     @endforeach
-                        <form action="{{ route("generateexcel", compact('fluidbook_id', 'hash') + ['date'=>$start_date.','.$end_date, 'period_override'=>$period]) }}" method="POST">
-                            @csrf
-                            <button class="btn btn-primary ml-3" type="submit">{{ __('Exporter au format Excel') }}</button>
-                        </form>
+                    <form
+                        action="{{ route("generateexcel", compact('fluidbook_id', 'hash') + ['date'=>$start_date.','.$end_date, 'period_override'=>$period]) }}"
+                        method="POST">
+                        @csrf
+                        <button class="btn btn-primary ml-3" type="submit">{{ __('Exporter au format Excel') }}</button>
+                    </form>
                 </div>
             </div>
 
             </table>
 
             {{-- Stats segregated by page number --}}
-            <h3 data-title-excel="{{ __('Page') }}" class="mt-5">{{ __('Détails par page') }} <small>({!! $formatted_date_range !!})</small></h3>
+            <h3 data-title-excel="{{ __('Page') }}" class="mt-5">{{ __('Détails par page') }}
+                <small>({!! $formatted_date_range !!})</small></h3>
 
             <table class="{!! $tableClasses !!}">
                 <thead>
                     <tr>
                         @foreach (array_keys($table_map['per-page']) as $summary_key)
                             @if($summary_key === 'page_group')
-                                @include('fluidbook_stats.pagelink',['group'=>$page_data[$summary_key]])
+                                @include('fluidbook_stats.pagelink',['group'=>$page_data[$summary_key],'td'=>true])
                             @else
                                 <td data-name="{{ $summary_key }}">
                                     {!! is_int($page_data[$summary_key]) ? $formatter->format($page_data[$summary_key]) : $page_data[$summary_key] !!}
                                 <i class="{{$icons[$media['type']]}}"
                                    data-tooltip="{{$tooltips[$media['type']]}}"></i> {{$label }}
                             </td>
-                            @include('fluidbook_stats.pagelink',['group'=>$media['pages'][0]??''])
+                            @include('fluidbook_stats.pagelink',['group'=>$media['pages'][0]??'','td'=>true])
                             <td>{{ $formatter->format($media['nb']) }}</td>
                         </tr>
                     @endforeach
                             <tbody>
                             @foreach($countries as $key => $country)
                                 <tr>
-                                    <td data-flag="{{ $key }}" class="whitespace-nowrap" data-sort-value="{{ $country['label'] }}">
+                                    <td data-flag="{{ $key }}" class="whitespace-nowrap"
+                                        data-sort-value="{{ $country['label'] }}">
                                         <img src="{{ $country['flag'] }}" alt="{{ $country['label'] }}"
                                              style="width: 1.5em; margin-right: 0.75em;">
                                         {{ $country['label'] }}
 
             </div>
 
+            @if($users)
+                <div>
+                    <h3 data-title-excel="{{ __('Utilisateurs') }}">{{ __('Utilisateurs') }}</h3>
 
+                    <table class="{!! $tableClasses !!}">
+                        <thead>
+                        <tr>
+                            <th style="width: 30%;">{{ __('Identifiant') }}</th>
+                            <th style="width: 10%;" class="sorttable_sorted_reverse">{{ __('Visites') }}</th>
+                            <th style="width: 60%;">{{ __('Pages') }}</th>
+                        </tr>
+                        </thead>
+                        <tbody>
+                        @foreach($users as $userId => $user)
+                            <tr>
+                                <td class="whitespace-nowrap" data-sort-value="{{ $user['userid'] }}">
+                                    {{ $user['userid'] }}
+                                </td>
+                                <td>{{ $formatter->format($user['nb_visits']) }}</td>
+                                <td class="user-pages" data-excel-content="{{implode(', ',$user['pages'])}}">
+                                    @foreach($user['pages'] as $p)
+                                        @include('fluidbook_stats.pagelink_user',['group'=>$p,'td'=>false])
+                                        <br>
+                                    @endforeach
+                                </td>
+                            </tr>
+                        @endforeach
+                        </tbody>
+                    </table>
+                </div>
+
+            @endif
             {{-- It's possible for there to be no statistics returned by the API --}}
         @else
             <div class="no-statistics">