Thesaurus/ajax/getStatistics.php

57 lines
1.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$dateStart = isset($_GET['dateStart']) ? $_GET['dateStart'] : "2022-01-01 00:00:00";
$dateEnd = isset($_GET['dateEnd']) ? $_GET['dateEnd'] : "2022-02-28 23:59:59";
include "db_connection.php";
require_once "libAuthorities.php";
$object = new CRUD();
$Results = $object->getStatistics($dateStart, $dateEnd);
$typeLabels = [
'Subject' => 'Schlagworte',
'Person' => 'Personennamen',
'Corporate' => 'Körperschaften',
'Publisher' => 'Verlage',
'Classification' => 'Klassifikationen',
];
$sumCreated = 0;
$sumModified = 0;
$rows = '';
$rank = 1;
foreach ($Results as $type => $result) {
$sumCreated += $result['DateCreated'];
$sumModified += $result['DateModified'];
$label = $typeLabels[$type] ?? $type;
$created = number_format($result['DateCreated'], 0, ',', '.');
$modified = number_format($result['DateModified'], 0, ',', '.');
$rows .= "<tr>"
. "<td class='text-center' style='width:60px;color:#1a3a5c;font-weight:600'>{$rank}</td>"
. "<td>{$label}</td>"
. "<td class='text-end pe-4' style='width:180px'>{$created}</td>"
. "<td class='text-end pe-4' style='width:180px'>{$modified}</td>"
. "</tr>";
$rank++;
}
$totalCreated = number_format($sumCreated, 0, ',', '.');
$totalModified = number_format($sumModified, 0, ',', '.');
$foot = "<tr style='background-color:#e8eef4;font-weight:700;color:#1a3a5c'>"
. "<td colspan='2' class='ps-3'>Summen</td>"
. "<td class='text-end pe-4'>{$totalCreated}</td>"
. "<td class='text-end pe-4'>{$totalModified}</td>"
. "</tr>";
$von = date('d.m.Y', strtotime($dateStart));
$bis = date('d.m.Y', strtotime($dateEnd));
echo json_encode([
"status" => 200,
"rows" => $rows,
"foot" => $foot,
"zeitraum" => "Zeitraum: {$von} {$bis}"
]);