_init('quickfaq/quickfaq'); } public function load($id, $field=null) { $store_id = $this->getStoreId(); if(!$store_id) { return parent::load($id, $field=null); } $faq = Mage::getModel('quickfaq/faqstore')->loadByStore($id,$store_id); if($faq->getIsApplied() == '1') //is applied { $this->setData($faq->getData()); } elseif($faq->getIsApplied() == '0' // use default value && !Mage::getSingleton('admin/session')->isLoggedIn() // not on admin page ){ parent::load($id, $field=null); } else { $this->setData($faq->getData()); } return $this; } public function save() { if(!$this->getStoreId()) return parent::save(); $cate_store = Mage::getModel('quickfaq/faqstore') ->loadByFaqIdStore($this->getFaqId(),$this->getStoreId()); $id = $cate_store->getId(); $cate_store->setData($this->getData()) ->setId($id) ->save(); return $this; } public function updateUrlKey() { $id = $this->getId(); $url_key = $this->getData('url_key'); $url_key .= ".html"; $urlrewrite = Mage::getModel("quickfaq/urlrewrite")->load("quickfaq/".$id,"id_path"); $urlrewrite->setData("id_path","quickfaq/".$id); $urlrewrite->setData("request_path",$this->getData('url_key')); $urlrewrite->setData("target_path",'quickfaq/index/view/id/'. $id ); try{ $urlrewrite->save(); } catch (Exception $e){ Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } } public function deleteUrlKey() { $id = $this->getId(); $url_key = $this->getData('url_key'); $urlrewrite = Mage::getModel("quickfaq/urlrewrite")->load("quickfaq/".$id,"id_path"); try{ $urlrewrite->delete(); } catch (Exception $e){ Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } } public function getMostFrequently() { $store_id = $this->getStoreId(); $limit = Mage::getStoreConfig('quickfaq/general/most_frequently_number'); if(!$store_id) { $collection = $this->getCollection() ->addFieldToFilter('most_frequently',1) ->setOrder('main_table.ordering','ASC') ->setOrder('main_table.title','ASC') ->setOrder('update_time','DESC') ->setCurPage(1) ->setPageSize($limit); } else { $collection = Mage::getSingleton('quickfaq/faqstore') ->getMostFrequently($limit); } return $collection; } public function getQuestions($category_id,$limit=0) { $store_id = $this->getStoreId(); if(!$store_id) { $collection = Mage::getResourceModel('quickfaq/faq_collection') ->join('category', 'category.category_id=main_table.category_id',array('category_id'=>'category_id')) ->addFieldToFilter("main_table.status",1) ->addFieldToFilter("category.status",1) ->addFieldToFilter('main_table.category_id',$category_id) ->setOrder('main_table.ordering','ASC') ->setOrder('main_table.title','ASC') ->setOrder('main_table.update_time','DESC') ->setCurPage(1); if($limit) { $collection->setPageSize($limit); } } else { $collection = Mage::getSingleton('quickfaq/faqstore') ->setStoreId($store_id) ->getQuestions($category_id,$limit); } return $collection; } public function getSearchResult($keyword) { $store_id = $this->getStoreId(); if(!$store_id) { $collection = Mage::getResourceModel('quickfaq/faq_collection') ->join('category', 'category.category_id=main_table.category_id',array('category_id'=>'category_id')) ->addFieldToFilter("main_table.status",1) ->addFieldToFilter("category.status",1) ->setOrder('main_table.ordering','ASC') ->setOrder('main_table.title','ASC') ->setOrder('main_table.update_time','DESC'); $collection->getSelect()->where("main_table.title like '%".$keyword."%' or main_table.description like '%".$keyword."%'"); } else { $collection = Mage::getModel('quickfaq/faqstore') ->setStoreId($store_id) ->getSearchResult($keyword); } return $collection; } }