From b49ec5f805fd47e0340aa76c0d05519d3a820d4e Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Thu, 4 Aug 2022 20:12:47 +0200 Subject: [PATCH] WIP #5316 @30 --- .../Admin/FluidbookStatsController.php | 33 ++- composer.json | 8 +- composer.lock | 80 +++++- resources/views/fluidbook_stats/API.blade.php | 229 ++++++++++++++++++ .../views/fluidbook_stats/summary.blade.php | 91 +++++++ routes/backpack/custom.php | 15 +- routes/web.php | 3 +- 7 files changed, 437 insertions(+), 22 deletions(-) create mode 100644 resources/views/fluidbook_stats/API.blade.php create mode 100644 resources/views/fluidbook_stats/summary.blade.php diff --git a/app/Http/Controllers/Admin/FluidbookStatsController.php b/app/Http/Controllers/Admin/FluidbookStatsController.php index ab77b39f4..8dad6405b 100644 --- a/app/Http/Controllers/Admin/FluidbookStatsController.php +++ b/app/Http/Controllers/Admin/FluidbookStatsController.php @@ -12,22 +12,24 @@ use Cubist\Matomo\Reporting; class FluidbookStatsController extends Controller { - private function _getReporting($fluidbook_id) - { - // Get the appropriate server / API token based on the Fluidbook ID - // Stats are split across different servers depending on the ID: - // ID < 21210 = stats3.fluidbook.com - // ID >= 21210 (even numbers) = stats4.fluidbook.com - // ID >= 21211 (odd numbers) = stats5.fluidbook.com - + public static function getMatomoTokens() { // Each stats server has a different instance of Matamo, so we need to provide different API tokens for each // Normally this information would be stored in the .env but there's no good way to do that with an array, so // it is simpler to keep it here. These are also stored in the shared Bitwarden entry for Matomo. - $matomo_tokens = [ + return [ 'stats3.fluidbook.com' => '9df722a0bd30878ddc4d737352427502', 'stats4.fluidbook.com' => '3ffdbe052ae625f065573df9fa9515df', 'stats5.fluidbook.com' => '85e9cc307b6e5083249949e9472a80b8', ]; + } + + private function _getReporting($fluidbook_id) + { + // Get the appropriate server / API token based on the Fluidbook ID + // Stats are split across different servers depending on the ID: + // ID < 21210 = stats3.fluidbook.com + // ID >= 21210 (even numbers) = stats4.fluidbook.com + // ID >= 21211 (odd numbers) = stats5.fluidbook.com $fluidbook_id = intval($fluidbook_id); @@ -41,6 +43,8 @@ class FluidbookStatsController extends Controller //dump("Server is $server"); + $matomo_tokens = self::getMatomoTokens(); + return new Reporting("https://{$server}/", $matomo_tokens[$server]); } @@ -155,5 +159,16 @@ class FluidbookStatsController extends Controller } + protected function API() { + + if (!can('superadmin')) { + // Only allow superadmin access because this is a dev tool and it exposes the API tokens + return response(null)->setStatusCode('403'); + } + + $matomo_tokens = json_encode(static::getMatomoTokens()); + + return view('fluidbook_stats.API', compact('matomo_tokens')); + } } diff --git a/composer.json b/composer.json index 10cf0f901..49df2639f 100644 --- a/composer.json +++ b/composer.json @@ -19,16 +19,19 @@ "license": "MIT", "require": { "php": ">=8.0", - "ext-json": "*", - "ext-simplexml": "*", + "ext-calendar": "*", "ext-dom": "*", + "ext-json": "*", "ext-libxml": "*", + "ext-simplexml": "*", "ext-tidy": "*", "ext-zip": "*", "ahmadshah/lucy": "dev-master", + "chartisan/php": "^1.2", "cubedesigners/userdatabase": "dev-master", "cubist/azuretts": "dev-master", "cubist/cms-back": "dev-master", + "cubist/matomo": "dev-master", "cubist/pdf": "dev-master", "cubist/scorm": "dev-master", "fluidbook/tools": "dev-master", @@ -37,7 +40,6 @@ "php-ffmpeg/php-ffmpeg": "^0.18.0", "phpoffice/phpspreadsheet": "^1.22", "rustici-software/scormcloud-api-v2-client-php": "^2.0" - }, "require-dev": { "facade/ignition": "^2.17", diff --git a/composer.lock b/composer.lock index f65d05dc1..3668170d6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c0e65b576302056a4929e45aaedd1971", + "content-hash": "37d4b92043ca0a35270b6f38d7ee16c1", "packages": [ { "name": "ahmadshah/lucy", @@ -1172,6 +1172,46 @@ ], "time": "2020-09-08T20:04:29+00:00" }, + { + "name": "chartisan/php", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/Chartisan/PHP.git", + "reference": "85d2352077800e9bcb411aec1ff7e4d23eef93a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Chartisan/PHP/zipball/85d2352077800e9bcb411aec1ff7e4d23eef93a1", + "reference": "85d2352077800e9bcb411aec1ff7e4d23eef93a1", + "shasum": "" + }, + "require": { + "php": ">=7.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "Chartisan\\PHP\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Èrik Campobadal Forés", + "email": "soc@erik.cat" + } + ], + "description": "Chartisan's PHP backend", + "support": { + "issues": "https://github.com/Chartisan/PHP/issues", + "source": "https://github.com/Chartisan/PHP/tree/1.2.1" + }, + "time": "2020-11-05T13:13:58+00:00" + }, { "name": "chrisjean/php-ico", "version": "1.0.4", @@ -1896,6 +1936,44 @@ "description": "Cubist Locale", "time": "2022-04-12T10:03:49+00:00" }, + { + "name": "cubist/matomo", + "version": "dev-master", + "source": { + "type": "git", + "url": "git://git.cubedesigners.com/cubist_matomo.git", + "reference": "6fc6532042481409ec54713b2967bea13b20f89d" + }, + "dist": { + "type": "tar", + "url": "https://composer.cubedesigners.com/dist/cubist/matomo/cubist-matomo-dev-master-7b4016.tar", + "reference": "6fc6532042481409ec54713b2967bea13b20f89d", + "shasum": "3a9d43421797356f9931b05a37f60da138e10ee3" + }, + "require": { + "ext-json": "*", + "guzzlehttp/guzzle": "^7.4.1", + "php": ">=7.2" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Cubist\\Matomo\\": "src" + } + }, + "license": [ + "proprietary" + ], + "authors": [ + { + "name": "Vincent Vanwaelscappel", + "email": "vincent@cubedesigners.com" + } + ], + "description": "Matomo API", + "time": "2022-06-15T10:09:17+00:00" + }, { "name": "cubist/net", "version": "dev-master", diff --git a/resources/views/fluidbook_stats/API.blade.php b/resources/views/fluidbook_stats/API.blade.php new file mode 100644 index 000000000..895b71ca5 --- /dev/null +++ b/resources/views/fluidbook_stats/API.blade.php @@ -0,0 +1,229 @@ +{{-- Matomo Stats API Helper --}} + + + + + + + Matomo API Explorer + + + + +
+ +
+
+ Matomo API + +
+ +
+ + + + + + +
+
+ +
+ +
+ + + + +{{----}} + + diff --git a/resources/views/fluidbook_stats/summary.blade.php b/resources/views/fluidbook_stats/summary.blade.php new file mode 100644 index 000000000..307b8d2ef --- /dev/null +++ b/resources/views/fluidbook_stats/summary.blade.php @@ -0,0 +1,91 @@ +@extends(backpack_view('blank')) + +@section('content') +

{{ __('Statistiques') }}

+ +
+
+
+ + @dump($fluidbook, $visits, $pageviews, $searches) + +@endsection + +@push('after_scripts') + {{-- Charting library --}} + + {{-- Chartisan --}} + + + + +@endpush diff --git a/routes/backpack/custom.php b/routes/backpack/custom.php index 2f11bb8c5..a6de6bff7 100644 --- a/routes/backpack/custom.php +++ b/routes/backpack/custom.php @@ -5,18 +5,17 @@ Route::group([ 'namespace' => 'App\Http\Controllers\Admin', ], function () { // custom admin routes try { + Route::crud('company', 'CompanyCrudController'); + Route::crud('fluidbook-publication', 'FluidbookPublicationCrudController'); + Route::crud('fluidbook-quote', 'FluidbookQuoteCrudController'); + Route::crud('fluidbook-theme', 'FluidbookThemeCrudController'); Route::crud('locale', 'LocaleCrudController'); Route::crud('settings', 'SettingsCrudController'); - Route::crud('quiztranslation', 'QuiztranslationCrudController'); - Route::crud('fluidbook-theme', 'FluidbookThemeCrudController'); - Route::crud('fluidbook-quote', 'FluidbookQuoteCrudController'); - Route::crud('quizatttempt', 'QuizatttemptCrudController'); + Route::crud('signature', 'SignatureCrudController'); Route::crud('toolbox-translate', 'ToolboxTranslateCrudController'); - Route::crud('fluidbook-publication', 'FluidbookPublicationCrudController'); Route::crud('quiz', 'QuizCrudController'); - Route::crud('signature', 'SignatureCrudController'); - Route::crud('users', 'UsersCrudController'); - Route::crud('company', 'CompanyCrudController'); + Route::crud('quizatttempt', 'QuizatttemptCrudController'); + Route::crud('quiztranslation', 'QuiztranslationCrudController'); Route::crud('users', 'UsersCrudController'); } catch (\Throwable $e) { diff --git a/routes/web.php b/routes/web.php index 7cd6cfcf3..bcb795198 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,5 +13,6 @@ Route::group([ Route::get('fluidbookthemepreview/{id}-burger.jpg', 'FluidbookThemePreviewController@previewBurger'); Route::get('fluidbookthemepreview/{id}-menu.jpg', 'FluidbookThemePreviewController@previewMenu'); Route::get('fluidbookthemepreview/{id}.jpg', 'FluidbookThemePreviewController@preview'); - + Route::get('fluidbook-stats/API', 'FluidbookStatsController@API'); + Route::get('fluidbook-stats/{fluidbook_id}/{date?}', 'FluidbookStatsController@summary'); }); -- 2.39.5