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') +