Browse Source

Ticket #4735 : recalculer les visites max, aujourd'hui et hier du site ou des articles

pull/5/head
Matthieu Marcillaud 1 year ago
parent
commit
f79d4ff860
  1. 23
      prive/squelettes/inclure/stats-visites-jours-resume.html
  2. 34
      prive/squelettes/inclure/stats-visites-jours-resume_fonctions.php

23
prive/squelettes/inclure/stats-visites-jours-resume.html

@ -1,12 +1,6 @@
#SET{c,#LISTE}
[(#ENV{id_article}|oui) #SET{c,#VAL{article}|classement_populaires} ]
#SET{max,0}
#SET{moy,0}
#SET{last,0}
#SET{lastlast,0}
<table class='spip spip_table--responsive spip_table--statistiques spip_table--statistiques-resume'>
<caption><:statistiques:resume:></caption>
<thead>
@ -39,16 +33,17 @@
</thead>
<tbody>
<tr>
<td class="num" data-label="<:info_maximum|spip_str_label|attribut_html:>">[(#GET{max}|number_format{0,"","&nbsp;"})]</td>
<td class='num' data-label="<:info_aujourdhui|spip_str_label|attribut_html:>">[(#GET{last}|number_format{0,"","&nbsp;"})]</td>
<td class='num' data-label="<:info_hier|spip_str_label|attribut_html:>">[(#GET{lastlast}|number_format{0,"","&nbsp;"})]</td>
#SET{stats,#NULL|statistiques_stats_generales}
<td class="num" data-label="<:info_maximum|spip_str_label|attribut_html:>">[(#GET{stats/max}|number_format{0,"","&nbsp;"})]</td>
<td class="num" data-label="<:info_aujourdhui|spip_str_label|attribut_html:>">[(#GET{stats/today}|number_format{0,"","&nbsp;"})]</td>
<td class="num" data-label="<:info_hier|spip_str_label|attribut_html:>">[(#GET{stats/yesterday}|number_format{0,"","&nbsp;"})]</td>
<BOUCLE_art(ARTICLES){id_article=#ENV{id_objet}}{statut?}{si #ENV{objet}|=={article}}>
<td class='num' data-label="<:statistiques:info_popularite_5|spip_str_label|attribut_html:>">[(#CHAMP_SQL{popularite}|round|number_format{0,"","&nbsp;"})]</td>
<td class='num' data-label="<:info_total|spip_str_label|attribut_html:>">[(#VISITES|round|number_format{0,"","&nbsp;"})]</td>
<td class='num' data-label="">[<strong>(#ID_ARTICLE|array_search{#GET{c}}|plus{1})</strong>[(#GET{c}|count|singulier_ou_pluriel{info_classement_1,info_classement_2,liste})]]</td>
<td class="num" data-label="<:statistiques:info_popularite_5|spip_str_label|attribut_html:>">[(#CHAMP_SQL{popularite}|round|number_format{0,"","&nbsp;"})]</td>
<td class="num" data-label="<:info_total|spip_str_label|attribut_html:>">[(#VISITES|round|number_format{0,"","&nbsp;"})]</td>
<td class="num" data-label="">[<strong>(#ID_ARTICLE|array_search{#GET{c}}|plus{1})</strong>[(#GET{c}|count|singulier_ou_pluriel{info_classement_1,info_classement_2,liste})]]</td>
</BOUCLE_art>
<td class='num' data-label="<:info_total|spip_str_label|attribut_html:>">[(#REM|stats_total|number_format{0,"","&nbsp;"})]</td>
<td class='num' data-label="<:statistiques:info_popularite_2|spip_str_label|attribut_html:>">[(#CONFIG{popularite_total}|round|number_format{0,"","&nbsp;"})]</td>
<td class="num" data-label="<:info_total|spip_str_label|attribut_html:>">[(#REM|stats_total|number_format{0,"","&nbsp;"})]</td>
<td class="num" data-label="<:statistiques:info_popularite_2|spip_str_label|attribut_html:>">[(#CONFIG{popularite_total}|round|number_format{0,"","&nbsp;"})]</td>
<//B_art>
</tr>
</tbody>

34
prive/squelettes/inclure/stats-visites-jours-resume_fonctions.php

@ -0,0 +1,34 @@
<?php
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
/**
* Calcule visites totales, aujourd'hui, hier pour le site ou objet/id_objet
*/
function statistiques_stats_generales(array $Pile) : array {
$objet = ($Pile[0]['objet'] ?? null) ?: null;
$id_objet = ($Pile[0]['id_objet'] ?? null) ?: null;
$table = 'spip_visites';
$where = [];
if ($objet === 'article') {
$table = 'spip_visites_articles';
$where[] = 'id_article = ' . sql_quote($id_objet);
} elseif ($objet) {
$table = 'spip_visites_objets';
$where[] = 'objet = ' . sql_quote($objet);
$where[] = 'id_objet = ' . sql_quote($id_objet);
}
$res = [];
$res['max'] = sql_getfetsel('MAX(visites) as max', $table, $where);
$stats_visites_to_array = charger_fonction('stats_visites_to_array', 'inc');
// on demande 2 jours de stats, à partir d'aujourd'hui
$stats = $stats_visites_to_array('day', 2, $objet, $id_objet);
$data = array_column($stats['data'], 'visites', 'date');
// les lignes ne sortent que s'il y a des entrées...
$res['today'] = $data[$stats['meta']['end_date']] ?? 0;
$res['yesterday'] = $data[$stats['meta']['start_date']] ?? 0;
return $res;
}
Loading…
Cancel
Save