00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Tag 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Tag model 00029 * 00030 * @category Mage 00031 * @package Mage_Tag 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 00035 class Mage_Tag_Model_Tag extends Mage_Core_Model_Abstract 00036 { 00037 const STATUS_DISABLED = -1; 00038 const STATUS_PENDING = 0; 00039 const STATUS_APPROVED = 1; 00040 00041 protected function _construct() 00042 { 00043 $this->_init('tag/tag'); 00044 } 00045 00046 public function getPopularity() 00047 { 00048 return $this->_getData('popularity'); 00049 } 00050 00051 public function getName() 00052 { 00053 return $this->_getData('name'); 00054 } 00055 00056 public function getTagId() 00057 { 00058 return $this->_getData('tag_id'); 00059 } 00060 00061 public function getRatio() 00062 { 00063 return $this->_getData('ratio'); 00064 } 00065 00066 public function setRatio($ratio) 00067 { 00068 $this->setData('ratio', $ratio); 00069 return $this; 00070 } 00071 00072 public function loadByName($name) 00073 { 00074 $this->_getResource()->loadByName($this, $name); 00075 return $this; 00076 } 00077 00078 public function aggregate() 00079 { 00080 $this->_getResource()->aggregate($this); 00081 return $this; 00082 } 00083 00084 public function productEventAggregate($observer) 00085 { 00086 $product = $observer->getEvent()->getProduct(); 00087 $collection = $this->getResourceCollection() 00088 ->joinRel() 00089 ->addProductFilter($product->getId()) 00090 ->addTagGroup() 00091 ->load(); 00092 00093 00094 $collection->walk('aggregate'); 00095 00096 00097 return $this; 00098 } 00099 00100 public function addSummary($storeId) 00101 { 00102 $this->setStoreId($storeId); 00103 $this->_getResource()->addSummary($this); 00104 return $this; 00105 } 00106 00107 public function getApprovedStatus() 00108 { 00109 return self::STATUS_APPROVED; 00110 } 00111 00112 public function getPendingStatus() 00113 { 00114 return self::STATUS_PENDING; 00115 } 00116 00117 public function getEntityCollection() 00118 { 00119 return Mage::getResourceModel('tag/product_collection'); 00120 } 00121 00122 public function getCustomerCollection() 00123 { 00124 return Mage::getResourceModel('tag/customer_collection'); 00125 } 00126 00127 public function getTaggedProductsUrl() 00128 { 00129 return Mage::getUrl('tag/product/list', array('tagId' => $this->getTagId())); 00130 } 00131 00132 public function getViewTagUrl() 00133 { 00134 return Mage::getUrl('tag/customer/view', array('tagId' => $this->getTagId())); 00135 } 00136 00137 public function getEditTagUrl() 00138 { 00139 return Mage::getUrl('tag/customer/edit', array('tagId' => $this->getTagId())); 00140 } 00141 00142 public function getRemoveTagUrl() 00143 { 00144 return Mage::getUrl('tag/customer/remove', array('tagId' => $this->getTagId())); 00145 } 00146 00147 public function getPopularCollection() 00148 { 00149 return Mage::getResourceModel('tag/popular_collection'); 00150 } 00151 00152 protected function _beforeDelete() 00153 { 00154 $this->_protectFromNonAdmin(); 00155 return parent::_beforeDelete(); 00156 } 00157 }