Back to PhocaDownloadLayout class

Method displayTags

public
displayTags
(mixed $fileId, mixed $type = 0)

Method displayTags - Source code

public function displayTags($fileId, $type = 0)
{
    $o = '';
    $db = Factory::getDBO();
    $query = 'SELECT a.id, a.title, a.link_ext, a.link_cat' . ' FROM #__phocadownload_tags AS a' . ' LEFT JOIN #__phocadownload_tags_ref AS r ON r.tagid = a.id' . ' WHERE r.fileid = ' . (int) $fileId . ' ORDER BY a.id';
    $db->setQuery($query);
    try {
        $fileIdObject = $db->loadObjectList();
    } catch (\Exception $e) {
        throw new \Exception($e->getMessage(), 500);
    }
    $tl = $this->params->get('tags_links', 0);
    $class = '';
    if ($type == 1) {
        $class = 'class="label label-default"';
    }
    foreach ($fileIdObject as $k => $v) {
        $o .= '<span ' . $class . '>';
        if ($tl == 0) {
            $o .= $v->title;
        } else {
            if ($tl == 1) {
                if ($v->link_ext != '') {
                    $o .= '<a href="' . $v->link_ext . '">' . $v->title . '</a>';
                } else {
                    $o .= $v->title;
                }
            } else {
                if ($tl == 2) {
                    if ($v->link_cat != '') {
                        $query = 'SELECT a.id, a.alias' . ' FROM #__phocadownload_categories AS a' . ' WHERE a.id = ' . (int) $v->link_cat . ' ORDER BY a.id';
                        $db->setQuery($query, 0, 1);
                        try {
                            $category = $db->loadObject();
                        } catch (\RuntimeException $e) {
                            throw new \Exception($e->getMessage(), 500);
                        }
                        if (isset($category->id) && isset($category->alias)) {
                            $link = PhocaDownloadRoute::getCategoryRoute($category->id, $category->alias);
                            $o .= '<a href="' . $link . '">' . $v->title . '</a>';
                        } else {
                            $o .= $v->title;
                        }
                    } else {
                        $o .= $v->title;
                    }
                } else {
                    if ($tl == 3) {
                        $link = PhocaDownloadRoute::getCategoryRouteByTag($v->id);
                        $o .= '<a href="' . $link . '">' . $v->title . '</a>';
                    }
                }
            }
        }
        $o .= '</span> ';
    }
    return $o;
}