From b792ee54f7449ddd6308527603f71dd342325b77 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 23 May 2024 19:06:46 +0200 Subject: [PATCH] wip #6934 @5 --- app/Fluidbook/Stats.php | 26 +++++++++- .../FluidbookPublication/StatsOperation.php | 8 ++- .../packages/fluidbook/toolbox/css/stats.less | 12 ++++- .../views/fluidbook_stats/pagelink.blade.php | 32 +++++++----- .../fluidbook_stats/pagelink_user.blade.php | 30 +++++++++++ .../views/fluidbook_stats/stats.blade.php | 51 ++++++++++++++++--- 6 files changed, 132 insertions(+), 27 deletions(-) create mode 100644 resources/views/fluidbook_stats/pagelink_user.blade.php diff --git a/app/Fluidbook/Stats.php b/app/Fluidbook/Stats.php index 5709850a0..011f8cb43 100644 --- a/app/Fluidbook/Stats.php +++ b/app/Fluidbook/Stats.php @@ -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']; diff --git a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php index de2498027..e244358d7 100644 --- a/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php +++ b/app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php @@ -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; } } diff --git a/public/packages/fluidbook/toolbox/css/stats.less b/public/packages/fluidbook/toolbox/css/stats.less index d88ae6f50..44abf2424 100644 --- a/public/packages/fluidbook/toolbox/css/stats.less +++ b/public/packages/fluidbook/toolbox/css/stats.less @@ -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; } } diff --git a/resources/views/fluidbook_stats/pagelink.blade.php b/resources/views/fluidbook_stats/pagelink.blade.php index ec7a257a7..e17efd2a5 100644 --- a/resources/views/fluidbook_stats/pagelink.blade.php +++ b/resources/views/fluidbook_stats/pagelink.blade.php @@ -4,23 +4,27 @@ } @endphp - - @if($group) - @if(count($group['page_aliases'])>0) -
- @foreach($group['page_aliases'] as $alias) - +@if($td) + + @endif + @if($group) + @if(count($group['page_aliases'])>0) +
+ @foreach($group['page_aliases'] as $alias) + {{$alias}} - @endforeach - @endif - {{$group['page_group']}} - @if(count($group['page_aliases'])>0) -
+ @endforeach + @endif + {{$group['page_group']}} + @if(count($group['page_aliases'])>0) +
+ @endif @endif - @endif - + @if($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 index 000000000..e17efd2a5 --- /dev/null +++ b/resources/views/fluidbook_stats/pagelink_user.blade.php @@ -0,0 +1,30 @@ +@php + if($group && (is_string($group) || is_int($group))){ + $group=$pages[$group]; + } +@endphp + +@if($td) + + @endif + @if($group) + @if(count($group['page_aliases'])>0) +
+ @foreach($group['page_aliases'] as $alias) + + + {{$alias}} + + + @endforeach + @endif + {{$group['page_group']}} + @if(count($group['page_aliases'])>0) +
+ @endif + @endif + @if($td) + +@endif diff --git a/resources/views/fluidbook_stats/stats.blade.php b/resources/views/fluidbook_stats/stats.blade.php index 61fb07434..0fcaa1ef3 100644 --- a/resources/views/fluidbook_stats/stats.blade.php +++ b/resources/views/fluidbook_stats/stats.blade.php @@ -124,10 +124,12 @@ {{ $period_title['singular'] }} @endforeach -
$start_date.','.$end_date, 'period_override'=>$period]) }}" method="POST"> - @csrf - -
+
$start_date.','.$end_date, 'period_override'=>$period]) }}" + method="POST"> + @csrf + +
@@ -166,7 +168,8 @@ {{-- Stats segregated by page number --}} -

{{ __('Détails par page') }} ({!! $formatted_date_range !!})

+

{{ __('Détails par page') }} + ({!! $formatted_date_range !!})

@@ -184,7 +187,7 @@ @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 - @include('fluidbook_stats.pagelink',['group'=>$media['pages'][0]??'']) + @include('fluidbook_stats.pagelink',['group'=>$media['pages'][0]??'','td'=>true]) @endforeach @@ -312,7 +315,8 @@ @foreach($countries as $key => $country) -
{!! is_int($page_data[$summary_key]) ? $formatter->format($page_data[$summary_key]) : $page_data[$summary_key] !!} @@ -236,7 +239,7 @@ {{$label }} {{ $formatter->format($media['nb']) }}
+ {{ $country['label'] }} {{ $country['label'] }} @@ -328,7 +332,38 @@ + @if($users) +
+

{{ __('Utilisateurs') }}

+ + + + + + + + + + @foreach($users as $userId => $user) + + + + + + @endforeach + +
{{ __('Identifiant') }}{{ __('Visites') }}{{ __('Pages') }}
+ {{ $user['userid'] }} + {{ $formatter->format($user['nb_visits']) }} + @foreach($user['pages'] as $p) + @include('fluidbook_stats.pagelink_user',['group'=>$p,'td'=>false]) +
+ @endforeach +
+
+ + @endif {{-- It's possible for there to be no statistics returned by the API --}} @else
-- 2.39.5