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 collection 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_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
 36: {
 37:     /**
 38:      * Use getFlag('store_filter') & setFlag('store_filter', true) instead.
 39:      *
 40:      * @var bool
 41:      */
 42:     protected $_isStoreFilter  = false;
 43: 
 44:     /**
 45:      * Joined tables
 46:      *
 47:      * @var array
 48:      */
 49:     protected $_joinFlags      = array();
 50: 
 51:     /**
 52:      * Mapping for fields
 53:      *
 54:      * @var array
 55:      */
 56:     public $_map               = array(
 57:         'fields' => array(
 58:             'tag_id' => 'main_table.tag_id'
 59:         ),
 60:     );
 61: 
 62:     /**
 63:      * Define resource model and model
 64:      *
 65:      */
 66:     protected function _construct()
 67:     {
 68:         $this->_init('tag/tag');
 69:     }
 70: 
 71:     /**
 72:      * Loads collection
 73:      *
 74:      * @param bool $printQuery
 75:      * @param bool $logQuery
 76:      * @return Mage_Tag_Model_Resource_Tag_Collection
 77:      */
 78:     public function load($printQuery = false, $logQuery = false)
 79:     {
 80:         if ($this->isLoaded()) {
 81:             return $this;
 82:         }
 83:         parent::load($printQuery, $logQuery);
 84:         if ($this->getFlag('add_stores_after')) {
 85:             $this->_addStoresVisibility();
 86:         }
 87:         return $this;
 88:     }
 89: 
 90:     /**
 91:      * Set flag about joined table.
 92:      * setFlag method must be used in future.
 93:      *
 94:      * @deprecated after 1.3.2.3
 95:      *
 96:      * @param string $table
 97:      * @return Mage_Tag_Model_Resource_Tag_Collection
 98:      */
 99:     public function setJoinFlag($table)
100:     {
101:         $this->setFlag($table, true);
102:         return $this;
103:     }
104: 
105:     /**
106:      * Get flag's status about joined table.
107:      * getFlag method must be used in future.
108:      *
109:      * @deprecated after 1.3.2.3
110:      *
111:      * @param string $table
112:      * @return bool
113:      */
114:     public function getJoinFlag($table)
115:     {
116:         return $this->getFlag($table);
117:     }
118: 
119:     /**
120:      * Unset value of join flag.
121:      * Set false (bool) value to flag instead in future.
122:      *
123:      * @deprecated after 1.3.2.3
124:      *
125:      * @param string $table
126:      * @return Mage_Tag_Model_Resource_Tag_Collection
127:      */
128:     public function unsetJoinFlag($table = null)
129:     {
130:         $this->setFlag($table, false);
131:         return $this;
132:     }
133: 
134:     /**
135:      * Sett
136:      *
137:      * @param int $limit
138:      * @return Mage_Tag_Model_Resource_Tag_Collection
139:      */
140:     public function limit($limit)
141:     {
142:         $this->getSelect()->limit($limit);
143:         return $this;
144:     }
145: 
146:     /**
147:      * Replacing popularity by sum of popularity and base_popularity
148:      *
149:      * @param int $limit
150:      * @return Mage_Tag_Model_Resource_Tag_Collection
151:      */
152:     public function addPopularity($limit = null)
153:     {
154:         if (!$this->getFlag('popularity')) {
155:             $this->getSelect()
156:             ->joinLeft(
157:                 array('relation' => $this->getTable('tag/relation')),
158:                 'main_table.tag_id = relation.tag_id',
159:                 array()
160:             )
161:             ->joinLeft(
162:                 array('summary' => $this->getTable('tag/summary')),
163:                 'relation.tag_id = summary.tag_id AND relation.store_id = summary.store_id',
164:                 array('popularity')
165:             )
166:             ->group('main_table.tag_id');
167: 
168:             /*
169:              * Allow analytic function usage
170:              */
171:             $this->_useAnalyticFunction = true;
172: 
173:             if (!is_null($limit)) {
174:                 $this->getSelect()->limit($limit);
175:             }
176: 
177:             $this->setFlag('popularity');
178:         }
179:         return $this;
180:     }
181: 
182:     /**
183:      * Adds summary
184:      *
185:      * @param int $storeId
186:      * @return Mage_Tag_Model_Resource_Tag_Collection
187:      */
188:     public function addSummary($storeId)
189:     {
190:         if (!$this->getFlag('summary')) {
191:             $tableAlias = 'summary';
192:             $joinCondition = $this->getConnection()
193:                     ->quoteInto(' AND ' . $tableAlias . '.store_id IN(?)', $storeId);
194: 
195:             $this->getSelect()
196:                 ->joinLeft(
197:                     array($tableAlias => $this->getTable('tag/summary')),
198:                     'main_table.tag_id = ' . $tableAlias . '.tag_id' . $joinCondition,
199:                     array('store_id','popularity', 'customers', 'products'
200:                 ));
201: 
202:             $this->addFilterToMap('store_id', $tableAlias . '.store_id');
203:             $this->addFilterToMap('popularity', $tableAlias . '.popularity');
204:             $this->addFilterToMap('customers', $tableAlias . '.customers');
205:             $this->addFilterToMap('products', $tableAlias . '.products');
206: 
207:             $this->setFlag('summary', true);
208:         }
209:         return $this;
210:     }
211: 
212:     /**
213:      * Adds store visibility
214:      *
215:      * @return Mage_Tag_Model_Resource_Tag_Collection
216:      */
217:     public function addStoresVisibility()
218:     {
219:         $this->setFlag('add_stores_after', true);
220:         return $this;
221:     }
222: 
223:     /**
224:      * Adds store visibility
225:      *
226:      * @return Mage_Tag_Model_Resource_Tag_Collection
227:      */
228:     protected function _addStoresVisibility()
229:     {
230:         $tagIds = $this->getColumnValues('tag_id');
231: 
232:         $tagsStores = array();
233:         if (sizeof($tagIds) > 0) {
234:             $select = $this->getConnection()->select()
235:                 ->from($this->getTable('tag/summary'), array('store_id', 'tag_id'))
236:                 ->where('tag_id IN(?)', $tagIds);
237:             $tagsRaw = $this->getConnection()->fetchAll($select);
238: 
239:             foreach ($tagsRaw as $tag) {
240:                 if (!isset($tagsStores[$tag['tag_id']])) {
241:                     $tagsStores[$tag['tag_id']] = array();
242:                 }
243: 
244:                 $tagsStores[$tag['tag_id']][] = $tag['store_id'];
245:             }
246:         }
247: 
248:         foreach ($this as $item) {
249:             if (isset($tagsStores[$item->getId()])) {
250:                 $item->setStores($tagsStores[$item->getId()]);
251:             } else {
252:                 $item->setStores(array());
253:             }
254:         }
255: 
256:         return $this;
257:     }
258: 
259:     /**
260:      * Adds field to filter
261:      *
262:      * @param string $field
263:      * @param array $condition
264:      * @return Mage_Tag_Model_Resource_Tag_Collection
265:      */
266:     public function addFieldToFilter($field, $condition = null)
267:     {
268:         if ($this->getFlag('relation') && 'popularity' == $field) {
269:             // TOFIX
270:             $this->getSelect()->having(
271:                 $this->_getConditionSql('COUNT(relation.tag_relation_id)', $condition)
272:             );
273:         } elseif ($this->getFlag('summary') && in_array(
274:             $field, array('customers', 'products', 'uses', 'historical_uses', 'popularity')
275:         )) {
276:             $this->getSelect()->where($this->_getConditionSql('summary.' . $field, $condition));
277:         } else {
278:            parent::addFieldToFilter($field, $condition);
279:         }
280:         return $this;
281:     }
282: 
283:     /**
284:      * Get sql for get record count
285:      *
286:      * @return string
287:      */
288:     public function getSelectCountSql()
289:     {
290:         $select = parent::getSelectCountSql();
291: 
292:         $select->reset(Zend_Db_Select::COLUMNS);
293:         $select->reset(Zend_Db_Select::GROUP);
294:         $select->reset(Zend_Db_Select::HAVING);
295:         $select->columns('COUNT(DISTINCT main_table.tag_id)');
296:         return $select;
297:     }
298: 
299:     /**
300:      * Add filter by store
301:      *
302:      * @param array | int $storeId
303:      * @param bool $allFilter
304:      * @return Mage_Tag_Model_Resource_Tag_Collection
305:      */
306:     public function addStoreFilter($storeId, $allFilter = true)
307:     {
308:         if (!$this->getFlag('store_filter')) {
309: 
310:             $this->getSelect()->joinLeft(
311:                 array('summary_store' => $this->getTable('tag/summary')),
312:                 'main_table.tag_id = summary_store.tag_id'
313:             );
314: 
315:             $this->getSelect()->where('summary_store.store_id IN (?)', $storeId);
316: 
317:             $this->getSelect()->group('main_table.tag_id');
318: 
319:             if ($this->getFlag('relation') && $allFilter) {
320:                 $this->getSelect()->where('relation.store_id IN (?)', $storeId);
321:             }
322:             if ($this->getFlag('prelation') && $allFilter) {
323:                 $this->getSelect()->where('prelation.store_id IN (?)', $storeId);
324:             }
325: 
326:             /*
327:              * Allow Analytic functions usage
328:              */
329: 
330:             $this->_useAnalyticFunction = true;
331: 
332:             $this->setFlag('store_filter', true);
333:         }
334: 
335:         return $this;
336:     }
337: 
338:     /**
339:      * Adds filtering by active
340:      *
341:      * @return Mage_Tag_Model_Resource_Tag_Collection
342:      */
343:     public function setActiveFilter()
344:     {
345:         $statusActive = Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE;
346:         $this->getSelect()->where('relation.active = ?', $statusActive);
347:         if ($this->getFlag('prelation')) {
348:             $this->getSelect()->where('prelation.active = ?', $statusActive);
349:         }
350:         return $this;
351:     }
352: 
353:     /**
354:      * Adds filter by status
355:      *
356:      * @param int $status
357:      * @return Mage_Tag_Model_Resource_Tag_Collection
358:      */
359:     public function addStatusFilter($status)
360:     {
361:         $this->getSelect()->where('main_table.status = ?', $status);
362:         return $this;
363:     }
364: 
365:     /**
366:      * Adds filter by product id
367:      *
368:      * @param int $productId
369:      * @return Mage_Tag_Model_Resource_Tag_Collection
370:      */
371:     public function addProductFilter($productId)
372:     {
373:         $this->addFieldToFilter('relation.product_id', $productId);
374:         if ($this->getFlag('prelation')) {
375:             $this->addFieldToFilter('prelation.product_id', $productId);
376:         }
377:         return $this;
378:     }
379: 
380:     /**
381:      * Adds filter by customer id
382:      *
383:      * @param int $customerId
384:      * @return Mage_Tag_Model_Resource_Tag_Collection
385:      */
386:     public function addCustomerFilter($customerId)
387:     {
388:         $this->getSelect()
389:             ->where('relation.customer_id = ?', $customerId);
390:         if ($this->getFlag('prelation')) {
391:             $this->getSelect()
392:                 ->where('prelation.customer_id = ?', $customerId);
393:         }
394:         return $this;
395:     }
396: 
397:     /**
398:      * Adds grouping by tag id
399:      *
400:      * @return Mage_Tag_Model_Resource_Tag_Collection
401:      */
402:     public function addTagGroup()
403:     {
404:         $this->getSelect()->group('main_table.tag_id');
405:         $this->_useAnalyticFunction = true;
406:         return $this;
407:     }
408: 
409:     /**
410:      * Joins tag/relation table
411:      *
412:      * @return Mage_Tag_Model_Resource_Tag_Collection
413:      */
414:     public function joinRel()
415:     {
416:         $this->setFlag('relation', true);
417:         $this->getSelect()->joinLeft(
418:             array('relation' => $this->getTable('tag/relation')),
419:             'main_table.tag_id=relation.tag_id'
420:         );
421:         return $this;
422:     }
423: }
424: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0