From f5a269d634f5af963ebaf8ac0ea1729af1263a6a Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Wed, 6 Sep 2017 16:08:38 +0100 Subject: [PATCH] #3: Added a quick and simple pie chart of cameras used in the gallery. Added an image to the "Albums" menu item. --- .../Gallery/StatisticsController.php | 70 +++++++++++++++++++ resources/lang/en/gallery.php | 7 +- resources/lang/en/navigation.php | 3 +- .../themes/base/gallery/statistics.blade.php | 59 ++++++++++++++++ .../themes/base/partials/navbar.blade.php | 5 +- routes/web.php | 2 + 6 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/Gallery/StatisticsController.php create mode 100644 resources/views/themes/base/gallery/statistics.blade.php diff --git a/app/Http/Controllers/Gallery/StatisticsController.php b/app/Http/Controllers/Gallery/StatisticsController.php new file mode 100644 index 0000000..f7f3835 --- /dev/null +++ b/app/Http/Controllers/Gallery/StatisticsController.php @@ -0,0 +1,70 @@ +where([ + ['camera_make', '!=', ''], + ['camera_model', '!=', ''] + ]) + ->groupBy('camera_make', 'camera_model') + ->select('camera_make', 'camera_model', DB::raw('count(*) as photo_count')) + ->orderBy('photo_count', 'desc') + ->get(); + + $labels = []; + $data = []; + + foreach ($stats as $stat) + { + // Remove the model from the make if it starts with it + // E.g. CANON - CANON EOS 1200D becomes just CANON EOS 1200D + if (substr($stat->camera_model, 0, strlen($stat->camera_make)) == $stat->camera_make) + { + $stat->camera_make = substr($stat->camera_make, strlen($stat->camera_make)); + } + + $labels[] = sprintf('%s %s', $stat->camera_make, $stat->camera_model); + $data[] = $stat->photo_count; + } + + return response()->json([ + 'labels' => $labels, + 'backgrounds' => $this->rotateColoursForData($data), + 'data' => $data + ]); + } + + public function index(Request $request) + { + return Theme::render('gallery.statistics'); + } + + private function rotateColoursForData(array $data = []) + { + $colours = ['#0F2240', '#174E79', '#287598', '#46BBB5', '#35DCAD']; + $result = []; + $lastIndex = 0; + + for ($i = 0; $i < count($data); $i++) + { + $result[] = $colours[$lastIndex]; + $lastIndex++; + if ($lastIndex >= count($colours)) + { + $lastIndex = 0; + } + } + + return $result; + } +} \ No newline at end of file diff --git a/resources/lang/en/gallery.php b/resources/lang/en/gallery.php index 3701e02..3d0cc28 100644 --- a/resources/lang/en/gallery.php +++ b/resources/lang/en/gallery.php @@ -14,5 +14,10 @@ return [ 'manage_album_link_2' => 'Manage Album', 'open_album_link' => 'Open Album', 'other_albums_description' => 'You may also be interested in the following albums.', - 'other_albums_heading' => 'More Albums in :album_name' + 'other_albums_heading' => 'More Albums in :album_name', + 'statistics' => [ + 'cameras' => 'Cameras Used', + 'intro' => 'This page displays some interesting graphs and statistics about :gallery_name.', + 'title' => 'Statistics' + ] ]; \ No newline at end of file diff --git a/resources/lang/en/navigation.php b/resources/lang/en/navigation.php index a6cbc24..a3af3ed 100644 --- a/resources/lang/en/navigation.php +++ b/resources/lang/en/navigation.php @@ -27,6 +27,7 @@ return [ 'change_password' => 'Change password', 'login' => 'Login', 'logout' => 'Logout', - 'register' => 'Register' + 'register' => 'Register', + 'statistics' => 'Statistics' ] ]; \ No newline at end of file diff --git a/resources/views/themes/base/gallery/statistics.blade.php b/resources/views/themes/base/gallery/statistics.blade.php new file mode 100644 index 0000000..369e6d7 --- /dev/null +++ b/resources/views/themes/base/gallery/statistics.blade.php @@ -0,0 +1,59 @@ +@extends('themes.base.layout') +@section('title', trans('gallery.statistics.title')) + +@section('breadcrumb') + + +@endsection + +@section('content') +
+
+
+

@lang('gallery.statistics.title')

+
+ @lang('gallery.statistics.intro', ['gallery_name' => UserConfig::get('app_name')]) +
+
+
+ +
+
+
+
@lang('gallery.statistics.cameras')
+
+ + +
+
+
+
+
+@endsection + +@push('scripts') + {{-- TODO: include ChartJS locally --}} + + +@endpush \ No newline at end of file diff --git a/resources/views/themes/base/partials/navbar.blade.php b/resources/views/themes/base/partials/navbar.blade.php index 66bf6a9..43e42c0 100644 --- a/resources/views/themes/base/partials/navbar.blade.php +++ b/resources/views/themes/base/partials/navbar.blade.php @@ -9,7 +9,7 @@ @if (count($albums) > 0) + @endif @if (!Auth::guest() && (Auth::user()->can('admin:access'))) diff --git a/routes/web.php b/routes/web.php index 9a138c6..2b3b571 100644 --- a/routes/web.php +++ b/routes/web.php @@ -69,6 +69,8 @@ Route::get('/activate/{token}', 'Auth\ActivateController@activate')->name('auth. Route::get('/password/change', 'Auth\ChangePasswordController@showChangePasswordForm')->name('auth.changePassword'); Route::post('/password/change', 'Auth\ChangePasswordController@processChangePassword')->name('auth.processChangePassword'); Route::get('/sitemap.xml', 'Gallery\DefaultController@sitemapXml'); +Route::get('/statistics', 'Gallery\StatisticsController@index')->name('statistics.index'); +Route::get('/statistics/cameras', 'Gallery\StatisticsController@camerasChart')->name('statistics.cameras'); Route::get('a/{albumUrlAlias}', 'Gallery\AlbumController@index') ->name('viewAlbum') ->where('albumUrlAlias', '.*');