2016-12-01 3 views
0

Если я сделаю это http://www.website.com/index.php?page=search&sCategory=123&sFeed=rssСоздание RSS-канал для нескольких выбранных категорий

Я могу создать RSS-канал для той или иной категории. Но что, если я хочу создать RSS-канал для нескольких выбранных категорий? Является ли это возможным? Версия OSClass - 3.3.2

ответ

1

Я не нашел короткий или интегрированный способ сделать это, поэтому я закодировал его.

<?php 


define('ABS_PATH', str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME']) . '/')); 
if(PHP_SAPI==='cli') { 
    define('CLI', true); 
} 

require_once ABS_PATH . 'oc-load.php'; 

$mSearch = Search::newInstance(); 

$array_categorias = array("16","22","23","24","31","33","43","102","119","121","122","123","124"); 

$aItems = $mSearch->doCustomSearch($array_categorias); 

View::newInstance()->_exportVariableToView('items', $aItems); 

// FEED REQUESTED! 
header('Content-type: text/xml; charset=utf-8'); 

$feed = new RSSFeed; 
$feed->setTitle(__('Latest listings added') . ' - ' . osc_page_title()); 
$feed->setLink(osc_base_url()); 
$feed->setDescription(__('Latest listings added in') . ' ' . osc_page_title()); 

$contador_items = osc_count_items(); 

if(osc_count_items()>0) { 
    while(osc_has_items()) { 
     if(osc_count_item_resources() > 0){ 
      osc_has_item_resources(); 
      $feed->addItem(array(
       'title' => osc_item_title(), 
       'link' => htmlentities(osc_item_url(), ENT_COMPAT, "UTF-8"), 
       'description' => osc_item_description(), 
       'dt_pub_date' => osc_item_pub_date(), 
       'image'  => array( 'url' => htmlentities(osc_resource_thumbnail_url(), ENT_COMPAT, "UTF-8"), 
             'title' => osc_item_title(), 
             'link' => htmlentities(osc_item_url() , ENT_COMPAT, "UTF-8")) 
      )); 
     } else { 
      $feed->addItem(array(
       'title' => osc_item_title(), 
       'link' => htmlentities(osc_item_url() , ENT_COMPAT, "UTF-8"), 
       'description' => osc_item_description(), 
       'dt_pub_date' => osc_item_pub_date() 
      )); 
     } 
    } 
} 

$feed->dumpXML(); 
?> 

Я также должен был добавить несколько пользовательских методов поиска модели

public function _makeSQLCustomCategories($categories) 
     { 


       $cadena_select = DB_TABLE_PREFIX."t_item.*, ".DB_TABLE_PREFIX."t_item.s_contact_name as s_user_name,"; 
       $cadena_select = $cadena_select . DB_TABLE_PREFIX. "t_item_description.s_title, "; 
       $cadena_select = $cadena_select . DB_TABLE_PREFIX. "t_item_description.s_description"; 

       $this->dao->select($cadena_select); 

       $this->dao->from(DB_TABLE_PREFIX.'t_item');      
       $this->dao->from(DB_TABLE_PREFIX. 't_item_description'); 

       $this->dao->where(DB_TABLE_PREFIX. 't_item_description.fk_i_item_id = '. DB_TABLE_PREFIX. 't_item.pk_i_id'); 

       //$this->dao->where(DB_TABLE_PREFIX. 't_item.b_premium = 1'); 
       $this->dao->where(DB_TABLE_PREFIX. 't_item.b_enabled = 1'); 
       $this->dao->where(DB_TABLE_PREFIX. 't_item.b_active = 1'); 
       $this->dao->where(DB_TABLE_PREFIX. 't_item.b_spam = 0'); 

       $where_categorias = "("; 
       $contador_categorias = 0; 
       $tamano_categories = sizeof($categories); 

       foreach ($categories as $categoria) 
       { 
        $contador = $contador + 1; 
        $where_categorias = $where_categorias. DB_TABLE_PREFIX. 't_item.fk_i_category_id = ' . $categoria ; 
        if ($contador == $tamano_categories) 
         break;     
        $where_categorias = $where_categorias . " OR "; 
       } 

       $where_categorias = $where_categorias . ")"; 

       $this->dao->where($where_categorias); 

       $this->dao->groupBy(DB_TABLE_PREFIX.'t_item.pk_i_id'); 

       $this->dao->orderBy(DB_TABLE_PREFIX. 't_item.pk_i_id', 'DESC'); 


      $sql = $this->dao->_getSelect(); 
      // reset dao attributes 
      $this->dao->_resetSelect(); 

      return $sql; 
     } 

     public function doCustomSearch($categories, $extended = true, $count = true) 
     { 

      $sql = $this->_makeSQLCustomCategories($categories); 
      $result = $this->dao->query($sql); 

      if($count) { 
       $sql = $this->_makeSQLCustomCategories($categories); 
       $datatmp = $this->dao->query($sql); 

       if($datatmp == false) { 
        $this->total_results = 0; 
       } else { 
        $this->total_results = $datatmp->numRows(); 
       } 
      } else { 
       $this->total_results = 0; 
      } 

      if($result == false) { 
       return array(); 
      } 

      if($result) { 
       $items = $result->result(); 
      } else { 
       $items = array(); 
      } 

      if($extended) { 
       return Item::newInstance()->extendData($items); 
      } else { 
       return $items; 
      } 
     } 
Смежные вопросы