Top 10 allegati

This commit is contained in:
Luca 2020-06-26 13:02:38 +02:00
parent 9e70630c15
commit 830378b812
3 changed files with 53 additions and 9 deletions

View File

@ -154,9 +154,11 @@ switch (filter('op')) {
'description' => $description,
'size' => $size,
'formattedSize' => FileSystem::formatBytes($size),
'count' => (FileSystem::folderCount($dir)? : 0),
'count' => (FileSystem::fileCount($dir, ['htaccess'])? : 0),
'dbSize' => (($description == "Allegati") ? $dbo->fetchOne("SELECT SUM(`size`) AS dbsize FROM zz_files")["dbsize"] : ""),
'dbCount' => (($description == "Allegati") ? $dbo->fetchOne("SELECT COUNT(`id`) AS dbcount FROM zz_files")["dbcount"] : ""),
'dbExtensions' => (($description == "Allegati") ? $dbo->fetchArray("SELECT SUBSTRING_INDEX(FILENAME, '.', -1) AS EXTENSION, COUNT(*) AS NUM FROM ZZ_FILES GROUP BY EXTENSION ORDER BY NUM DESC LIMIT 10") : ""),
];
}

View File

@ -43,7 +43,7 @@ function crea_grafico(values){
var diff = (element.dbSize-element.size);
if (diff>1000){
$("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+formatBytes(diff)+" di file mancanti per allegati.</div>");
$("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+formatBytes(diff)+" di file mancanti per allegati.</div><br>");
}
}
}
@ -53,11 +53,26 @@ function crea_grafico(values){
if (element.count<element.dbCount){
var diff = (element.dbCount-element.count);
$("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+diff+" di file mancanti per allegati.</div>");
$("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+diff+" di file mancanti per allegati.</div><br>");
}
}
//Numero di file in Allegati per estensione
if (element.dbExtensions.length > 0){
$("#message").append("<p><b>Top 10 allegati:</b></p>");
element.dbExtensions.forEach(function(extension) {
$("#message").append("<div class=\"label label-info\" ><i class=\"fa fa-file\" aria-hidden=\"true\"></i> <b>"+extension["NUM"]+"</b> file con estensione <b>"+extension["EXTENSION"]+"</b>.</div><br>");
});
}
$labels.push(element.description + " (" + element.formattedSize + ")" + " [" + element.count + "]" )
@ -71,7 +86,31 @@ function crea_grafico(values){
animation:{
animateScale: true,
animateRotate: true,
},
},
tooltips: {
callbacks: {
title: function(tooltipItem, data) {
return data["labels"][tooltipItem[0]["index"]];
},
label: function(tooltipItem, data) {
//return data["datasets"][0]["data"][tooltipItem["index"]];
var dataset = data["datasets"][0];
var percent = Math.round((dataset["data"][tooltipItem["index"]] / dataset["_meta"][0]["total"]) * 100)
return "(" + percent + "%)";
},
afterLabel: function(tooltipItem, data) {
//var dataset = data["datasets"][0];
//var percent = Math.round((dataset["data"][tooltipItem["index"]] / dataset["_meta"][0]["total"]) * 100)
//return "(" + percent + "%)";
}
},
backgroundColor: "#fbfbfb",
titleFontSize: 12,
titleFontColor: "#000",
bodyFontColor: "#444",
bodyFontSize: 10,
displayColors: true
}
};
data = {
@ -105,7 +144,7 @@ function crea_grafico(values){
});
}
</script>
<div class="chart-container" style="width:25em;">
<div id="message" class="pull-right"></div>
<div class="chart-container" style="width:35em;">
<canvas id="chart"></canvas>
</div><div id="message" ></div>';
</div>';

View File

@ -67,14 +67,17 @@ class FileSystem
*
* @return int
*/
public static function folderCount($path)
public static function fileCount($path, $exclusions = array())
{
$total = 0;
$path = realpath($path);
if ($path !== false && $path != '' && file_exists($path)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
$total += 1;
if (!in_array($object->getExtension(), $exclusions))
$total += 1;
}
}