00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class Mage_CatalogSearch_Block_Term extends Mage_Core_Block_Template
00028 {
00029 protected $_terms;
00030 protected $_minPopularity;
00031 protected $_maxPopularity;
00032
00033 public function __construct()
00034 {
00035 parent::__construct();
00036 }
00037
00038 protected function _loadTerms()
00039 {
00040 if (empty($this->_terms)) {
00041 $this->_terms = array();
00042 $terms = Mage::getResourceModel('catalogsearch/query_collection')
00043 ->setPopularQueryFilter(Mage::app()->getStore()->getId())
00044 ->setOrder('popularity', 'DESC')
00045 ->setPageSize(100)
00046 ->load()
00047 ->getItems();
00048
00049 if( count($terms) == 0 ) {
00050 return $this;
00051 }
00052
00053
00054 $this->_maxPopularity = reset($terms)->getPopularity();
00055 $this->_minPopularity = end($terms)->getPopularity();
00056 $range = $this->_maxPopularity - $this->_minPopularity;
00057 $range = ( $range == 0 ) ? 1 : $range;
00058 foreach ($terms as $term) {
00059 if( !$term->getPopularity() ) {
00060 continue;
00061 }
00062 $term->setRatio(($term->getPopularity()-$this->_minPopularity)/$range);
00063 $this->_terms[$term->getName()] = $term;
00064 }
00065 ksort($this->_terms);
00066 }
00067 return $this;
00068 }
00069
00070 public function getTerms()
00071 {
00072 $this->_loadTerms();
00073 return $this->_terms;
00074 }
00075
00076 public function getSearchUrl($obj)
00077 {
00078 $url = Mage::getModel('core/url');
00079
00080
00081
00082
00083 $url->setQueryParam('q', $obj->getName());
00084 return $url->getUrl('catalogsearch/result');
00085 }
00086
00087 public function getMaxPopularity()
00088 {
00089 return $this->_maxPopularity;
00090 }
00091
00092 public function getMinPopularity()
00093 {
00094 return $this->_minPopularity;
00095 }
00096 }