_init('quickfaq/faqstore'); } public function loadByStore($faqid,$store_id) { $collection = $this->getCollection() ->addFieldToFilter('faq_id',$faqid) ->addFieldToFilter('store_id',$store_id) ->addFieldToFilter('is_applied',array('neq'=>2)) ; return $collection->getFirstItem(); } public function loadByFaqIdStore($faqid,$store_id) { $collection = $this->getCollection() ->addFieldToFilter('faq_id',$faqid) ->addFieldToFilter('store_id',$store_id) ; return $collection->getFirstItem(); } public function getJoinedCollection($status=1) { $store_id = $this->getStoreId(); $category_table = Mage::getSingleton('core/resource') ->getTableName('categorystore'); $collection = $this->getCollection() ->join($category_table,$category_table.'.category_id=main_table.category_id', array('category_id'=>'category_id', 'cat_is_applied'=>'is_applied', 'cat_store_id'=>'store_id', 'cat_status'=>'status', ) ) ->addFieldToFilter('main_table.status',$status) ->addFieldToFilter($category_table.'.status',$status) ->addFieldToFilter('main_table.is_applied',array('neq'=>2)) ->addFieldToFilter($category_table.'.is_applied',array('neq'=>2)) ->addFieldToFilter('main_table.store_id',$store_id) ->addFieldToFilter($category_table.'.store_id',$store_id) ->setOrder('main_table.ordering','ASC') ->setOrder('main_table.title','ASC') ->setOrder('main_table.update_time','DESC') ; // $collection->printlogquery(true);die(); return $collection; } public function getMostFrequently($limit) { $collection = $this->getJoinedCollection() ->addFieldToFilter('main_table.most_frequently',1) ->setCurPage(1) ->setPageSize($limit) ; return $this->_prepareLoadData($collection); } public function getQuestions($category_id,$limit = null) { $collection = $this->getJoinedCollection() ->addFieldToFilter('main_table.category_id',$category_id) ->setCurPage(1) ; if($limit) { $collection->setPageSize($limit); } return $this->_prepareLoadData($collection); } public function getSearchResult($keyword) { $collection = $this->getJoinedCollection(); $collection->getSelect()->where("main_table.title like '%".$keyword."%' or main_table.description like '%".$keyword."%'"); return $this->_prepareLoadData($collection); } protected function _prepareLoadData($collection) { $faq = Mage::getModel('quickfaq/quickfaq'); foreach($collection as $item) { if($item->getIsApplied() == '0') //use default value { $item->setData($faq->load($item->getFaqId()) ->getData()); } } return $collection; } }