insert($event, false); } /** Aggregated rows for the admin dashboard. */ public function topTools(int $days = 7, int $limit = 20): array { return $this->select("tool_slug, COUNT(*) AS views, SUM(name = 'tool_start') AS starts, SUM(name = 'tool_success') AS successes, SUM(name = 'tool_failure') AS failures") ->where('name', 'tool_view') ->where('created_at >=', gmdate('Y-m-d H:i:s', time() - $days * 86400)) ->groupBy('tool_slug') ->orderBy('views', 'DESC') ->limit($limit) ->findAll(); } public function countsSince(int $days = 1): array { $rows = $this->select('name, COUNT(*) AS total') ->where('created_at >=', gmdate('Y-m-d H:i:s', time() - $days * 86400)) ->groupBy('name') ->findAll(); return array_column($rows, 'total', 'name'); } /** @return list */ public function topFormats(int $days = 7, int $limit = 12): array { return $this->select("format, COUNT(*) AS total") ->where('name', 'download') ->where('format !=', '') ->where('created_at >=', gmdate('Y-m-d H:i:s', time() - $days * 86400)) ->groupBy('format') ->orderBy('total', 'DESC') ->limit($limit) ->findAll(); } /** Recent search queries (term stored in meta.term). */ public function recentSearches(int $limit = 30): array { return $this->like('meta', '"search_term"') ->where('name', 'search') ->orderBy('id', 'DESC') ->limit($limit) ->findAll(); } }