public static function getList(&$params)
 {
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $catid = $params->get('catid', array());
     $query->select(' count(t.id) as total, t.*');
     $query->select('CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(":", t.id, t.alias) ELSE t.id END as tagslug');
     $query->from('#__tz_portfolio_plus_tags AS t');
     $query->where('t.published = 1');
     $query->join('LEFT', '#__tz_portfolio_plus_tag_content_map AS tm ON tm.tagsid = t.id');
     $query->join('LEFT', '#__tz_portfolio_plus_content AS c ON (tm.contentid = c.id)');
     $query->where('c.state = 1');
     $query->join('LEFT', '#__tz_portfolio_plus_content_category_map AS cm ON (cm.contentid = c.id)');
     $query->join('LEFT', '#__tz_portfolio_plus_categories AS cc ON cc.id = cm.catid');
     $query->where('cc.published = 1');
     if (is_array($catid)) {
         $catid = array_filter($catid);
         if (count($catid)) {
             $query->where('cm.catid IN (' . implode(',', $catid) . ')');
         }
     } else {
         $query->where('cm.catid = ' . $catid);
     }
     $query->group('t.alias');
     $db->setQuery($query, 0, $params->get('tag_limit'));
     if ($items = $db->loadObjectList()) {
         foreach ($items as $item) {
             $cloud[] = $item->total;
         }
         $max_size = $params->get('maxfont', 300);
         $min_size = $params->get('minfont', 75);
         $max_qty = max(array_values($cloud));
         $min_qty = min(array_values($cloud));
         $spread = $max_qty - $min_qty;
         if (0 == $spread) {
             $spread = 1;
         }
         $step = ($max_size - $min_size) / $spread;
         foreach ($items as $tag) {
             $size = $min_size + ($tag->total - $min_qty) * $step;
             $size = ceil($size);
             $tag->size = $size;
             $tag->link = TZ_Portfolio_PlusHelperRoute::getTagRoute($tag->tagslug, 0, 'auto');
         }
         return $items;
     }
     return false;
 }
Exemple #2
0
 public static function getTagsByArticleId($contentId, $options = array('orderby' => null, 'condition' => null, 'reverse_contentid' => true, 'menuActive' => null))
 {
     if ($contentId) {
         if (is_array($contentId)) {
             $storeId = md5(__METHOD__ . '::' . implode(',', $contentId));
         } else {
             $storeId = md5(__METHOD__ . '::' . $contentId);
         }
         if (!isset(self::$cache[$storeId])) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('t.*, c.id AS contentid');
             $query->select('CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(":", t.id, t.alias) ELSE t.id END as slug');
             $query->from('#__tz_portfolio_plus_tags AS t');
             $query->join('INNER', '#__tz_portfolio_plus_tag_content_map AS m ON m.tagsid = t.id');
             $query->join('INNER', '#__tz_portfolio_plus_content AS c ON c.id = m.contentid');
             $query->where('t.published = 1');
             if (is_array($contentId)) {
                 $query->where('c.id IN(' . implode(',', $contentId) . ')');
             } else {
                 $query->where('c.id = ' . $contentId);
             }
             if (count($options)) {
                 if (isset($options['condition']) && $options['condition']) {
                     $query->where($options['condition']);
                 }
                 if (isset($options['orderby']) && $options['orderby']) {
                     $query->order($options['orderby']);
                 }
             }
             $db->setQuery($query);
             if ($data = $db->loadObjectList()) {
                 $tags = array();
                 $tagIds = array();
                 $menuActive = null;
                 if (isset($options['menuActive']) && !empty($options['menuActive'])) {
                     $menuActive = $options['menuActive'];
                 }
                 foreach ($data as &$tag) {
                     // Create Tag Link
                     $tag->link = JRoute::_(TZ_Portfolio_PlusHelperRoute::getTagRoute($tag->slug, 0, $menuActive));
                     // Create article's id is array's key with value are tags
                     if (count($options) && isset($options['reverse_contentid']) && $options['reverse_contentid']) {
                         if (!isset($tags[$tag->contentid])) {
                             $tags[$tag->contentid] = array();
                         }
                         if (!isset($tagIds[$tag->contentid])) {
                             $tagIds[$tag->contentid] = array();
                         }
                         if (!in_array($tag->id, $tagIds[$tag->contentid])) {
                             $tags[$tag->contentid][] = $tag;
                             $tagIds[$tag->contentid][] = $tag->id;
                         }
                     }
                 }
                 if (!count($tags)) {
                     $tags = $data;
                 }
                 self::$cache[$storeId] = $tags;
                 return $tags;
             }
             self::$cache[$storeId] = false;
         }
         return self::$cache[$storeId];
     }
     return false;
 }