]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5626 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Dec 2022 16:00:20 +0000 (17:00 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Dec 2022 16:00:20 +0000 (17:00 +0100)
app/Http/Controllers/Admin/CrudController.php
app/Http/Controllers/Admin/CubemailsCrudController.php
app/Http/Controllers/Admin/FluidbookQuoteCrudController.php
app/Http/Controllers/Admin/Operations/FluidbookPublication/StatsOperation.php
app/Http/Controllers/Admin/TeamEmailsCrudController.php [new file with mode: 0644]
app/Http/Controllers/Admin/TeamLeaveCrudController.php [new file with mode: 0644]
app/Http/Controllers/Admin/TeamOvertimeCrudController.php [new file with mode: 0644]
app/Http/Controllers/Admin/UsersCrudController.php

index 560a9461f494d9a41e18dc8d16e10f35e24f32b9..bed63b7f768215171fc3636192d59f88ecb15db3 100644 (file)
@@ -19,7 +19,7 @@ class CrudController extends \Cubist\Backpack\Magic\Controllers\CubistMagicContr
     /*
        */
 
-    protected $_modelNamespace = 'App\Models\Base\ToolboxSettingsModel';
+    protected $_modelNamespace = 'App\Models\Base\ToolboxHRModel';
     protected $_routeURL = '';
     protected $_singular = '';
     protected $_plural = '';
index eabdd8f776b7addfb75f4826c9ab489f0e0fbddb..fbf743ef99b162ac3ef44ca3d59a9960dbfec6ec 100644 (file)
@@ -21,7 +21,7 @@ class CubemailsCrudController extends \Cubist\Backpack\Magic\Controllers\CubistM
        __('paramètres')
        */
 
-    protected $_modelNamespace = 'App\Models\CubedesignersEmails';
+    protected $_modelNamespace = 'App\Models\TeamEmails';
     protected $_routeURL = 'cubemails';
     protected $_singular = 'paramètre';
     protected $_plural = 'paramètres';
index 4520c3e58ee7f2f3f4bae983c8f090a897fbb13a..094637ac273b205807e41e0d1f392d49318c1c77 100644 (file)
@@ -10,6 +10,7 @@ class FluidbookQuoteCrudController extends \Cubist\Backpack\Magic\Controllers\Cu
        use \App\Http\Controllers\Admin\Operations\FluidbookQuote\AssignOperation;
        use \App\Http\Controllers\Admin\Operations\FluidbookQuote\CreateFromWebsite;
        use \App\Http\Controllers\Admin\Operations\FluidbookQuote\ConfirmAssignmentOperation;
+       use \App\Http\Controllers\Admin\Operations\FluidbookQuote\SpamOperation;
        
 
 
index f900f03bd1c7186b5dfd9fe04096a8b862ee40e8..e60cb62f8da68826cdeaa7814d79beb90548baa1 100644 (file)
@@ -61,14 +61,11 @@ trait StatsOperation
         $fluidbook_id = intval($fluidbook_id);
 
         if ($fluidbook_id < 21210) {
-            $server = 'stats3.fluidbook.com';
+            return 'stats3.fluidbook.com';
         } elseif ($fluidbook_id % 2 === 0) {
-            $server = 'stats4.fluidbook.com';
-        } else {
-            $server = 'stats5.fluidbook.com';
+            return 'stats4.fluidbook.com';
         }
-
-        return $server;
+        return 'stats5.fluidbook.com';
     }
 
     protected function getMatomoToken($server) : bool|string {
@@ -103,9 +100,24 @@ trait StatsOperation
         return $date_matches;
     }
 
+    // Since the report date can be in different formats (ie. YYYY, YYYY-MM or a full range)
+    // and this format determines the report mode (range, month or year), we have to figure out
+    // the mode and full starting and ending dates, as necessary
+    public function getReportSettings($date, $fluidbook) {
+        $date_matches = $this->parseDate($date);
+
+        // ...
+
+        // TODO: centralise all mode + start / end date logic here... then in the main report function, we can use the returned mode in a switch() statement to clean things up a lot.
+
+
+    }
+
     // Figure out the best period to use for the stats according to the date range
     public function determinePeriod($dates, $fluidbook) {
 
+        // TODO: refactor this into getReportSettings() so that this function can simply take the determined start and end dates, calculate the number of days and give an answer based on that. No extra logic to try to figure out which mode it is...
+
         // If no valid date range is given, use the Fluidbook's lifetime
         if (empty($dates) || !is_array($dates)) {
             $dates['start_date'] = $fluidbook->created_at->isoFormat('YYYY-MM-DD');
@@ -156,6 +168,7 @@ trait StatsOperation
         $locale = app()->getLocale();
         $base_URL = route('stats', compact('fluidbook_id', 'hash')); // Used by date range picker to update report URL
 
+        // If the Fluidbook ID + hash combination isn't found, a 404 response will be returned
         $fluidbook = FluidbookPublication::where('id', $fluidbook_id)->where('hash', $hash)->firstOrFail();
         $fluidbook_settings = json_decode($fluidbook->settings);
 
@@ -211,8 +224,8 @@ trait StatsOperation
             $start_date = $dates['start_date'];
             $end_date = $dates['end_date'];
             $date_range = "{$start_date},{$end_date}";
-            $formatted_date_range = Carbon::parse($start_date)->isoFormat('MMMM Do, YYYY') . ' &mdash; ' .
-                                    Carbon::parse($end_date)->isoFormat('MMMM Do, YYYY');
+            // $formatted_date_range = Carbon::parse($start_date)->isoFormat('MMMM Do, YYYY') . ' &mdash; ' .
+            //                         Carbon::parse($end_date)->isoFormat('MMMM Do, YYYY');
 
             // Human-friendly representation of the time span
             // Since our start and end dates are only in the format YYYY-MM-DD, the time defaults to midnight
@@ -220,8 +233,8 @@ trait StatsOperation
             // calculates until the *start* of the end_date, effectively excluding it. To get a clean result,
             // we add 1 day to the end date (setting time to 23:59:59 has undesired effects with the diff display)
             $report_timespan = Carbon::parse($start_date)->startOfDay()->diffForHumans(Carbon::parse($end_date)->addDay(), [
-                'syntax' => CarbonInterface::DIFF_ABSOLUTE,
-                'parts' => 3, // How much detail to go into (ie. years, months, days)
+                'syntax' => CarbonInterface::DIFF_ABSOLUTE, // Absolute means without "ago" added
+                'parts' => 3, // How many levels of detail to go into (ie. years, months, days, hours, etc)
                 'join' => true, // Join string with natural language separators for the locale
             ]);
 
@@ -235,8 +248,6 @@ trait StatsOperation
             $date_range = "{$start_date},{$year}-{$month}-{$last_day_of_month}";
             $end_date = ($month == date('m') && $year == date('Y')) ? date('Y-m-d') : "{$year}-{$month}-{$last_day_of_month}";
             $chart_heading .= '<span class="heading-subtitle">' . Carbon::parse($start_date)->isoFormat('MMMM YYYY') . '</span>';
-            $formatted_date_range = Carbon::parse($start_date)->isoFormat('Do') . ' &mdash; ' .
-                                    Carbon::parse($end_date)->isoFormat('Do MMMM, YYYY');
 
         } elseif (!empty($dates['start_year'])) { // Year view
             $mode = 'year';
@@ -244,38 +255,23 @@ trait StatsOperation
             $start_date = "{$year}-01-01";
             $date_range = "{$start_date},{$year}-12-31"; // Full range of specified year (guarantees a full chart, even if it's early in the current year)
             $end_date = $year == date('Y') ? date('Y-m-d') : "{$year}-12-31"; // If it's the current year, don't count future dates
-            $formatted_date_range = Carbon::parse($start_date)->isoFormat('MMMM Do, YYYY') . ' &mdash; ' .
-                                    Carbon::parse($end_date)->isoFormat('MMMM Do, YYYY');
             $chart_heading .= "<span class='heading-subtitle'>$year</span>";
 
         } else { // No valid dates specified, display the full data set
             $mode = 'overview';
             $start_date = $fluidbook->created_at->isoFormat('YYYY-MM-DD');
             $end_date = now()->isoFormat('YYYY-MM-DD');
-
-            // If the Fluidbook is recent, the range will be very short (eg. just a few days or a month), which makes the
-            // bar chart look strange due to lack of entries. There's no easy way to limit the width of the bar chart while
-            // retaining the responsiveness, so instead we fetch a longer period of stats, even if they'll be mostly empty.
-            if ($period === 'month' && $fluidbook->created_at->diffInMonths($end_date) < 12) { // For the overview, we want at least 12 months
-                //$date_range = 'last12'; // Special date that Matomo understands
-                // Originally this used the special "last12" setting that Matomo understands but this causes problems
-                // later when we need to fetch certain statistics with a period of "range" - real dates are needed.
-                // To make sure the populated bar graph data is at the left of the chart instead of the right,
-                // we fetch future dates (Matomo just returns empty values in this case)
-                // TODO: see if there's a more elegant solution to this, possibly in Chart.js
-                $end_date = $fluidbook->created_at->addMonths(12)->isoFormat('YYYY-MM-DD');
-            }
-
             $date_range = "{$start_date},{$end_date}"; // All data up until today's date
-            $formatted_date_range = $fluidbook->created_at->isoFormat('MMMM Do, YYYY') . ' &mdash; ' .
-                                    Carbon::now()->isoFormat('MMMM Do, YYYY');
             $chart_heading = __('Overview');
         }
 
+        $formatted_date_range = $this->formatDateRange($start_date, $end_date);
+
         //=== Set up Matomo Reporting API
         $report = $this->getReporting($fluidbook_id);
         $report->setDate($date_range);
         $report->setPeriod($period);
+        $report->setLanguage($locale); // Matomo will return translated data when relevant (eg. country names)
 
         // * Note about visits and page views:
         // Although Matomo records visits and page views (API: VisitsSummary.get & Actions.get), we don't use these
@@ -504,18 +500,13 @@ trait StatsOperation
         $period_details = $pagesByPeriod->filter(fn ($value, $key) => !empty($value)); // Remove any empty periods
 
         //=== CHART PREPARATION
-        // Format dates for display as labels on the x-axis
-        $labels = $pagesByPeriod->keys()->map(function ($label, $index) use ($period, $start_date, $end_date) {
-            return $this->formatDateForXAxis($label, $period, $start_date, $end_date);
+        // Format dates for display as labels on the x-axis and in the tooltips / tables
+        $tooltip_labels = $pagesByPeriod->keys()->mapWithKeys(function($date, $index) use ($period, $start_date, $end_date) {
+            $short_label = $this->formatDateForXAxis($date, $period, $start_date, $end_date);
+            $full_label = $this->formatDateForPeriod($date, $period);
+            return [$short_label => $full_label];
         })->toArray();
 
-        // Format dates for display in the tooltip title
-        $formatted_dates = $pagesByPeriod->keys()->map(function ($label, $index) use ($period) {
-            return $this->formatDateForPeriod($label, $period);
-        })->toArray();
-
-        $tooltip_labels = array_combine($labels, $formatted_dates);
-
         $chart_datasets = [
             [
                 'label' => __('Visits'),
@@ -596,11 +587,11 @@ trait StatsOperation
                 'hash',
                 'date',
                 'fluidbook',
+                'fluidbook_settings',
                 'start_date',
                 'end_date',
                 'report_timespan',
                 'page_count',
-                'labels',
                 'tooltip_labels',
                 'formatted_date_range',
                 'chart_heading',
@@ -634,7 +625,7 @@ trait StatsOperation
         $hash = $fluidbook->hash;
 
         if (!$fluidbook->stats) {
-            return "Statistics are disabled for this Fluidbook #{$fluidbook_id} ({$fluidbook->name})";
+            return "Statistics are disabled for this Fluidbook #{$fluidbook_id} ({$settings->title})";
         }
 
         return redirect()->route('stats', compact('fluidbook_id', 'hash'));
@@ -652,6 +643,33 @@ trait StatsOperation
         return view('fluidbook_stats.API', compact('matomo_tokens'));
     }
 
+    // Format a date range for display in the interface
+    protected function formatDateRange($start_date, $end_date): string {
+
+        $start = Carbon::parse($start_date);
+        $end = Carbon::parse($end_date);
+        $crosses_month_boundary = $end->isoFormat('YYYY-MM') > $start->isoFormat('YYYY-MM');
+        $crosses_year_boundary = $end->isoFormat('YYYY') > $start->isoFormat('YYYY');
+
+        // Default formatting for start and end dates according to Carbon isoFormat() function
+        $start_format = 'Do'; // Day with ordinal
+        $end_format = 'Do MMMM, YYYY';
+        $separator = $crosses_year_boundary || $crosses_month_boundary ? ' — ' : '—';
+
+        if ($crosses_year_boundary) {
+            // When a date range crosses a year boundary, we need to show the full dates
+            $start_format = 'MMMM Do, YYYY';
+            $end_format = 'MMMM Do, YYYY';
+        } elseif ($crosses_month_boundary) {
+            // When crossing a month boundary, show both month names
+            $start_format = 'MMMM Do';
+            $end_format = 'MMMM Do, YYYY';
+        }
+
+        return $start->isoFormat($start_format) . $separator . $end->isoFormat($end_format);
+    }
+
+
     // Format dates depending on the segregation period (used for tooltips and stats detail tables)
     protected function formatDateForPeriod($date, $period): string {
 
diff --git a/app/Http/Controllers/Admin/TeamEmailsCrudController.php b/app/Http/Controllers/Admin/TeamEmailsCrudController.php
new file mode 100644 (file)
index 0000000..6d05c64
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+class TeamEmailsCrudController extends \Cubist\Backpack\Magic\Controllers\CubistMagicController
+{
+    use \Cubist\Backpack\Magic\Operations\CreateOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\CloneEditOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\BulkPublishOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\ReviseOperation;
+       
+
+
+    /*
+       __('paramètre')
+       __('paramètres')
+       */
+
+    protected $_modelNamespace = 'App\Models\TeamEmails';
+    protected $_routeURL = 'team-emails';
+    protected $_singular = 'paramètre';
+    protected $_plural = 'paramètres';
+    protected $_oneInstance= true;
+}
diff --git a/app/Http/Controllers/Admin/TeamLeaveCrudController.php b/app/Http/Controllers/Admin/TeamLeaveCrudController.php
new file mode 100644 (file)
index 0000000..ef983bd
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+class TeamLeaveCrudController extends \Cubist\Backpack\Magic\Controllers\CubistMagicController
+{
+    use \Cubist\Backpack\Magic\Operations\CreateOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\CloneEditOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\BulkPublishOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\ReviseOperation;
+       
+
+
+    /*
+       __('absence')
+       __('congés et absence')
+       */
+
+    protected $_modelNamespace = 'App\Models\TeamLeave';
+    protected $_routeURL = 'team-leave';
+    protected $_singular = 'absence';
+    protected $_plural = 'congés et absence';
+    protected $_oneInstance= false;
+}
diff --git a/app/Http/Controllers/Admin/TeamOvertimeCrudController.php b/app/Http/Controllers/Admin/TeamOvertimeCrudController.php
new file mode 100644 (file)
index 0000000..cc2da0c
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+class TeamOvertimeCrudController extends \Cubist\Backpack\Magic\Controllers\CubistMagicController
+{
+    use \Cubist\Backpack\Magic\Operations\CreateOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\CloneEditOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\BulkPublishOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
+       use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
+       use \Cubist\Backpack\Http\Controllers\Operations\ReviseOperation;
+       
+
+
+    /*
+       __('heures supplémentaires')
+       __('heures supplémentaires')
+       */
+
+    protected $_modelNamespace = 'App\Models\TeamOvertime';
+    protected $_routeURL = 'team-overtime';
+    protected $_singular = 'heures supplémentaires';
+    protected $_plural = 'heures supplémentaires';
+    protected $_oneInstance= false;
+}
index f215fde9420e64deec688f112de1128a118a38a3..63ffb0d9f625957d96ac06be18f8ccdd3b96d120 100644 (file)
@@ -18,7 +18,7 @@ class UsersCrudController extends \Cubist\Backpack\Magic\Controllers\CubistMagic
        __('utilisateurs')
        */
 
-    protected $_modelNamespace = 'App\Models\User';
+    protected $_modelNamespace = 'App\Models\CubedesignersTeamMember';
     protected $_routeURL = 'users';
     protected $_singular = 'utilisateur';
     protected $_plural = 'utilisateurs';