2012-03-28 53 views
0

我一直在使用Land of Coder開發的K2 Scroller模塊。當我使用此模塊在項目視圖中顯示相同的類別項目時,模塊按創建日期的升序顯示項目,並且它是後端模塊參數設置中的默認設置並且是唯一可用的設置。但是,我希望模塊以明智的降序顯示項目。所以我選擇編輯助手中的默認代碼,我想用它來處理基於後端設置的項目。這是在幫助文件中的代碼,我認爲控制順序部分:Lof K2Scroller模塊

public function __getList($params){ 
      global $mainframe; 

         /*some irrelevant code removed*/ 

         $condition  = $this->buildConditionQuery($params); 
      $limitDescriptionBy = $params->get('limit_description_by','char'); 
      $ordering = $params->get('k2_ordering', 'created_desc'); 
      $limit   = $params->get('limit_items', 5); 
      $ordering = str_replace('_', ' ', $ordering); 
      $my   = &JFactory::getUser(); 
      $aid   = $my->get('aid', 0); 

         /*some irrelevant code removed*/ 

      $extraURL  = $params->get('open_target')!='modalbox'?'':'&tmpl=component'; 
      $excludeIds  = $params->get('exclude_ids', ''); 
      $db  = &JFactory::getDBO(); 
      $date =& JFactory::getDate(); 
      $now = $date->toMySQL(); 
      $dateFormat = $params->get('date_format', 'DATE_FORMAT_LC3'); 

      $limitDescriptionBy = $params->get('limit_description_by','char'); 
      $isAuthor= $params->get('itemAuthor',0); 
      require_once (JPath::clean(JPATH_SITE.'/components/com_k2/helpers/route.php')); 
      $query = "SELECT a.*, cr.rating_sum/cr.rating_count as rating, c.name as categoryname, 
          c.id as categoryid, c.alias as categoryalias, c.params as categoryparams, cc.commentcount as commentcount". 
        " FROM #__k2_items as a". 
         " LEFT JOIN #__k2_categories c ON c.id = a.catid" . 
         " LEFT JOIN #__k2_rating as cr ON a.id = cr.itemid". 
         " LEFT JOIN (select cm.itemid as id, count(cm.id) as commentcount from #__k2_comments as cm 
                    where cm.published=1 group by cm.itemid) as cc on a.id = cc.id"; 

      $query .= " WHERE a.published = 1" 
         . " AND a.access get('featured_items_show','0') == 0){ 
       $query.= " AND a.featured != 1"; 
      } elseif( $params->get('featured_items_show','0') == 2) { 
       $query.= " AND a.featured = 1"; 
      } 
      if(trim($excludeIds)){ 
       $query .= " AND a.id NOT IN(".$excludeIds.") "; 
      } 
      $query .= $condition . ' ORDER BY ' . $ordering; 
      $query .= $limit ? ' LIMIT ' . $limit : ''; 

      $db->setQuery($query); 
      $data = $db->loadObjectlist(); 

      /*some irrelevant code removed*/ 

         return $data; 
     } 


     /** 
     * build condition query base parameter 
     * 
     * @param JParameter $params; 
     * @return string. 
     */ 
     public function buildConditionQuery($params){ 
      $source = trim($params->get('k2_source', 'k2_category')); 
      if($source == 'k2_category'){ 
       $catids = $params->get('k2_category',''); 

       if(!$catids){ 
        return ''; 
       } 
       $catids = !is_array($catids) ? $catids : '"'.implode('","',$catids).'"'; 
       $condition = ' AND a.catid IN('.$catids.')'; 
      } else { 
       $ids = preg_split('/,/',$params->get('k2_items_ids','')); 
       $tmp = array(); 
       foreach($ids as $id){ 
        $tmp[] = (int) trim($id); 
       } 
       $condition = " AND a.id IN('". implode("','", $tmp) ."')"; 
      } 
      return $condition; 
     } 

我是編輯代碼的右邊部分還是我失去了別的東西。

我期待着您的幫助

謝謝。

回答

0

也許最好的方法是修改模塊的xml文件。

我看了Lof K2Scroller(2.2 for Joomla 2.5)的代碼,不同的訂購選項在那裏。

但是,如果您想修改默認選項,您在正確的文件中,只需將'created_desc'替換爲'created_asc'即可。

+0

謝謝沙茲。我實際上修改了默認選項,但它不起作用。你能告訴我需要在xml文件中編輯什麼嗎? – 2012-04-04 09:53:38