00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Eav_Model_Entity_Type extends Mage_Core_Model_Abstract
00036 {
00037
00038
00039
00040
00041
00042
00043 protected $_attributes;
00044
00045
00046
00047
00048
00049
00050 protected $_attributesBySet = array();
00051
00052
00053
00054
00055
00056
00057 protected $_sets;
00058
00059
00060
00061
00062
00063 protected function _construct()
00064 {
00065 $this->_init('eav/entity_type');
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 public function loadByCode($code)
00075 {
00076 $this->_getResource()->loadByCode($this, $code);
00077 $this->_afterLoad();
00078 return $this;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 public function getAttributeCollection($setId = null)
00088 {
00089 if (is_null($setId)) {
00090 if (is_null($this->_attributes)) {
00091 $this->_attributes = $this->_getAttributeCollection()
00092 ->setEntityTypeFilter($this->getId());
00093 }
00094 $collection = $this->_attributes;
00095 }
00096 else {
00097 if (!isset($this->_attributesBySet[$setId])) {
00098 $this->_attributesBySet[$setId] = $this->_getAttributeCollection()
00099 ->setEntityTypeFilter($this->getId())
00100 ->setAttributeSetFilter($setId);
00101 }
00102 $collection = $this->_attributesBySet[$setId];
00103 }
00104 return $collection;
00105 }
00106
00107
00108
00109
00110
00111
00112 protected function _getAttributeCollection()
00113 {
00114 $collection = Mage::getModel('eav/entity_attribute')->getCollection();
00115 if ($objectsModel = $this->getAttributeModel()) {
00116 $collection->setModel($objectsModel);
00117 }
00118 return $collection;
00119 }
00120
00121
00122
00123
00124
00125
00126 public function getAttributeSetCollection()
00127 {
00128 if (empty($this->_sets)) {
00129 $this->_sets = Mage::getModel('eav/entity_attribute_set')->getResourceCollection()
00130 ->setEntityTypeFilter($this->getId());
00131 }
00132 return $this->_sets;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141 public function fetchNewIncrementId($storeId=null)
00142 {
00143 if (!$this->getIncrementModel()) {
00144 return false;
00145 }
00146
00147 if (!$this->getIncrementPerStore()) {
00148 $storeId = 0;
00149 }
00150 elseif (is_null($storeId)) {
00151
00152
00153
00154 $storeId = 0;
00155
00156 }
00157
00158 $entityStoreConfig = Mage::getModel('eav/entity_store')
00159 ->loadByEntityStore($this->getId(), $storeId);
00160
00161 if (!$entityStoreConfig->getId()) {
00162 $entityStoreConfig
00163 ->setEntityTypeId($this->getId())
00164 ->setStoreId($storeId)
00165 ->setIncrementPrefix($storeId)
00166 ->save();
00167 }
00168
00169 $incrementInstance = Mage::getModel($this->getIncrementModel())
00170 ->setPrefix($entityStoreConfig->getIncrementPrefix())
00171 ->setPadLength($this->getIncrementPadLength())
00172 ->setPadChar($this->getIncrementPadChar())
00173 ->setLastId($entityStoreConfig->getIncrementLastId())
00174 ->setEntityTypeId($entityStoreConfig->getEntityTypeId())
00175 ->setStoreId($entityStoreConfig->getStoreId());
00176
00177
00178
00179
00180
00181 $incrementId = $incrementInstance->getNextId();
00182 $entityStoreConfig->setIncrementLastId($incrementId);
00183 $entityStoreConfig->save();
00184
00185 return $incrementId;
00186 }
00187
00188
00189
00190
00191
00192
00193 public function getEntityIdField()
00194 {
00195 return isset($this->_data['entity_id_field']) ? $this->_data['entity_id_field'] : null;
00196 }
00197
00198
00199
00200
00201
00202
00203 public function getEntityTable()
00204 {
00205 return isset($this->_data['entity_table']) ? $this->_data['entity_table'] : null;
00206 }
00207
00208
00209
00210
00211
00212
00213 public function getValueTablePrefix()
00214 {
00215 if (empty($this->_data['value_table_prefix'])) {
00216 $this->_data['value_table_prefix'] = $this->_getResource()->getTable($this->getEntityTable());
00217 }
00218 return $this->_data['value_table_prefix'];
00219 }
00220
00221
00222
00223
00224
00225
00226 public function getDefaultAttributeSetId()
00227 {
00228 return isset($this->_data['default_attribute_set_id']) ? $this->_data['default_attribute_set_id'] : null;
00229 }
00230
00231
00232
00233
00234
00235
00236 public function getEntityTypeId()
00237 {
00238 return isset($this->_data['entity_type_id']) ? $this->_data['entity_type_id'] : null;
00239 }
00240
00241 public function getEntityTypeCode()
00242 {
00243 return isset($this->_data['entity_type_code']) ? $this->_data['entity_type_code'] : null;
00244 }
00245
00246 public function getAttributeCodes()
00247 {
00248 return isset($this->_data['attribute_codes']) ? $this->_data['attribute_codes'] : null;
00249 }
00250
00251
00252
00253
00254
00255
00256 public function getAttributeModel()
00257 {
00258 if (empty($this->_data['attribute_model'])) {
00259 return Mage_Eav_Model_Entity::DEFAULT_ATTRIBUTE_MODEL;
00260 }
00261 else {
00262 return $this->_data['attribute_model'];
00263 }
00264 }
00265
00266 public function getEntity()
00267 {
00268 return Mage::getResourceSingleton($this->_data['entity_model']);
00269 }
00270 }