public function getTagCloud() : array
{
$tags = $this->db->run('SELECT
t.tagid,
t.name,
t.slug,
COUNT(j.postid) AS num_posts
FROM
hull_blog_tags t
LEFT JOIN
hull_blog_post_tags j
ON j.tagid = t.tagid
JOIN hull_blog_posts p
ON j.postid = p.postid
WHERE
p.status AND p.published <= current_timestamp
GROUP BY
t.tagid,
t.name,
t.slug
ORDER BY t.name ASC');
if (empty($tags)) {
return [];
}
$avg = \array_sum(\array_column($tags, 'num_posts')) / \count($tags);
if ($avg == 0) {
$avg = 1;
}
foreach ($tags as $i => $tag) {
$tags[$i]['post_ratio'] = \round($tag['num_posts'] / $avg, 2);
}
return $tags;
}