research-document-archive / web /src /controllers /DashboardController.php
datamatters24's picture
Upload web/src/controllers/DashboardController.php with huggingface_hub
9a33c82 verified
<?php
declare(strict_types=1);
class DashboardController
{
public function index(): void
{
$db = Database::getInstance();
// Collection summary
$collectionSummary = [];
try {
$row = $db->fetchAll("SELECT value FROM analytics_cache WHERE key = 'collection_summary'");
if (!empty($row[0]['value'])) {
$collectionSummary = json_decode($row[0]['value'], true) ?: [];
}
} catch (\PDOException $e) {}
// Topic profiles
$topicProfiles = [];
try {
$row = $db->fetchAll("SELECT value FROM analytics_cache WHERE key = 'topic_profiles'");
if (!empty($row[0]['value'])) {
$topicProfiles = json_decode($row[0]['value'], true) ?: [];
}
} catch (\PDOException $e) {}
// Collection similarity
$similarities = [];
try {
$row = $db->fetchAll("SELECT value FROM analytics_cache WHERE key = 'collection_similarity'");
if (!empty($row[0]['value'])) {
$similarities = json_decode($row[0]['value'], true) ?: [];
}
} catch (\PDOException $e) {}
// Bridge entities (PERSON)
$bridgePersons = [];
try {
$row = $db->fetchAll("SELECT value FROM analytics_cache WHERE key = 'bridge_entities_person'");
if (!empty($row[0]['value'])) {
$bridgePersons = json_decode($row[0]['value'], true) ?: [];
}
} catch (\PDOException $e) {}
// Bridge entities (ORG)
$bridgeOrgs = [];
try {
$row = $db->fetchAll("SELECT value FROM analytics_cache WHERE key = 'bridge_entities_org'");
if (!empty($row[0]['value'])) {
$bridgeOrgs = json_decode($row[0]['value'], true) ?: [];
}
} catch (\PDOException $e) {}
// Sentiment summary
$sentimentSummary = [];
try {
$row = $db->fetchAll("SELECT value FROM analytics_cache WHERE key = 'sentiment_summary'");
if (!empty($row[0]['value'])) {
$sentimentSummary = json_decode($row[0]['value'], true) ?: [];
}
} catch (\PDOException $e) {}
// Stamp distribution
$stamps = [];
try {
$stamps = $db->fetchAll("
SELECT stamp->>'stamp' as classification, COUNT(*) as doc_count
FROM document_features,
jsonb_array_elements(feature_json->'stamps') as stamp
WHERE feature_name = 'forensic_metadata'
GROUP BY stamp->>'stamp'
ORDER BY doc_count DESC
");
} catch (\PDOException $e) {}
require __DIR__ . '/../views/dashboard.php';
}
}