Example #1
0
 static function getList($params, $count)
 {
     $mainframe = JFactory::getApplication();
     $catids = $params->get('k2catids', array());
     $ordering = $params->get('ordering', 'a.ordering');
     $ordering_direction = $params->get('ordering_direction', 'ASC');
     $user_id = $params->get('user_id');
     $show_featured = $params->get('show_featured');
     $user = JFactory::getUser();
     $aid = $user->get('aid');
     $db = JFactory::getDBO();
     $jnow = JFactory::getDate();
     if (version_compare(JVERSION, '3.0', '<') == 1) {
         $now = $jnow->toMySQL();
     } else {
         $now = $jnow->toSql();
     }
     $nullDate = $db->getNullDate();
     $query = "SELECT a.*, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams" . " FROM #__k2_items as a" . " LEFT JOIN #__k2_categories c ON c.id = a.catid";
     if (version_compare(JVERSION, '3.0', '<') == 1) {
         $query .= " WHERE a.published = 1 AND a.access IN(" . implode(',', $user->authorisedLevels()) . ") AND a.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->authorisedLevels()) . ")  AND c.trash = 0";
     } else {
         $query .= " WHERE a.published = 1 AND a.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ") AND a.trash = 0 AND c.published = 1 AND c.access IN(" . implode(',', $user->getAuthorisedViewLevels()) . ")  AND c.trash = 0";
     }
     // User filter
     $userId = JFactory::getUser()->get('id');
     switch ($params->get('user_id')) {
         case 'by_me':
             $query .= ' AND (a.created_by = ' . (int) $userId . ' OR a.modified_by = ' . (int) $userId . ')';
             break;
         case 'not_me':
             $query .= ' AND (a.created_by <> ' . (int) $userId . ' AND a.modified_by <> ' . (int) $userId . ')';
             break;
         case '0':
             break;
         default:
             $query .= ' AND (a.created_by = ' . (int) $userId . ' OR a.modified_by = ' . (int) $userId . ')';
             break;
     }
     //Added Category
     if (!is_null($catids)) {
         if (is_array($catids)) {
             JArrayHelper::toInteger($catids);
             $query .= " AND a.catid IN(" . implode(',', $catids) . ")";
         } else {
             $query .= " AND a.catid=" . (int) $catids;
         }
     }
     //  Featured items filter
     if ($show_featured == '0') {
         $query .= " AND a.featured != 1";
     }
     if ($show_featured == '1') {
         $query .= " AND a.featured = 1";
     }
     // ensure should be published
     $query .= " AND ( a.publish_up = " . $db->Quote($nullDate) . " OR a.publish_up <= " . $db->Quote($now) . " )";
     $query .= " AND ( a.publish_down = " . $db->Quote($nullDate) . " OR a.publish_down >= " . $db->Quote($now) . " )";
     if (K2_JVERSION != '15') {
         if ($mainframe->getLanguageFilter()) {
             $languageTag = JFactory::getLanguage()->getTag();
             $query .= " AND c.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ") AND i.language IN (" . $db->Quote($languageTag) . ", " . $db->Quote('*') . ")";
         }
     }
     //Ordering
     $orderby = $ordering . ' ' . $ordering_direction;
     //ordering
     $query .= " ORDER BY " . $orderby;
     $db->setQuery($query, 0, $count);
     $items = $db->loadObjectList();
     $model = K2Model::getInstance('Item', 'K2Model');
     if (count($items)) {
         foreach ($items as $item) {
             if (!empty($item->created_by_alias)) {
                 $item->author = $item->created_by_alias;
             } else {
                 $author = JFactory::getUser($item->created_by);
                 $item->author = $author->name;
             }
             $item->created = $item->created;
             $item->hits = $item->hits;
             $item->category = $item->categoryname;
             $item->cat_link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));
             $item->image = modTzContentSliderK2Helper::getImage($item->id, $item->introtext);
             $item->title = htmlspecialchars($item->title);
             $item->introtext = $item->introtext;
             $item->link = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id . ':' . urlencode($item->alias), $item->catid . ':' . urlencode($item->categoryalias))));
             $item->comment = '<a class="tzcontentslider-comments" href="' . $item->link . '#itemCommentsAnchor">' . JText::_('COMMENTS_TEXT') . ' (' . $model->countItemComments($item->id) . ')</a>';
             $item->rating = $model->getVotesPercentage($item->id);
             if ($params->get('article_extra_fields')) {
                 $item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);
             }
             $rows[] = $item;
         }
         return $rows;
     }
 }
$c_count = $c_article_count + $c_links_count;
if (!class_exists("modTzContentSliderCommonHelper")) {
    require_once 'common.php';
}
if ($content_source == "joomla") {
    require_once dirname(__FILE__) . DS . 'helper.php';
    $list = modTzContentSliderJHelper::getList($params, $c_count);
} elseif ($content_source == "vm") {
    if (!class_exists('VmModel')) {
        require JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'vmmodel.php';
    }
    require_once dirname(__FILE__) . DS . 'vmhelper.php';
    $list = modTzContentSliderVMHelper::getList($params, $c_count);
} else {
    require_once dirname(__FILE__) . DS . 'k2helper.php';
    $list = modTzContentSliderK2Helper::getList($params, $c_count);
}
$a_count = count($list);
//actual count
if ($c_count > $a_count) {
    $c_count = $a_count;
    if ($c_article_count >= $c_count) {
        $c_article_count = $c_count;
        $c_links_count = 0;
    } else {
        if ($c_links_count > $c_count - $c_article_count) {
            $c_links_count = $c_count - $c_article_count;
        }
    }
}
if ($content_source == "vm" && ($art_show_cart_button || $links_show_cart_button)) {