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:  * Tag model
 29:  *
 30:  * @method Mage_Tag_Model_Resource_Tag _getResource()
 31:  * @method Mage_Tag_Model_Resource_Tag getResource()
 32:  * @method Mage_Tag_Model_Tag setName(string $value)
 33:  * @method int getStatus()
 34:  * @method Mage_Tag_Model_Tag setStatus(int $value)
 35:  * @method int getFirstCustomerId()
 36:  * @method Mage_Tag_Model_Tag setFirstCustomerId(int $value)
 37:  * @method int getFirstStoreId()
 38:  * @method Mage_Tag_Model_Tag setFirstStoreId(int $value)
 39:  *
 40:  * @category    Mage
 41:  * @package     Mage_Tag
 42:  * @author      Magento Core Team <core@magentocommerce.com>
 43:  */
 44: 
 45: class Mage_Tag_Model_Tag extends Mage_Core_Model_Abstract
 46: {
 47:     const STATUS_DISABLED = -1;
 48:     const STATUS_PENDING = 0;
 49:     const STATUS_APPROVED = 1;
 50: 
 51:     // statuses for tag relation add
 52:     const ADD_STATUS_SUCCESS = 'success';
 53:     const ADD_STATUS_NEW = 'new';
 54:     const ADD_STATUS_EXIST = 'exist';
 55:     const ADD_STATUS_REJECTED = 'rejected';
 56: 
 57:     /**
 58:      * Entity code.
 59:      * Can be used as part of method name for entity processing
 60:      */
 61:     const ENTITY = 'tag';
 62: 
 63:     /**
 64:      * Event prefix for observer
 65:      *
 66:      * @var string
 67:      */
 68:     protected $_eventPrefix = 'tag';
 69: 
 70:     /**
 71:      * This flag means should we or not add base popularity on tag load
 72:      *
 73:      * @var bool
 74:      */
 75:     protected $_addBasePopularity = false;
 76: 
 77:     protected function _construct()
 78:     {
 79:         $this->_init('tag/tag');
 80:     }
 81: 
 82:     /**
 83:      * Init indexing process after tag data commit
 84:      *
 85:      * @return Mage_Tag_Model_Tag
 86:      */
 87:     public function afterCommitCallback()
 88:     {
 89:         parent::afterCommitCallback();
 90:         Mage::getSingleton('index/indexer')->processEntityAction(
 91:             $this, self::ENTITY, Mage_Index_Model_Event::TYPE_SAVE
 92:         );
 93:         return $this;
 94:     }
 95: 
 96:     /**
 97:      * Setter for addBasePopularity flag
 98:      *
 99:      * @param bool $flag
100:      * @return Mage_Tag_Model_Tag
101:      */
102:     public function setAddBasePopularity($flag = true)
103:     {
104:         $this->_addBasePopularity = $flag;
105:         return $this;
106:     }
107: 
108:     /**
109:      * Getter for addBasePopularity flag
110:      *
111:      * @return bool
112:      */
113:     public function getAddBasePopularity()
114:     {
115:         return $this->_addBasePopularity;
116:     }
117: 
118:     /**
119:      * Product event tags collection getter
120:      *
121:      * @param  Varien_Event_Observer $observer
122:      * @return Mage_Tag_Model_Mysql4_Tag_Collection
123:      */
124:     protected function _getProductEventTagsCollection(Varien_Event_Observer $observer)
125:     {
126:         return $this->getResourceCollection()
127:                         ->joinRel()
128:                         ->addProductFilter($observer->getEvent()->getProduct()->getId())
129:                         ->addTagGroup()
130:                         ->load();
131:     }
132: 
133:     public function getPopularity()
134:     {
135:         return $this->_getData('popularity');
136:     }
137: 
138:     public function getName()
139:     {
140:         return $this->_getData('name');
141:     }
142: 
143:     public function getTagId()
144:     {
145:         return $this->_getData('tag_id');
146:     }
147: 
148:     public function getRatio()
149:     {
150:         return $this->_getData('ratio');
151:     }
152: 
153:     public function setRatio($ratio)
154:     {
155:         $this->setData('ratio', $ratio);
156:         return $this;
157:     }
158: 
159:     public function loadByName($name)
160:     {
161:         $this->_getResource()->loadByName($this, $name);
162:         return $this;
163:     }
164: 
165:     public function aggregate()
166:     {
167:         $this->_getResource()->aggregate($this);
168:         return $this;
169:     }
170: 
171:     public function productEventAggregate($observer)
172:     {
173:         $this->_getProductEventTagsCollection($observer)->walk('aggregate');
174:         return $this;
175:     }
176: 
177:     /**
178:      * Product delete event action
179:      *
180:      * @param  Varien_Event_Observer $observer
181:      * @return Mage_Tag_Model_Tag
182:      */
183:     public function productDeleteEventAction($observer)
184:     {
185:         $this->_getResource()->decrementProducts($this->_getProductEventTagsCollection($observer)->getAllIds());
186:         return $this;
187:     }
188: 
189:     /**
190:      * Add summary data to current object
191:      *
192:      * @deprecated after 1.4.0.0
193:      * @param int $storeId
194:      * @return Mage_Tag_Model_Tag
195:      */
196:     public function addSummary($storeId)
197:     {
198:         $this->setStoreId($storeId);
199:         $this->_getResource()->addSummary($this);
200:         return $this;
201:     }
202: 
203:     /**
204:      * getter for self::STATUS_APPROVED
205:      */
206:     public function getApprovedStatus()
207:     {
208:         return self::STATUS_APPROVED;
209:     }
210: 
211:     /**
212:      * getter for self::STATUS_PENDING
213:      */
214:     public function getPendingStatus()
215:     {
216:         return self::STATUS_PENDING;
217:     }
218: 
219:     /**
220:      * getter for self::STATUS_DISABLED
221:      */
222:     public function getDisabledStatus()
223:     {
224:         return self::STATUS_DISABLED;
225:     }
226: 
227:     public function getEntityCollection()
228:     {
229:         return Mage::getResourceModel('tag/product_collection');
230:     }
231: 
232:     public function getCustomerCollection()
233:     {
234:         return Mage::getResourceModel('tag/customer_collection');
235:     }
236: 
237:     public function getTaggedProductsUrl()
238:     {
239:         return Mage::getUrl('tag/product/list', array('tagId' => $this->getTagId()));
240:     }
241: 
242:     public function getViewTagUrl()
243:     {
244:         return Mage::getUrl('tag/customer/view', array('tagId' => $this->getTagId()));
245:     }
246: 
247:     public function getEditTagUrl()
248:     {
249:         return Mage::getUrl('tag/customer/edit', array('tagId' => $this->getTagId()));
250:     }
251: 
252:     public function getRemoveTagUrl()
253:     {
254:         return Mage::getUrl('tag/customer/remove', array('tagId' => $this->getTagId()));
255:     }
256: 
257:     public function getPopularCollection()
258:     {
259:         return Mage::getResourceModel('tag/popular_collection');
260:     }
261: 
262:     /**
263:      * Retrieves array of related product IDs
264:      *
265:      * @return array
266:      */
267:     public function getRelatedProductIds()
268:     {
269:         return Mage::getModel('tag/tag_relation')
270:             ->setTagId($this->getTagId())
271:             ->setStoreId($this->getStoreId())
272:             ->setStatusFilter($this->getStatusFilter())
273:             ->setCustomerId(null)
274:             ->getProductIds();
275:     }
276: 
277:     /**
278:      * Checks is available current tag in specified store
279:      *
280:      * @param int $storeId
281:      * @return bool
282:      */
283:     public function isAvailableInStore($storeId = null)
284:     {
285:         $storeId = (is_null($storeId)) ? Mage::app()->getStore()->getId() : $storeId;
286:         return in_array($storeId, $this->getVisibleInStoreIds());
287:     }
288: 
289:     protected function _beforeDelete()
290:     {
291:         $this->_protectFromNonAdmin();
292:         return parent::_beforeDelete();
293:     }
294: 
295:     /**
296:      * Save tag relation with product, customer and store
297:      *
298:      * @param int $productId
299:      * @param int $customerId
300:      * @param int $storeId
301:      * @return string - relation add status
302:      */
303:     public function saveRelation($productId, $customerId, $storeId)
304:     {
305:         /** @var $relationModel Mage_Tag_Model_Tag_Relation */
306:         $relationModel = Mage::getModel('tag/tag_relation');
307:         $relationModel->setTagId($this->getId())
308:             ->setStoreId($storeId)
309:             ->setProductId($productId)
310:             ->setCustomerId($customerId)
311:             ->setActive(Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE)
312:             ->setCreatedAt($relationModel->getResource()->formatDate(time()));
313: 
314:         $relationModelSaveNeed = false;
315:         switch($this->getStatus()) {
316:             case $this->getApprovedStatus():
317:                 if($this->_checkLinkBetweenTagProduct($relationModel)) {
318:                     $relation = $this->_getLinkBetweenTagCustomerProduct($relationModel);
319:                     if ($relation->getId()) {
320:                         if (!$relation->getActive()) {
321:                             // activate relation if it was inactive
322:                             $relationModel->setId($relation->getId());
323:                             $relationModelSaveNeed = true;
324:                         }
325:                     } else {
326:                         $relationModelSaveNeed = true;
327:                     }
328:                     $result = self::ADD_STATUS_EXIST;
329:                 } else {
330:                     $relationModelSaveNeed = true;
331:                     $result = self::ADD_STATUS_SUCCESS;
332:                 }
333:                 break;
334:             case $this->getPendingStatus():
335:                 $relation = $this->_getLinkBetweenTagCustomerProduct($relationModel);
336:                 if ($relation->getId()) {
337:                     if (!$relation->getActive()) {
338:                         $relationModel->setId($relation->getId());
339:                         $relationModelSaveNeed = true;
340:                     }
341:                 } else {
342:                     $relationModelSaveNeed = true;
343:                 }
344:                 $result = self::ADD_STATUS_NEW;
345:                 break;
346:             case $this->getDisabledStatus():
347:                 if($this->_checkLinkBetweenTagCustomerProduct($relationModel)) {
348:                     $result = self::ADD_STATUS_REJECTED;
349:                 } else {
350:                     $this->setStatus($this->getPendingStatus())->save();
351:                     $relationModelSaveNeed = true;
352:                     $result = self::ADD_STATUS_NEW;
353:                 }
354:                 break;
355:         }
356:         if ($relationModelSaveNeed) {
357:             $relationModel->save();
358:         }
359: 
360:         return $result;
361:     }
362: 
363:     /**
364:      * Check whether product is already marked in store with tag
365:      *
366:      * @param Mage_Tag_Model_Tag_Relation $relationModel
367:      * @return boolean
368:      */
369:     protected function _checkLinkBetweenTagProduct($relationModel)
370:     {
371:         $customerId = $relationModel->getCustomerId();
372:         $relationModel->setCustomerId(null);
373:         $result = in_array($relationModel->getProductId(), $relationModel->getProductIds());
374:         $relationModel->setCustomerId($customerId);
375:         return $result;
376:     }
377: 
378:     /**
379:      * Check whether product is already marked in store with tag by customer
380:      *
381:      * @param Mage_Tag_Model_Tag_Relation $relationModel
382:      * @return bool
383:      */
384:     protected function _checkLinkBetweenTagCustomerProduct($relationModel)
385:     {
386:         return (count($this->_getLinkBetweenTagCustomerProduct($relationModel)->getProductIds()) > 0);
387:     }
388: 
389:     /**
390:      * Get relation model for product marked in store with tag by customer
391:      *
392:      * @param Mage_Tag_Model_Tag_Relation $relationModel
393:      * @return Mage_Tag_Model_Tag_Relation
394:      */
395:     protected function _getLinkBetweenTagCustomerProduct($relationModel)
396:     {
397:         return Mage::getModel('tag/tag_relation')->loadByTagCustomer(
398:             $relationModel->getProductId(),
399:             $this->getId(),
400:             $relationModel->getCustomerId(),
401:             $relationModel->getStoreId()
402:         );
403:     }
404: 
405: }
406: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0