1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Tag
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Tags list in customer's account
29: *
30: * @category Mage
31: * @package Mage_Tag
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34:
35: class Mage_Tag_Block_Customer_Tags extends Mage_Customer_Block_Account_Dashboard
36: {
37: protected $_tags;
38: protected $_minPopularity;
39: protected $_maxPopularity;
40:
41: protected function _loadTags()
42: {
43: if (empty($this->_tags)) {
44: $this->_tags = array();
45:
46: $tags = Mage::getResourceModel('tag/tag_collection')
47: ->addPopularity(null, Mage::app()->getStore()->getId())
48: ->setOrder('popularity', 'DESC')
49: ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId())
50: ->setActiveFilter()
51: ->load()
52: ->getItems();
53: } else {
54: return;
55: }
56:
57: if( isset($tags) && count($tags) == 0 ) {
58: return;
59: }
60:
61: $this->_maxPopularity = reset($tags)->getPopularity();
62: $this->_minPopularity = end($tags)->getPopularity();
63: $range = $this->_maxPopularity - $this->_minPopularity;
64: $range = ( $range == 0 ) ? 1 : $range;
65:
66: foreach ($tags as $tag) {
67: $tag->setRatio(($tag->getPopularity()-$this->_minPopularity)/$range);
68: $this->_tags[$tag->getName()] = $tag;
69: }
70: ksort($this->_tags);
71: }
72:
73: public function getTags()
74: {
75: $this->_loadTags();
76: return $this->_tags;
77: }
78:
79: public function getMaxPopularity()
80: {
81: return $this->_maxPopularity;
82: }
83:
84: public function getMinPopularity()
85: {
86: return $this->_minPopularity;
87: }
88: }
89: