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:  * Tags customer collection
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Tag
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Tag_Model_Resource_Customer_Collection extends Mage_Customer_Model_Resource_Customer_Collection
 36: {
 37:     /**
 38:      * Allows disabling grouping
 39:      *
 40:      * @var bool
 41:      */
 42:     protected $_allowDisableGrouping     = true;
 43: 
 44:     /**
 45:      * Count attribute for count sql
 46:      *
 47:      * @var string
 48:      */
 49:     protected $_countAttribute           = 'tr.tag_id';
 50: 
 51:     /**
 52:      * Array with joined tables
 53:      *
 54:      * @var array
 55:      */
 56:     protected $_joinFlags                = array();
 57: 
 58:     /**
 59:      * Prepare select
 60:      *
 61:      * @return Mage_Tag_Model_Resource_Customer_Collection
 62:      */
 63:     public function _initSelect()
 64:     {
 65:         parent::_initSelect();
 66:         $this->_joinFields();
 67:         $this->_setIdFieldName('tag_relation_id');
 68:         return $this;
 69:     }
 70: 
 71:     /**
 72:      * Set flag about joined table.
 73:      * setFlag method must be used in future.
 74:      *
 75:      * @deprecated after 1.3.2.3
 76:      *
 77:      * @param string $table
 78:      * @return Mage_Tag_Model_Resource_Customer_Collection
 79:      */
 80:     public function setJoinFlag($table)
 81:     {
 82:         $this->setFlag($table, true);
 83:         return $this;
 84:     }
 85: 
 86:     /**
 87:      * Get flag's status about joined table.
 88:      * getFlag method must be used in future.
 89:      *
 90:      * @deprecated after 1.3.2.3
 91:      *
 92:      * @param string $table
 93:      * @return bool
 94:      */
 95:     public function getJoinFlag($table)
 96:     {
 97:         return $this->getFlag($table);
 98:     }
 99: 
100:     /**
101:      * Unset value of join flag.
102:      * Set false (bool) value to flag instead in future.
103:      *
104:      * @deprecated after 1.3.2.3
105:      *
106:      * @param string $table
107:      * @return Mage_Tag_Model_Resource_Customer_Collection
108:      */
109:     public function unsetJoinFlag($table = null)
110:     {
111:         $this->setFlag($table, false);
112:         return $this;
113:     }
114: 
115:     /**
116:      * Adds filter by tag is
117:      *
118:      * @param int $tagId
119:      * @return Mage_Tag_Model_Resource_Customer_Collection
120:      */
121:     public function addTagFilter($tagId)
122:     {
123:         $this->getSelect()
124:             ->where('tr.tag_id = ?', $tagId);
125:         return $this;
126:     }
127: 
128:     /**
129:      * adds filter by product id
130:      *
131:      * @param int $productId
132:      * @return Mage_Tag_Model_Resource_Customer_Collection
133:      */
134:     public function addProductFilter($productId)
135:     {
136:         $this->getSelect()
137:             ->where('tr.product_id = ?', $productId);
138:         return $this;
139:     }
140: 
141:     /**
142:      * Apply filter by store id(s).
143:      *
144:      * @param int|array $storeId
145:      * @return Mage_Tag_Model_Resource_Customer_Collection
146:      */
147:     public function addStoreFilter($storeId)
148:     {
149:         $this->getSelect()->where('tr.store_id IN (?)', $storeId);
150:         return $this;
151:     }
152: 
153:     /**
154:      * Adds filter by status
155:      *
156:      * @param int $status
157:      * @return Mage_Tag_Model_Resource_Customer_Collection
158:      */
159:     public function addStatusFilter($status)
160:     {
161:         $this->getSelect()
162:             ->where('t.status = ?', $status);
163:         return $this;
164:     }
165: 
166:     /**
167:      * Adds desc order by tag relation id
168:      *
169:      * @return Mage_Tag_Model_Resource_Customer_Collection
170:      */
171:     public function addDescOrder()
172:     {
173:         $this->getSelect()
174:             ->order('tr.tag_relation_id desc');
175:         return $this;
176:     }
177: 
178:     /**
179:      * Adds grouping by tag id
180:      *
181:      * @return Mage_Tag_Model_Resource_Customer_Collection
182:      */
183:     public function addGroupByTag()
184:     {
185:         $this->getSelect()
186:             ->group('tr.tag_id');
187: 
188:         /*
189:          * Allow analytic functions usage
190:          */
191:         $this->_useAnalyticFunction = true;
192: 
193:         $this->_allowDisableGrouping = true;
194:         return $this;
195:     }
196: 
197:     /**
198:      * Adds grouping by customer id
199:      *
200:      * @return Mage_Tag_Model_Resource_Customer_Collection
201:      */
202:     public function addGroupByCustomer()
203:     {
204:         $this->getSelect()
205:             ->group('tr.customer_id');
206: 
207:         $this->_allowDisableGrouping = false;
208:         return $this;
209:     }
210: 
211:     /**
212:      * Disables grouping
213:      *
214:      * @return Mage_Tag_Model_Resource_Customer_Collection
215:      */
216:     public function addGroupByCustomerProduct()
217:     {
218:         // Nothing need to group
219:         $this->_allowDisableGrouping = false;
220:         return $this;
221:     }
222: 
223:     /**
224:      * Adds filter by customer id
225:      *
226:      * @param int $customerId
227:      * @return Mage_Tag_Model_Resource_Customer_Collection
228:      */
229:     public function addCustomerFilter($customerId)
230:     {
231:         $this->getSelect()->where('tr.customer_id = ?', $customerId);
232:         return $this;
233:     }
234: 
235:     /**
236:      * Joins tables to select
237:      *
238:      */
239:     protected function _joinFields()
240:     {
241:         $tagRelationTable = $this->getTable('tag/relation');
242:         $tagTable = $this->getTable('tag/tag');
243: 
244:         //TODO: add full name logic
245:         $this->addAttributeToSelect('firstname')
246:             ->addAttributeToSelect('lastname')
247:             ->addAttributeToSelect('email');
248: 
249:         $this->getSelect()
250:         ->join(
251:             array('tr' => $tagRelationTable),
252:             'tr.customer_id = e.entity_id',
253:             array('tag_relation_id', 'product_id', 'active')
254:         )
255:         ->join(array('t' => $tagTable), 't.tag_id = tr.tag_id', array('*'));
256:     }
257: 
258:     /**
259:      * Gets number of rows
260:      *
261:      * @return Varien_Db_Select
262:      */
263:     public function getSelectCountSql()
264:     {
265:         $countSelect = parent::getSelectCountSql();
266: 
267:         if ($this->_allowDisableGrouping) {
268:             $countSelect->reset(Zend_Db_Select::COLUMNS);
269:             $countSelect->reset(Zend_Db_Select::GROUP);
270:             $countSelect->columns('COUNT(DISTINCT ' . $this->getCountAttribute() . ')');
271:         }
272:         return $countSelect;
273:     }
274: 
275:     /**
276:      * Adds Product names to select
277:      *
278:      * @return Mage_Tag_Model_Resource_Customer_Collection
279:      */
280:     public function addProductName()
281:     {
282:         $productsId = array();
283:         $productsData = array();
284: 
285:         foreach ($this->getItems() as $item) {
286:             $productsId[] = $item->getProductId();
287:         }
288: 
289:         $productsId = array_unique($productsId);
290: 
291:         /* small fix */
292:         if ( sizeof($productsId) == 0 ) {
293:             return;
294:         }
295: 
296:         $collection = Mage::getModel('catalog/product')->getCollection()
297:             ->addAttributeToSelect('name')
298:             ->addAttributeToSelect('sku')
299:             ->addIdFilter($productsId);
300: 
301:         $collection->load();
302: 
303:         foreach ($collection->getItems() as $item) {
304:             $productsData[$item->getId()] = $item->getName();
305:             $productsSku[$item->getId()] = $item->getSku();
306:         }
307: 
308:         foreach ($this->getItems() as $item) {
309:             $item->setProduct($productsData[$item->getProductId()]);
310:             $item->setProductSku($productsSku[$item->getProductId()]);
311:         }
312:         return $this;
313:     }
314: 
315:     /**
316:      * Sets order by attribute
317:      *
318:      * @param string $attribute
319:      * @param string $dir
320:      * @return Mage_Tag_Model_Resource_Customer_Collection
321:      */
322:     public function setOrder($attribute, $dir = 'desc')
323:     {
324:         switch( $attribute ) {
325:             case 'name':
326:             case 'status':
327:                 $this->getSelect()->order($attribute . ' ' . $dir);
328:                 break;
329: 
330:             default:
331:                 parent::setOrder($attribute, $dir);
332:         }
333:         return $this;
334:     }
335: 
336:     /**
337:      * Sets attribute for count
338:      *
339:      * @param string $value
340:      * @return Mage_Tag_Model_Resource_Customer_Collection
341:      */
342:     public function setCountAttribute($value)
343:     {
344:         $this->_countAttribute = $value;
345:         return $this;
346:     }
347: 
348:     /**
349:      * Gets attribure for count
350:      *
351:      * @return string
352:      */
353:     public function getCountAttribute()
354:     {
355:         return $this->_countAttribute;
356:     }
357: 
358:     /**
359:      * Adds field to filter
360:      *
361:      * @param string $attribute
362:      * @param array $condition
363:      * @return Mage_Tag_Model_Resource_Customer_Collection
364:      */
365:     public function addFieldToFilter($attribute, $condition = null)
366:     {
367:         if ($attribute == 'name') {
368:             $where = $this->_getConditionSql('t.name', $condition);
369:             $this->getSelect()->where($where, null, Varien_Db_Select::TYPE_CONDITION);
370:             return $this;
371:         } else {
372:             return parent::addFieldToFilter($attribute, $condition);
373:         }
374:     }
375: 
376: }
377: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0