/** * Get all tags * * @param int $limit * @param int $page * @param string $sort * @return array */ public function getAll($limit = null, $page = null, $sort = null) { $order = $this->getSortOrder($sort, $page); $sql = Table\TagItems::sql(); $sql->select([0 => 'tag_id', 1 => 'id', 2 => 'title', 3 => 'slug', 'count' => 'COUNT(1)'])->join(DB_PREFIX . 'tags', [DB_PREFIX . 'tags.id' => DB_PREFIX . 'tag_items.tag_id']); $sql->select()->groupBy('tag_id'); $orderAry = explode(' ', $order); $sql->select()->orderBy($orderAry[0], $orderAry[1]); if (null !== $limit) { $page = null !== $page && (int) $page > 1 ? $page * $limit - $limit : null; $sql->select()->offset($page); $sql->select()->limit($limit); return Table\TagItems::query($sql)->rows(); } else { return Table\TagItems::query($sql)->rows(); } }
/** * Init tag model and tag cloud * * @param AbstractController $controller * @param Application $application * @return void */ public static function init(AbstractController $controller, Application $application) { if (!$_POST && $controller->hasView() && $controller instanceof \Phire\Content\Controller\IndexController) { $sql = Table\TagItems::sql(); $sql->select([0 => 'tag_id', 1 => 'id', 2 => 'title', 3 => 'slug', 'count' => 'COUNT(1)'])->join(DB_PREFIX . 'tags', [DB_PREFIX . 'tags.id' => DB_PREFIX . 'tag_items.tag_id']); $sql->select()->groupBy('tag_id')->orderBy('count', 'DESC'); $tags = Table\TagItems::query($sql); $cloud = null; $max = 0; if ($tags->hasRows()) { foreach ($tags->rows() as $i => $tag) { if ($i == 0) { $max = $tag->count; } $weight = round($tag->count / $max * 100); if ($weight < 10) { $weight = 1; } else { $weight = $weight - $weight % 10; } $cloud .= '<a class="tag-link tag-weight-' . $weight . '" href="' . BASE_PATH . '/tag/' . $tag->slug . '">' . $tag->title . '</a>' . PHP_EOL; } } $tag = new Model\Tag(); $tag->filters = $application->module('phire-tags')['filters']; $controller->view()->tag_cloud = $cloud; $controller->view()->phire->tag = $tag; } }