浏览代码

ot_stats: add the period selection

Olivier Massot 5 年之前
父节点
当前提交
e02cb63a34

+ 3 - 7
ot_stats/Classes/Controller/OtStatsController.php

@@ -38,15 +38,11 @@ class OtStatsController extends SelectedSiteController {
         }
         $this->view->assign('matomoSiteId', (int)$matomoId);
         $this->view->assign('matomoToken', self::MATOMO_TOKEN);
+        $args = $this->request->getArguments();
 
         // Default interval
-        $date_end = new \DateTime('today');
-        $date_start = clone $date_end;
-        $date_start->sub(new \DateInterval('P1M'));
-
-        $this->view->assign('date_start', $date_start);
-        $this->view->assign('date_end', $date_end);
-
+        $period = isset($args['period']) ? $args['period'] : 'month';
+        $this->view->assign('period', $period);
 
         // <-- Shall be removed when a fix is released for https://github.com/matomo-org/matomo/issues/16867
         $matomoRepository = GeneralUtility::makeInstance(MatomoWebsiteRepository::class);

+ 2 - 3
ot_stats/Resources/Private/Partials/ReportCard.html

@@ -9,8 +9,7 @@
    * {matomoToken}     (string)   the matomo's user token
    * {module}          (string)   the matomo 'moduleToWidgetize' parameter
    * {action}          (string)   the matomo 'actionToWidgetize' parameter
-   * {date_start}      (Datetime) The perdiod starting date
-   * {date_end}        (Datetime) The perdiod ending date
+   * {period}      (string)   The analysis period ('day', 'month' or 'year')
    * {additionalUrl}   (string)   [Optional] This string will be added at the end of the iframe's url without any formatting
    * {width}           (int)      [Optional] Override the default card width
    * {height}          (int)      [Optional] Override the default card height, and disable auto-resizing
@@ -30,7 +29,7 @@
 						&moduleToWidgetize={module}
 						&actionToWidgetize={action}
 						&idSite={matomoSiteId}
-						&period=month
+						&period={period}
 						&date=today
 						&token_auth={matomoToken}
 						{additionalUrl}"

+ 33 - 16
ot_stats/Resources/Private/Templates/OtStats/Index.html

@@ -8,11 +8,28 @@
         <h1>Statistiques d'utilisation</h1>
 
         <div id="matomoFilters">
-            Données affichées pour la période du
-                <b><f:format.date format="d/m/Y">{date_start}</f:format.date></b>
-                au
-                <b><f:format.date format="d/m/Y">{date_end}</f:format.date></b>
-            <a id="matomoFiltersEdit" href="" title="Modifier"><i class="fa fa-edit"></i></a>
+            <span>Période d'analyse: </span>
+            <f:form action="index">
+                <f:form.select class="form-control"
+                               name="period"
+                               options="{week: 'La semaine passée',
+                                         month: 'Le mois passé',
+                                         year: 'L\'année passée'}"
+                               value="{period}">
+                </f:form.select>
+
+                <f:comment><!--
+                Important: if the cache is not disabled,
+                 then the results won't be updated even after submitting this form
+                 --></f:comment>
+                <input type="hidden"
+                       name="no_cache"
+                       value="1">
+
+                <f:form.button type="submit" class="ot-btn">
+                    Actualiser
+                </f:form.button>
+            </f:form>
         </div>
 
         <div id="matomoReport">
@@ -23,19 +40,19 @@
                 <f:render partial="ReportCard"
                           arguments="{title: 'Visites en temps réel', id: 'realTimeVisits',
                                       module: 'Live', action: 'widget',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
 
                  <f:comment><!-- Last visits graph--></f:comment>
                 <f:render partial="ReportCard"
                           arguments="{title: 'Dernières visites', id: 'lastVisitsGraph',
                                       module: 'VisitsSummary', action: 'getEvolutionGraph',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
 
                 <f:comment><!-- Visits Summary --></f:comment>
                 <f:render partial="ReportCard"
                           arguments="{title: 'Résumé', id: 'visitsSummary',
                                       module: 'VisitsSummary', action: 'get',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
             </div>
 
             <div class="reportSection">
@@ -44,19 +61,19 @@
                 <f:render partial="ReportCard"
                           arguments="{title: 'Par jours de la semaine', id: 'visitsByWeekday',
                                       module: 'VisitTime', action: 'getByDayOfWeek',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
 
                 <f:comment><!-- By local hour --></f:comment>
                 <f:render partial="ReportCard"
                           arguments="{title: 'Par heures locales', id: 'visitsByHour',
                                       module: 'VisitTime', action: 'getVisitInformationPerLocalTime',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
 
                 <f:comment><!-- Map --></f:comment>
                 <f:render partial="ReportCard"
                           arguments="{title: 'Répartition géographique', id: 'visitsMap',
                                       module: 'UserCountryMap', action: 'visitorMap', height: '450',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
             </div>
 
             <div class="reportSection">
@@ -65,13 +82,13 @@
                 <f:render partial="ReportCard"
                           arguments="{title: 'Origines', id: 'visitsRefferers',
                                       module: 'Referrers', action: 'getAll',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
 
                 <f:comment><!-- By web-browsers   --></f:comment>
                 <f:render partial="ReportCard"
                           arguments="{title: 'DevicesDetection', id: 'getBrowsers',
                                       module: 'Referrers', action: 'getAll',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
 
             </div>
 
@@ -81,7 +98,7 @@
                 <f:render partial="ReportCard"
                           arguments="{title: 'Pages visitées', id: 'visitsByPage',
                                       module: 'Actions', action: 'getPageUrls', width: '1028',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
             </div>
 
             <div class="reportSection">
@@ -90,13 +107,13 @@
                 <f:render partial="ReportCard"
                           arguments="{title: 'Pages d\'entrée', id: 'visitorsEntryPoints',
                                       module: 'Actions', action: 'getEntryPageUrls',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
 
                 <f:comment><!-- By visits duration   --></f:comment>
                 <f:render partial="ReportCard"
                           arguments="{title: 'Durée des visite', id: 'visitsByDuration',
                                       module: 'VisitorInterest', action: 'getNumberOfVisitsPerVisitDuration',
-                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, date_start: date_start, date_end: date_end}"/>
+                                      matomoSiteId: matomoSiteId, matomoToken: matomoToken, period: period}"/>
             </div>
 
             <div class="reportFooter">

+ 15 - 0
ot_stats/Resources/Public/assets/Backend/style/ot_stats.css

@@ -16,6 +16,21 @@
     color: #800000;
 }
 
+#matomoFilters {
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+}
+
+#matomoFilters > form {
+    display: flex;
+    flex-direction: row;
+}
+
+#matomoFilters > form > * {
+    margin: 0 6px;
+}
+
 #matomoReport {
     display: flex;
     flex-direction: column;