From af94b2e5bc32a118837c7ce8e2d234f6ae3243bf Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 12 Feb 2021 17:06:38 +0100 Subject: [PATCH] Stats en cours --- module/download/download.php | 66 ++++++++++++++++++++++++++-- module/download/view/stats/stats.css | 18 ++++++++ module/download/view/stats/stats.php | 31 +++++++++++++ 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 module/download/view/stats/stats.css create mode 100644 module/download/view/stats/stats.php diff --git a/module/download/download.php b/module/download/download.php index f99bbd9a..17fcead6 100644 --- a/module/download/download.php +++ b/module/download/download.php @@ -27,6 +27,7 @@ class download extends common { 'config' => self::GROUP_MODERATOR, 'delete' => self::GROUP_MODERATOR, 'edit' => self::GROUP_MODERATOR, + 'stats' => self::GROUP_MODERATOR, 'index' => self::GROUP_VISITOR, 'rss' => self::GROUP_VISITOR, 'downloadFile' => self::GROUP_VISITOR @@ -426,7 +427,6 @@ class download extends common { } // Nombre de téléchargements $stats = helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i],'fileStats']), 'time'); - // Met en forme le tableau $date = mb_detect_encoding(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i], 'fileDate'])), 'UTF-8', true) ? strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i], 'fileDate'])) @@ -440,7 +440,7 @@ class download extends common { '', $this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i], 'fileVersion']), $date .' à '. $heure, - count($stats), + '' . count($stats) . '', self::$states[$this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i], 'state'])], // Bouton pour afficher les commentaires de l'item template::button('downloadConfigComment' . $itemIds[$i], [ @@ -771,6 +771,7 @@ class download extends common { * Initie un téléchargement protégé */ public function downloadFile() { + if($this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2)]) === null) { // Valeurs en sortie $this->addOutput([ @@ -825,5 +826,64 @@ class download extends common { } } } -} + /** + * Ecran de consultation des données statistiques + */ + + public function stats() { + // Soumission du formulaire + if($this->isPost()) { + // Jeton incorrect + if ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => 'Action non autorisée' + ]); + } + // L'item n'existe pas + if($this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + } else { + // Construction de la page des statistiques + // Ids des items par ordre de publication + + $itemIds = array_keys($this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats'])); + // Pagination + $pagination = helper::pagination($itemIds, $this->getUrl(),$this->getData(['config','itemsperPage'])); + + // Liste des pages + self::$pages = $pagination['pages']; + + for($i = $pagination['first']; $i < $pagination['last']; $i++) { + + // Format des variables + + echo $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate']); + + $date = mb_detect_encoding(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate'])), 'UTF-8', true) + ? strftime('%d %B %Y',$this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate'])) + : utf8_encode(strftime('%d %B %Y', $this->getData(['module', $this->getUrl(0), 'items', $this->getUrl(2), 'fileStats', $itemIds[$i], 'fileDate']))); + + // Met en forme le tableau + self::$items[] = [ + $date, + $this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i], 'fileStats', 'ip']) + ]; + + } + die(); + // Valeurs en sortie + $this->addOutput([ + 'title' => 'Statistiques de téléchargement', + 'view' => 'stats' + ]); + + } + } +} \ No newline at end of file diff --git a/module/download/view/stats/stats.css b/module/download/view/stats/stats.css new file mode 100644 index 00000000..805e9150 --- /dev/null +++ b/module/download/view/stats/stats.css @@ -0,0 +1,18 @@ +/** + * This file is part of Zwii. + * + * For full copyright and license information, please see the LICENSE + * file that was distributed with this source code. + * + * @author Rémi Jean + * @copyright Copyright (C) 2008-2018, Rémi Jean + * @author Frédéric Tempez + * @copyright Copyright (C) 2018-2020, Frédéric Tempez + * @license GNU General Public License, version 3 + * @link http://zwiicms.fr/ + */ + + +/** NE PAS EFFACER +* admin.css +*/ \ No newline at end of file diff --git a/module/download/view/stats/stats.php b/module/download/view/stats/stats.php new file mode 100644 index 00000000..9bcc3316 --- /dev/null +++ b/module/download/view/stats/stats.php @@ -0,0 +1,31 @@ + +
+
+ 'buttonGrey', + 'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0), 'items', + 'ico' => 'left', + 'value' => 'Retour' + ]); ?> +
+
+ helper::baseUrl() . $this->getUrl(0) . '/add', + 'ico' => 'plus', + 'value' => 'Item' + ]); ?> +
+
+ +
+
+ + + + + + + +
Version n° + +
\ No newline at end of file