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: /**
 29:  * Tag Relation resource model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Tag
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Tag_Model_Resource_Tag_Relation extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Initialize resource connection and define table resource
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('tag/relation', 'tag_relation_id');
 44:     }
 45: 
 46:     /**
 47:      * Load by Tag and Customer
 48:      *
 49:      * @param Mage_Tag_Model_Tag_Relation $model
 50:      * @return Mage_Tag_Model_Resource_Tag_Relation
 51:      */
 52:     public function loadByTagCustomer($model)
 53:     {
 54:         if ($model->getTagId() && $model->getCustomerId()) {
 55:             $read = $this->_getReadAdapter();
 56:             $bind = array(
 57:                 'tag_id'      => $model->getTagId(),
 58:                 'customer_id' => $model->getCustomerId()
 59:             );
 60: 
 61:             $select = $read->select()
 62:                 ->from($this->getMainTable())
 63:                 ->join(
 64:                     $this->getTable('tag/tag'),
 65:                     $this->getTable('tag/tag') . '.tag_id = ' . $this->getMainTable() . '.tag_id'
 66:                 )
 67:                 ->where($this->getMainTable() . '.tag_id = :tag_id')
 68:                 ->where('customer_id = :customer_id');
 69: 
 70:             if ($model->getProductId()) {
 71:                 $select->where($this->getMainTable() . '.product_id = :product_id');
 72:                 $bind['product_id'] = $model->getProductId();
 73:             }
 74: 
 75:             if ($model->hasStoreId()) {
 76:                 $select->where($this->getMainTable() . '.store_id = :sore_id');
 77:                 $bind['sore_id'] = $model->getStoreId();
 78:             }
 79:             $data = $read->fetchRow($select, $bind);
 80:             $model->setData(( is_array($data) ) ? $data : array());
 81:         }
 82: 
 83:         return $this;
 84:     }
 85: 
 86:     /**
 87:      * Retrieve Tagged Products
 88:      *
 89:      * @param Mage_Tag_Model_Tag_Relation $model
 90:      * @return array
 91:      */
 92:     public function getProductIds($model)
 93:     {
 94:         $bind = array(
 95:             'tag_id' => $model->getTagId()
 96:         );
 97:         $select = $this->_getReadAdapter()->select()
 98:             ->from($this->getMainTable(), 'product_id')
 99:             ->where($this->getMainTable() . '.tag_id=:tag_id');
100: 
101:         if (!is_null($model->getCustomerId())) {
102:             $select->where($this->getMainTable() . '.customer_id= :customer_id');
103:             $bind['customer_id'] = $model->getCustomerId();
104:         }
105: 
106:         if ($model->hasStoreId()) {
107:             $select->where($this->getMainTable() . '.store_id = :store_id');
108:             $bind['store_id'] = $model->getStoreId();
109:         }
110: 
111:         if (!is_null($model->getStatusFilter())) {
112:             $select->join(
113:                 $this->getTable('tag/tag'),
114:                 $this->getTable('tag/tag') . '.tag_id = ' . $this->getMainTable() . '.tag_id'
115:             )
116:             ->where($this->getTable('tag/tag') . '.status = :t_status');
117:             $bind['t_status'] = $model->getStatusFilter();
118:         }
119: 
120:         return $this->_getReadAdapter()->fetchCol($select, $bind);
121:     }
122: 
123:     /**
124:      * Retrieve related to product tag ids
125:      *
126:      * @param Mage_Tag_Model_Tag_Relation $model
127:      * @return array
128:      */
129:     public function getRelatedTagIds($model)
130:     {
131:         $productIds = (is_array($model->getProductId())) ? $model->getProductId() : array($model->getProductId());
132:         $select = $this->_getReadAdapter()->select()
133:             ->from($this->getMainTable(), 'tag_id')
134:             ->where("product_id IN(?)", $productIds)
135:             ->order('tag_id');
136:         return $this->_getReadAdapter()->fetchCol($select);
137:     }
138: 
139:     /**
140:      * Deactivate tag relations by tag and customer
141:      *
142:      * @param int $tagId
143:      * @param int $customerId
144:      * @return Mage_Tag_Model_Resource_Tag_Relation
145:      */
146:     public function deactivate($tagId, $customerId)
147:     {
148:         $condition = array(
149:             'tag_id = ?'      => $tagId,
150:             'customer_id = ?' => $customerId
151:         );
152: 
153:         $data = array('active' => Mage_Tag_Model_Tag_Relation::STATUS_NOT_ACTIVE);
154:         $this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
155:         return $this;
156:     }
157: 
158:     /**
159:      * Add TAG to PRODUCT relations
160:      *
161:      * @param Mage_Tag_Model_Tag_Relation $model
162:      * @return Mage_Tag_Model_Resource_Tag_Relation
163:      */
164:     public function addRelations($model)
165:     {
166:         $addedIds = $model->getAddedProductIds();
167: 
168:         $bind = array(
169:             'tag_id'   => $model->getTagId(),
170:             'store_id' => $model->getStoreId()
171:         );
172:         $write = $this->_getWriteAdapter();
173: 
174:         $select = $write->select()
175:             ->from($this->getMainTable(), 'product_id')
176:             ->where('tag_id = :tag_id')
177:             ->where('store_id = :store_id');
178:         $oldRelationIds = $write->fetchCol($select, $bind);
179: 
180:         $insert = array_diff($addedIds, $oldRelationIds);
181:         $delete = array_diff($oldRelationIds, $addedIds);
182: 
183:         if (!empty($insert)) {
184:             $insertData = array();
185:             foreach ($insert as $value) {
186:                 $insertData[] = array(
187:                     'tag_id'        => $model->getTagId(),
188:                     'store_id'      => $model->getStoreId(),
189:                     'product_id'    => $value,
190:                     'customer_id'   => $model->getCustomerId(),
191:                     'created_at'    => $this->formatDate(time())
192:                 );
193:             }
194:             $write->insertMultiple($this->getMainTable(), $insertData);
195:         }
196: 
197:         if (!empty($delete)) {
198:             $write->delete($this->getMainTable(), array(
199:                 'product_id IN (?)' => $delete,
200:                 'store_id = ?'      => $model->getStoreId(),
201:             ));
202:         }
203: 
204:         return $this;
205:     }
206: }
207: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0