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: /**
29: * List of products tagged by customer Block
30: *
31: * @category Mage
32: * @package Mage_Tag
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Tag_Block_Customer_View extends Mage_Catalog_Block_Product_Abstract
36: {
37: /**
38: * Tagged Product Collection
39: *
40: * @var Mage_Tag_Model_Mysql4_Product_Collection
41: */
42: protected $_collection;
43:
44: /**
45: * Current Tag object
46: *
47: * @var Mage_Tag_Model_Tag
48: */
49: protected $_tagInfo;
50:
51: /**
52: * Initialize block
53: *
54: */
55: protected function _construct()
56: {
57: parent::_construct();
58: $this->setTagId(Mage::registry('tagId'));
59: }
60:
61: /**
62: * Retrieve current Tag object
63: *
64: * @return Mage_Tag_Model_Tag
65: */
66: public function getTagInfo()
67: {
68: if (is_null($this->_tagInfo)) {
69: $this->_tagInfo = Mage::getModel('tag/tag')
70: ->load($this->getTagId());
71: }
72: return $this->_tagInfo;
73: }
74:
75: /**
76: * Retrieve Tagged Product Collection items
77: *
78: * @return array
79: */
80: public function getMyProducts()
81: {
82: return $this->_getCollection()->getItems();
83: }
84:
85: /**
86: * Retrieve count of Tagged Product(s)
87: *
88: * @return int
89: */
90: public function getCount()
91: {
92: return sizeof($this->getMyProducts());
93: }
94:
95: /**
96: * Retrieve Product Info URL
97: *
98: * @param int $productId
99: * @return string
100: */
101: public function getReviewUrl($productId)
102: {
103: return Mage::getUrl('review/product/list', array('id' => $productId));
104: }
105:
106: /**
107: * Preparing block layout
108: *
109: * @return Mage_Tag_Block_Customer_View
110: */
111: protected function _prepareLayout()
112: {
113: $toolbar = $this->getLayout()
114: ->createBlock('page/html_pager', 'customer_tag_list.toolbar')
115: ->setCollection($this->_getCollection());
116:
117: $this->setChild('toolbar', $toolbar);
118: return parent::_prepareLayout();
119: }
120:
121: /**
122: * Retrieve Toolbar block HTML
123: *
124: * @return string
125: */
126: public function getToolbarHtml()
127: {
128: return $this->getChildHtml('toolbar');
129: }
130:
131: /**
132: * Retrieve Current Mode
133: *
134: * @return string
135: */
136: public function getMode()
137: {
138: return $this->getChild('toolbar')->getCurrentMode();
139: }
140:
141: /**
142: * Retrieve Tagged product(s) collection
143: *
144: * @return Mage_Tag_Model_Mysql4_Product_Collection
145: */
146: protected function _getCollection()
147: {
148: if (is_null($this->_collection)) {
149: $this->_collection = Mage::getModel('tag/tag')
150: ->getEntityCollection()
151: ->addTagFilter($this->getTagId())
152: ->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId())
153: ->addStoreFilter(Mage::app()->getStore()->getId())
154: ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
155: ->setActiveFilter();
156:
157: Mage::getSingleton('catalog/product_status')
158: ->addVisibleFilterToCollection($this->_collection);
159: Mage::getSingleton('catalog/product_visibility')
160: ->addVisibleInSiteFilterToCollection($this->_collection);
161: }
162: return $this->_collection;
163: }
164: }
165: