Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Tag_Block_All
  • Mage_Tag_Block_Customer_Recent
  • Mage_Tag_Block_Customer_Tags
  • Mage_Tag_Block_Customer_View
  • Mage_Tag_Block_Popular
  • Mage_Tag_Block_Product_List
  • Mage_Tag_Block_Product_Result
  • Mage_Tag_CustomerController
  • Mage_Tag_Helper_Data
  • Mage_Tag_IndexController
  • Mage_Tag_ListController
  • Mage_Tag_Model_Api
  • Mage_Tag_Model_Api_V2
  • Mage_Tag_Model_Entity_Customer_Collection
  • Mage_Tag_Model_Indexer_Summary
  • Mage_Tag_Model_Mysql4_Customer_Collection
  • Mage_Tag_Model_Mysql4_Indexer_Summary
  • Mage_Tag_Model_Mysql4_Popular_Collection
  • Mage_Tag_Model_Mysql4_Product_Collection
  • Mage_Tag_Model_Mysql4_Tag
  • Mage_Tag_Model_Mysql4_Tag_Collection
  • Mage_Tag_Model_Mysql4_Tag_Relation
  • Mage_Tag_Model_Resource_Customer_Collection
  • Mage_Tag_Model_Resource_Indexer_Summary
  • Mage_Tag_Model_Resource_Popular_Collection
  • Mage_Tag_Model_Resource_Product_Collection
  • Mage_Tag_Model_Resource_Tag
  • Mage_Tag_Model_Resource_Tag_Collection
  • Mage_Tag_Model_Resource_Tag_Relation
  • Mage_Tag_Model_Session
  • Mage_Tag_Model_Tag
  • Mage_Tag_Model_Tag_Relation
  • Mage_Tag_ProductController
  • Overview
  • Package
  • Class
  • Tree
  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:  * Customers collection
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Tag
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: 
 35: class Mage_Tag_Model_Entity_Customer_Collection extends Mage_Customer_Model_Entity_Customer_Collection
 36: {
 37:     protected $_tagTable;
 38:     protected $_tagRelTable;
 39: 
 40:     public function __construct()
 41:     {
 42:         $resource = Mage::getSingleton('core/resource');
 43:         parent::__construct();
 44:         $this->_tagTable = $resource->getTableName('tag/tag');
 45:         $this->_tagRelTable = $resource->getTableName('tag/tag_relation');
 46: 
 47: //        $this->joinField('tag_total_used', $this->_tagRelTable, 'count(_table_tag_total_used.tag_relations_id)', 'entity_val_id=entity_id', array('entity_id' => '2'));
 48: //        $this->getSelect()->group('tag_tag_id');
 49: //        echo $this->getSelect();
 50: //        $this->_productTable = $resource->getTableName('catalog/product');
 51: //        $this->_select->from(array('p' => $this->_productTable))
 52: //            ->join(array('tr' => $this->_tagRelTable), 'tr.entity_val_id=p.product_id and tr.entity_id=1', array('total_used' => 'count(tr.tag_relations_id)'))
 53: //            ->group('p.product_id', 'tr.tag_id')
 54: //        ;
 55: 
 56:     }
 57: 
 58:     public function addTagFilter($tagId)
 59:     {
 60:         $this->joinField('tag_tag_id', $this->_tagRelTable, 'tag_id', 'customer_id=entity_id');
 61:         $this->getSelect()->where($this->_getAttributeTableAlias('tag_tag_id') . '.tag_id=?', $tagId);
 62:         return $this;
 63:     }
 64: 
 65:     public function addProductFilter($productId)
 66:     {
 67:         $this->joinField('tag_product_id', $this->_tagRelTable, 'product_id', 'customer_id=entity_id');
 68:         $this->getSelect()->where($this->_getAttributeTableAlias('tag_product_id') . '.product_id=?', $productId);
 69:         return $this;
 70:     }
 71: 
 72:     public function load($printQuery = false, $logQuery = false)
 73:     {
 74:         parent::load($printQuery, $logQuery);
 75:         $this->_loadTags($printQuery, $logQuery);
 76:         return $this;
 77:     }
 78: 
 79:     protected function _loadTags($printQuery = false, $logQuery = false)
 80:     {
 81:         if (empty($this->_items)) {
 82:             return $this;
 83:         }
 84:         $customerIds = array();
 85:         foreach ($this->getItems() as $item) {
 86:             $customerIds[] = $item->getId();
 87:         }
 88:         $this->getSelect()->reset()
 89:             ->from(array('tr' => $this->_tagRelTable), array('*','total_used' => 'count(tr.tag_relation_id)'))
 90:             ->joinLeft(array('t' => $this->_tagTable),'t.tag_id=tr.tag_id')
 91:             ->group(array('tr.customer_id', 't.tag_id'))
 92:             ->where('tr.customer_id in (?)',$customerIds)
 93:         ;
 94:         $this->printLogQuery($printQuery, $logQuery);
 95: 
 96:         $tags = array();
 97:         $data = $this->_read->fetchAll($this->getSelect());
 98:         foreach ($data as $row) {
 99:             if (!isset($tags[ $row['customer_id'] ])) {
100:                 $tags[ $row['customer_id'] ] = array();
101:             }
102:             $tags[ $row['customer_id'] ][] = $row;
103:         }
104:         foreach ($this->getItems() as $item) {
105:             if (isset($tags[$item->getId()])) {
106:                 $item->setData('tags', $tags[$item->getId()]);
107:             }
108:         }
109:         return $this;
110:     }
111: 
112: }
113: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0