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 class Mage_Eav_Model_Mysql4_Config extends Mage_Core_Model_Mysql4_Abstract
00029 {
00030 protected static $_entityTypes;
00031 protected static $_attributes = array();
00032
00033 protected function _construct()
00034 {
00035 $this->_init('eav/entity_type', 'entity_type_id');
00036 }
00037
00038
00039
00040
00041
00042
00043 protected function _loadTypes()
00044 {
00045 if (!$this->_getReadAdapter()) {
00046 self::$_entityTypes = array();
00047 return $this;
00048 }
00049 if (is_null(self::$_entityTypes)) {
00050 self::$_entityTypes = array();
00051 $select = $this->_getReadAdapter()->select()->from($this->getMainTable());
00052 $data = $this->_getReadAdapter()->fetchAll($select);
00053 foreach ($data as $row) {
00054 self::$_entityTypes['by_id'][$row['entity_type_id']] = $row;
00055 self::$_entityTypes['by_code'][$row['entity_type_code']] = $row;
00056 }
00057 }
00058
00059 return $this;
00060 }
00061
00062 protected function _loadTypeAttributes($typeId)
00063 {
00064 if (!isset(self::$_attributes[$typeId])) {
00065 $select = $this->_getReadAdapter()->select()->from($this->getTable('eav/attribute'))
00066 ->where('entity_type_id=?', $typeId);
00067 self::$_attributes[$typeId] = $this->_getReadAdapter()->fetchAll($select);
00068 }
00069 return self::$_attributes[$typeId];
00070 }
00071
00072 public function fetchEntityTypeData($entityType)
00073 {
00074 $this->_loadTypes();
00075
00076 if (is_numeric($entityType)) {
00077 $info = isset(self::$_entityTypes['by_id'][$entityType]) ? self::$_entityTypes['by_id'][$entityType] : null;
00078 }
00079 else {
00080 $info = isset(self::$_entityTypes['by_code'][$entityType]) ? self::$_entityTypes['by_code'][$entityType] : null;
00081 }
00082
00083 $data = array();
00084 if ($info) {
00085 $data['entity'] = $info;
00086 $attributes = $this->_loadTypeAttributes($info['entity_type_id']);
00087 $data['attributes'] = array();
00088 foreach ($attributes as $attribute) {
00089 $data['attributes'][$attribute['attribute_id']] = $attribute;
00090 $data['attributes'][$attribute['attribute_code']] = $attribute['attribute_id'];
00091 }
00092 }
00093 return $data;
00094 }
00095 }