Stats en cours

This commit is contained in:
Fred Tempez 2021-02-12 17:06:38 +01:00
parent 5fda899e88
commit af94b2e5bc
3 changed files with 112 additions and 3 deletions

View File

@ -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 {
'</a>',
$this->getData(['module', $this->getUrl(0), 'items', $itemIds[$i], 'fileVersion']),
$date .' à '. $heure,
count($stats),
'<a href="' . helper::baseurl() . $this->getUrl(0) . '/stats/' . $itemIds[$i] . '" >' . count($stats) . '</a>',
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'
]);
}
}
}

View File

@ -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 <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @author Frédéric Tempez <frederic.tempez@outlook.com>
* @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
*/

View File

@ -0,0 +1,31 @@
<?php echo template::formOpen('statsConfig'); ?>
<div class="row">
<div class="col2">
<?php echo template::button('statsConfigBack', [
'class' => 'buttonGrey',
'href' => helper::baseUrl() . 'page/edit/' . $this->getUrl(0), 'items',
'ico' => 'left',
'value' => 'Retour'
]); ?>
</div>
<div class="col2 offset6">
<?php echo template::button('statsConfigAdd', [
'href' => helper::baseUrl() . $this->getUrl(0) . '/add',
'ico' => 'plus',
'value' => 'Item'
]); ?>
</div>
<div class="col2">
<?php echo template::submit('statsConfigSubmit'); ?>
</div>
</div>
<?php echo template::formClose(); ?>
<?php if($module::$items): ?>
<?php echo template::table([6, 6], $module::$items, ['Date', 'Adresse IP']); ?>
<?php echo $module::$pages; ?>
<?php else: ?>
<?php echo template::speech('Aucun item.'); ?>
<?php endif; ?>
<div class="moduleVersion">Version
<?php echo $module::VERSION; ?>
</div>