Mage_Eav_Model_Entity_Attribute_Abstract Class Reference

Inheritance diagram for Mage_Eav_Model_Entity_Attribute_Abstract:

Mage_Core_Model_Abstract Mage_Eav_Model_Entity_Attribute_Interface Varien_Object Mage_Eav_Model_Entity_Attribute Mage_Catalog_Model_Entity_Attribute Mage_Catalog_Model_Resource_Eav_Attribute

List of all members.

Public Member Functions

 loadByCode ($entityType, $code)
 getConfig ()
 getName ()
 setAttributeId ($data)
 getAttributeId ()
 setAttributeCode ($data)
 getAttributeCode ()
 setAttributeModel ($data)
 getAttributeModel ()
 setBackendType ($data)
 getBackendType ()
 setBackendModel ($data)
 getBackendModel ()
 setBackendTable ($data)
 getIsVisibleOnFront ()
 getDefaultValue ()
 getAttributeSetId ()
 setAttributeSetId ($id)
 getEntityTypeId ()
 setEntityTypeId ($id)
 setEntityType ($type)
 getIsGlobal ()
 getAlias ($entity=null)
 setName ($name)
 getEntityType ()
 setEntity ($entity)
 getEntity ()
 getEntityIdField ()
 getBackend ()
 getFrontend ()
 getSource ()
 usesSource ()
 isValueEmpty ($value)
 isInSet ($setId)
 isInGroup ($setId, $groupId)
 getIdByCode ($entityType, $code)
 isStatic ()
 getBackendTable ()
 getFlatColumns ()
 getFlatIndexes ()
 getFlatUpdateSelect ($store=null)

Public Attributes

const TYPE_STATIC = 'static'

Protected Member Functions

 _construct ()
 _getDefaultBackendModel ()
 _getDefaultFrontendModel ()
 _getDefaultSourceModel ()

Protected Attributes

 $_name
 $_entity
 $_backend
 $_frontend
 $_source
 $_attributeIdCache = array()
 $_dataTable = null


Detailed Description

Definition at line 35 of file Abstract.php.


Member Function Documentation

_construct (  )  [protected]

Initialize resource model

Reimplemented from Varien_Object.

Definition at line 92 of file Abstract.php.

00093     {
00094         $this->_init('eav/entity_attribute');
00095     }

_getDefaultBackendModel (  )  [protected]

Reimplemented in Mage_Eav_Model_Entity_Attribute.

Definition at line 378 of file Abstract.php.

00379     {
00380         return Mage_Eav_Model_Entity::DEFAULT_BACKEND_MODEL;
00381     }

_getDefaultFrontendModel (  )  [protected]

Reimplemented in Mage_Eav_Model_Entity_Attribute.

Definition at line 383 of file Abstract.php.

00384     {
00385         return Mage_Eav_Model_Entity::DEFAULT_FRONTEND_MODEL;
00386     }

_getDefaultSourceModel (  )  [protected]

Reimplemented in Mage_Catalog_Model_Resource_Eav_Attribute, and Mage_Eav_Model_Entity_Attribute.

Definition at line 388 of file Abstract.php.

00389     {
00390         return $this->getEntity()->getDefaultAttributeSourceModel();
00391     }

getAlias ( entity = null  ) 

Get attribute alias as "entity_type/attribute_code"

Parameters:
Mage_Eav_Model_Entity_Abstract $entity exclude this entity
Returns:
string

Definition at line 260 of file Abstract.php.

00261     {
00262         $alias = '';
00263         if (is_null($entity) || ($entity->getType() !== $this->getEntity()->getType())) {
00264             $alias .= $this->getEntity()->getType() . '/';
00265         }
00266         $alias .= $this->getAttributeCode();
00267         return  $alias;
00268     }

getAttributeCode (  ) 

Definition at line 171 of file Abstract.php.

00172     {
00173         return $this->_getData('attribute_code');
00174     }

getAttributeId (  ) 

Get attribute identifuer

Returns:
int | null

Definition at line 161 of file Abstract.php.

00162     {
00163         return $this->_getData('attribute_id');
00164     }

getAttributeModel (  ) 

Definition at line 181 of file Abstract.php.

00182     {
00183         return $this->_getData('attribute_model');
00184     }

getAttributeSetId (  ) 

Definition at line 221 of file Abstract.php.

00222     {
00223         return $this->_getData('attribute_set_id');
00224     }

getBackend (  ) 

Retrieve backend instance

Returns:
Mage_Eav_Model_Entity_Attribute_Backend_Abstract

Definition at line 324 of file Abstract.php.

00325     {
00326         if (empty($this->_backend)) {
00327             if (!$this->getBackendModel()) {
00328                 $this->setBackendModel($this->_getDefaultBackendModel());
00329             }
00330             $backend = Mage::getModel($this->getBackendModel());
00331             if (!$backend) {
00332                 throw Mage::exception('Mage_Eav', 'Invalid backend model specified: '.$this->getBackendModel());
00333             }
00334             $this->_backend = $backend->setAttribute($this);
00335         }
00336         return $this->_backend;
00337     }

getBackendModel (  ) 

Definition at line 201 of file Abstract.php.

00202     {
00203         return $this->_getData('backend_model');
00204     }

getBackendTable (  ) 

Get attribute backend table name

Returns:
string

Definition at line 475 of file Abstract.php.

00476     {
00477         if ($this->_dataTable === null) {
00478             if ($this->isStatic()) {
00479                 $this->_dataTable = $this->getEntityType()->getValueTablePrefix();
00480             } elseif ($this->_getData('backend_table')) {
00481                 $this->_dataTable = $this->_getData('backend_table');
00482             } else {
00483                 $this->_dataTable = $this->getEntity()->getValueTablePrefix().'_'.$this->getBackendType();
00484             }
00485         }
00486         return $this->_dataTable;
00487     }

getBackendType (  ) 

Definition at line 191 of file Abstract.php.

00192     {
00193         return $this->_getData('backend_type');
00194     }

getConfig (  ) 

Retrieve attribute configuration (deprecated)

Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 129 of file Abstract.php.

00130     {
00131         return $this;
00132     }

getDefaultValue (  ) 

Definition at line 216 of file Abstract.php.

00217     {
00218         return $this->_getData('default_value');
00219     }

getEntity (  ) 

Retrieve entity instance

Returns:
Mage_Eav_Model_Entity_Abstract

Definition at line 306 of file Abstract.php.

00307     {
00308         if (!$this->_entity) {
00309             $this->_entity = $this->getEntityType();
00310         }
00311         return $this->_entity;
00312     }

getEntityIdField (  ) 

Definition at line 314 of file Abstract.php.

00315     {
00316         return $this->getEntity()->getValueEntityIdField();
00317     }

getEntityType (  ) 

Definition at line 281 of file Abstract.php.

00282     {
00283         /*if ($this->hasData('entity_type')) {
00284             return $this->_getData('entity_type');
00285         }*/
00286         return Mage::getSingleton('eav/config')->getEntityType($this->getEntityTypeId());
00287     }

getEntityTypeId (  ) 

Definition at line 232 of file Abstract.php.

00233     {
00234         return $this->_getData('entity_type_id');
00235     }

getFlatColumns (  ) 

Retrieve Flat Column(s)

Returns:
array

Definition at line 494 of file Abstract.php.

00494                                      {
00495         if ($this->usesSource() && $this->getBackendType() != 'static') {
00496             return $this->getSource()->getFlatColums();
00497         }
00498 
00499         $columns = array();
00500         switch ($this->getBackendType()) {
00501             case 'static':
00502                 $describe = $this->_getResource()
00503                     ->describeTable($this->getBackend()->getTable());
00504                 if (!isset($describe[$this->getAttributeCode()])) {
00505                     break;
00506                 }
00507                 $prop = $describe[$this->getAttributeCode()];
00508                 $columns[$this->getAttributeCode()] = array(
00509                     'type'      => $prop['DATA_TYPE'] . ($prop['LENGTH'] ? "({$prop['LENGTH']})" : ""),
00510                     'unsigned'  => $prop['UNSIGNED'] ? true: false,
00511                     'is_null'   => $prop['NULLABLE'],
00512                     'default'   => $prop['DEFAULT'],
00513                     'extra'     => null
00514                 );
00515                 break;
00516             case 'datetime':
00517                 $columns[$this->getAttributeCode()] = array(
00518                     'type'      => 'datetime',
00519                     'unsigned'  => false,
00520                     'is_null'   => true,
00521                     'default'   => null,
00522                     'extra'     => null
00523                 );
00524                 break;
00525             case 'decimal':
00526                 $columns[$this->getAttributeCode()] = array(
00527                     'type'      => 'decimal(12,4)',
00528                     'unsigned'  => false,
00529                     'is_null'   => true,
00530                     'default'   => null,
00531                     'extra'     => null
00532                 );
00533                 break;
00534             case 'int':
00535                 $columns[$this->getAttributeCode()] = array(
00536                     'type'      => 'int',
00537                     'unsigned'  => false,
00538                     'is_null'   => true,
00539                     'default'   => null,
00540                     'extra'     => null
00541                 );
00542                 break;
00543             case 'text':
00544                 $columns[$this->getAttributeCode()] = array(
00545                     'type'      => 'text',
00546                     'unsigned'  => false,
00547                     'is_null'   => true,
00548                     'default'   => null,
00549                     'extra'     => null
00550                 );
00551                 break;
00552             case 'varchar':
00553                 $columns[$this->getAttributeCode()] = array(
00554                     'type'      => 'varchar(255)',
00555                     'unsigned'  => false,
00556                     'is_null'   => true,
00557                     'default'   => null,
00558                     'extra'     => null
00559                 );
00560                 break;
00561         }
00562         return $columns;
00563     }

getFlatIndexes (  ) 

Retrieve index data for Flat table

Returns:
array

Definition at line 570 of file Abstract.php.

00571     {
00572         $condition = $this->getUsedForSortBy();
00573         if ($this->getFlatAddFilterableAttributes()) {
00574             $condition = $condition || $this->getIsFilterable();
00575         }
00576 
00577         if ($condition) {
00578             if ($this->usesSource() && $this->getBackendType() != 'static') {
00579                 return $this->getSource()->getFlatIndexes();
00580             }
00581             $indexes = array();
00582 
00583             switch ($this->getBackendType()) {
00584                 case 'static':
00585                     $describe = $this->_getResource()
00586                         ->describeTable($this->getBackend()->getTable());
00587                     if (!isset($describe[$this->getAttributeCode()])) {
00588                         break;
00589                     }
00590                     $indexDataTypes = array(
00591                         'varchar',
00592                         'varbinary',
00593                         'char',
00594                         'date',
00595                         'datetime',
00596                         'timestamp',
00597                         'time',
00598                         'year',
00599                         'enum',
00600                         'set',
00601                         'bit',
00602                         'bool',
00603                         'tinyint',
00604                         'smallint',
00605                         'mediumint',
00606                         'int',
00607                         'bigint',
00608                         'float',
00609                         'double',
00610                         'decimal',
00611                     );
00612                     $prop = $describe[$this->getAttributeCode()];
00613                     if (in_array($prop['DATA_TYPE'], $indexDataTypes)) {
00614                         $indexName = 'IDX_' . strtoupper($this->getAttributeCode());
00615                         $indexes[$indexName] = array(
00616                             'type'      => 'index',
00617                             'fields'    => array($this->getAttributeCode())
00618                         );
00619                     }
00620 
00621                     break;
00622                 case 'datetime':
00623                 case 'decimal':
00624                 case 'int':
00625                 case 'varchar':
00626                     $indexName = 'IDX_' . strtoupper($this->getAttributeCode());
00627                     $indexes[$indexName] = array(
00628                         'type'      => 'index',
00629                         'fields'    => array($this->getAttributeCode())
00630                     );
00631                     break;
00632             }
00633 
00634             return $indexes;
00635         }
00636         return array();
00637     }

getFlatUpdateSelect ( store = null  ) 

Retrieve Select For Flat Attribute update

Parameters:
int $store
Returns:
Varien_Db_Select

Definition at line 645 of file Abstract.php.

00645                                                        {
00646         if (is_null($store)) {
00647             foreach (Mage::app()->getStores() as $store) {
00648                 $this->getFlatUpdateSelect($store->getId());
00649             }
00650             return $this;
00651         }
00652 
00653         if ($this->getBackendType() == 'static') {
00654             return null;
00655         }
00656 
00657         if ($this->usesSource()) {
00658             return $this->getSource()->getFlatUpdateSelect($store);
00659         }
00660         return $this->_getResource()->getFlatUpdateSelect($this, $store);
00661     }

getFrontend (  ) 

Retrieve frontend instance

Returns:
Mage_Eav_Model_Entity_Attribute_Frontend_Abstract

Definition at line 344 of file Abstract.php.

00345     {
00346         if (empty($this->_frontend)) {
00347             if (!$this->getFrontendModel()) {
00348                 $this->setFrontendModel($this->_getDefaultFrontendModel());
00349             }
00350             $this->_frontend = Mage::getModel($this->getFrontendModel())
00351                 ->setAttribute($this);
00352         }
00353         return $this->_frontend;
00354     }

getIdByCode ( entityType,
code 
)

Return attribute id

Parameters:
string $entityType
string $code
Returns:
int

Definition at line 451 of file Abstract.php.

00452     {
00453         $k = "{$entityType}|{$code}";
00454         if (!isset($this->_attributeIdCache[$k])) {
00455             $this->_attributeIdCache[$k] = $this->getResource()->getIdByCode($entityType, $code);
00456         }
00457         return $this->_attributeIdCache[$k];
00458     }

getIsGlobal (  ) 

Definition at line 249 of file Abstract.php.

00250     {
00251         return $this->_getData('is_global');
00252     }

getIsVisibleOnFront (  ) 

Definition at line 211 of file Abstract.php.

00212     {
00213         return $this->_getData('is_visible_on_front');
00214     }

getName (  ) 

Get attribute name

Returns:
string

Definition at line 139 of file Abstract.php.

00140     {
00141         return $this->_getData('attribute_code');
00142     }

getSource (  ) 

Retrieve source instance

Returns:
Mage_Eav_Model_Entity_Attribute_Source_Abstract

Definition at line 361 of file Abstract.php.

00362     {
00363         if (empty($this->_source)) {
00364             if (!$this->getSourceModel()) {
00365                 $this->setSourceModel($this->_getDefaultSourceModel());
00366             }
00367             $this->_source = Mage::getModel($this->getSourceModel())
00368                 ->setAttribute($this);
00369         }
00370         return $this->_source;
00371     }

isInGroup ( setId,
groupId 
)

Check if attribute in specified group

Parameters:
int $setId
int $groupId
Returns:
boolean

Definition at line 435 of file Abstract.php.

00436     {
00437         if ($this->isInSet($setId) && $this->getData('attribute_set_info/' . $setId . '/group_id') == $groupId) {
00438             return true;
00439         }
00440 
00441         return false;
00442     }

isInSet ( setId  ) 

Check if attribute in specified set

Parameters:
int|array $setId
Returns:
boolean

Definition at line 409 of file Abstract.php.

00410     {
00411         if (!$this->hasAttributeSetInfo()) {
00412             return true;
00413         }
00414 
00415         if (is_array($setId)
00416             && count(array_intersect($setId, array_keys($this->getAttributeSetInfo())))) {
00417             return true;
00418         }
00419 
00420         if (!is_array($setId)
00421             && array_key_exists($setId, $this->getAttributeSetInfo())) {
00422             return true;
00423         }
00424 
00425         return false;
00426     }

isStatic (  ) 

Check if attribute is static

Returns:
bool

Definition at line 465 of file Abstract.php.

00466     {
00467         return $this->getBackendType() == self::TYPE_STATIC || $this->getBackendType() == '';
00468     }

isValueEmpty ( value  ) 

Definition at line 393 of file Abstract.php.

00394     {
00395         $attrType = $this->getBackend()->getType();
00396         $isEmpty = is_array($value)
00397             || is_null($value)
00398             || $value===false && $attrType!='int'
00399             || $value==='' && ($attrType=='int' || $attrType=='decimal' || $attrType=='datetime');
00400         return $isEmpty;
00401     }

loadByCode ( entityType,
code 
)

Load attribute data by code

Parameters:
mixed $entityType
string $code
Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 104 of file Abstract.php.

00105     {
00106         Varien_Profiler::start('_LOAD_ATTRIBUTE_BY_CODE__');
00107         if (is_numeric($entityType)) {
00108             $entityTypeId = $entityType;
00109         } elseif (is_string($entityType)) {
00110             $entityType = Mage::getModel('eav/entity_type')->loadByCode($entityType);
00111         }
00112         if ($entityType instanceof Mage_Eav_Model_Entity_Type) {
00113             $entityTypeId = $entityType->getId();
00114         }
00115         if (empty($entityTypeId)) {
00116             throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid entity supplied'));
00117         }
00118         $this->_getResource()->loadByCode($this, $entityTypeId, $code);
00119         $this->_afterLoad();
00120         Varien_Profiler::stop('_LOAD_ATTRIBUTE_BY_CODE__');
00121         return $this;
00122     }

setAttributeCode ( data  ) 

Definition at line 166 of file Abstract.php.

00167     {
00168         return $this->setData('attribute_code', $data);
00169     }

setAttributeId ( data  ) 

Specify attribute identifier

Parameters:
int $data
Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 150 of file Abstract.php.

00151     {
00152         $this->_data['attribute_id'] = $data;
00153         return $this;
00154     }

setAttributeModel ( data  ) 

Definition at line 176 of file Abstract.php.

00177     {
00178         return $this->setData('attribute_model', $data);
00179     }

setAttributeSetId ( id  ) 

Definition at line 226 of file Abstract.php.

00227     {
00228         $this->_data['attribute_set_id'] = $id;
00229         return $this;
00230     }

setBackendModel ( data  ) 

Definition at line 196 of file Abstract.php.

00197     {
00198         return $this->setData('backend_model', $data);
00199     }

setBackendTable ( data  ) 

Definition at line 206 of file Abstract.php.

00207     {
00208         return $this->setData('backend_table', $data);
00209     }

setBackendType ( data  ) 

Definition at line 186 of file Abstract.php.

00187     {
00188         return $this->setData('backend_type', $data);
00189     }

setEntity ( entity  ) 

Set attribute entity instance

Parameters:
Mage_Eav_Model_Entity_Abstract $entity
Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 295 of file Abstract.php.

00296     {
00297         $this->_entity = $entity;
00298         return $this;
00299     }

setEntityType ( type  ) 

Definition at line 243 of file Abstract.php.

00244     {
00245         $this->setData('entity_type', $type);
00246         return $this;
00247     }

setEntityTypeId ( id  ) 

Definition at line 237 of file Abstract.php.

00238     {
00239         $this->_data['entity_type_id'] = $id;
00240         return $this;
00241     }

setName ( name  ) 

Set attribute name

Parameters:
string $name
Returns:
Mage_Eav_Model_Entity_Attribute_Abstract

Definition at line 276 of file Abstract.php.

00277     {
00278         return $this->setData('attribute_code', $name);
00279     }

usesSource (  ) 

Definition at line 373 of file Abstract.php.

00374     {
00375         return $this->getFrontendInput()==='select' || $this->getFrontendInput()==='multiselect';
00376     }


Member Data Documentation

$_attributeIdCache = array() [protected]

Definition at line 80 of file Abstract.php.

$_backend [protected]

Definition at line 59 of file Abstract.php.

$_dataTable = null [protected]

Definition at line 87 of file Abstract.php.

$_entity [protected]

Definition at line 52 of file Abstract.php.

$_frontend [protected]

Definition at line 66 of file Abstract.php.

$_name [protected]

Definition at line 45 of file Abstract.php.

$_source [protected]

Definition at line 73 of file Abstract.php.

const TYPE_STATIC = 'static'

Definition at line 38 of file Abstract.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:10 2009 for Magento by  doxygen 1.5.8