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
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Tag_Block_Popular extends Mage_Core_Block_Template
00036 {
00037
00038 protected $_tags;
00039 protected $_minPopularity;
00040 protected $_maxPopularity;
00041
00042 protected function _loadTags()
00043 {
00044 if (empty($this->_tags)) {
00045 $this->_tags = array();
00046
00047 $tags = Mage::getModel('tag/tag')->getPopularCollection()
00048 ->joinFields(Mage::app()->getStore()->getId())
00049 ->limit(20)
00050 ->load()
00051 ->getItems();
00052
00053 if( count($tags) == 0 ) {
00054 return $this;
00055 }
00056
00057
00058 $this->_maxPopularity = reset($tags)->getPopularity();
00059 $this->_minPopularity = end($tags)->getPopularity();
00060 $range = $this->_maxPopularity - $this->_minPopularity;
00061 $range = ( $range == 0 ) ? 1 : $range;
00062 foreach ($tags as $tag) {
00063 if( !$tag->getPopularity() ) {
00064 continue;
00065 }
00066 $tag->setRatio(($tag->getPopularity()-$this->_minPopularity)/$range);
00067 $this->_tags[$tag->getName()] = $tag;
00068 }
00069 ksort($this->_tags);
00070 }
00071 return $this;
00072 }
00073
00074 public function getTags()
00075 {
00076 $this->_loadTags();
00077 return $this->_tags;
00078 }
00079
00080 public function getMaxPopularity()
00081 {
00082 return $this->_maxPopularity;
00083 }
00084
00085 public function getMinPopularity()
00086 {
00087 return $this->_minPopularity;
00088 }
00089
00090 protected function _toHtml()
00091 {
00092 if (count($this->getTags()) > 0) {
00093 return parent::_toHtml();
00094 }
00095 return '';
00096 }
00097 }