Mage_Eav_Model_Entity_Attribute_Source_Table Class Reference

Inheritance diagram for Mage_Eav_Model_Entity_Attribute_Source_Table:

Mage_Eav_Model_Entity_Attribute_Source_Abstract Mage_Eav_Model_Entity_Attribute_Source_Interface Mage_Customer_Model_Customer_Attribute_Source_Group Mage_Customer_Model_Customer_Attribute_Source_Store Mage_Customer_Model_Customer_Attribute_Source_Website Mage_Customer_Model_Entity_Address_Attribute_Source_Country Mage_Customer_Model_Entity_Address_Attribute_Source_Region Mage_Eav_Model_Entity_Attribute_Source_Store

List of all members.

Public Member Functions

 getAllOptions ($withEmpty=true, $defaultValues=false)
 getOptionText ($value)
 addValueSortToCollection ($collection, $dir= 'asc')
 getFlatColums ()
 getFlatIndexes ()
 getFlatUpdateSelect ($store)

Protected Attributes

 $_optionsDefault = array()


Detailed Description

Definition at line 28 of file Table.php.


Member Function Documentation

addValueSortToCollection ( collection,
dir = 'asc' 
)

Add Value Sort To Collection Select

Parameters:
Mage_Eav_Model_Entity_Collection_Abstract $collection
string $dir
Returns:
Mage_Eav_Model_Entity_Attribute_Source_Table

Reimplemented from Mage_Eav_Model_Entity_Attribute_Source_Abstract.

Definition at line 112 of file Table.php.

00113     {
00114         $valueTable1    = $this->getAttribute()->getAttributeCode() . '_t1';
00115         $valueTable2    = $this->getAttribute()->getAttributeCode() . '_t2';
00116         $collection->getSelect()
00117             ->joinLeft(
00118                 array($valueTable1 => $this->getAttribute()->getBackend()->getTable()),
00119                 "`e`.`entity_id`=`{$valueTable1}`.`entity_id`"
00120                 . " AND `{$valueTable1}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00121                 . " AND `{$valueTable1}`.`store_id`='0'",
00122                 array())
00123             ->joinLeft(
00124                 array($valueTable2 => $this->getAttribute()->getBackend()->getTable()),
00125                 "`e`.`entity_id`=`{$valueTable2}`.`entity_id`"
00126                 . " AND `{$valueTable2}`.`attribute_id`='{$this->getAttribute()->getId()}'"
00127                 . " AND `{$valueTable2}`.`store_id`='{$collection->getStoreId()}'",
00128                 array()
00129             );
00130         $valueExpr = new Zend_Db_Expr("IFNULL(`{$valueTable2}`.`value`, `{$valueTable1}`.`value`)");
00131 
00132         Mage::getResourceModel('eav/entity_attribute_option')
00133             ->addOptionValueToCollection($collection, $this->getAttribute(), $valueExpr);
00134 
00135         $collection->getSelect()
00136             ->order("{$this->getAttribute()->getAttributeCode()} {$dir}");
00137 
00138         return $this;
00139     }

getAllOptions ( withEmpty = true,
defaultValues = false 
)

Retrieve Full Option values array

Parameters:
bool $withEmpty Add empty option to array
bool $defaultValues
Returns:
array

Definition at line 44 of file Table.php.

00045     {
00046         $storeId = $this->getAttribute()->getStoreId();
00047         if (!is_array($this->_options)) {
00048             $this->_options = array();
00049         }
00050         if (!is_array($this->_optionsDefault)) {
00051             $this->_optionsDefault = array();
00052         }
00053         if (!isset($this->_options[$storeId])) {
00054             $collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
00055                 ->setPositionOrder('asc')
00056                 ->setAttributeFilter($this->getAttribute()->getId())
00057                 ->setStoreFilter($this->getAttribute()->getStoreId())
00058                 ->load();
00059             $this->_options[$storeId]        = $collection->toOptionArray();
00060             $this->_optionsDefault[$storeId] = $collection->toOptionArray('default_value');
00061         }
00062         $options = ($defaultValues ? $this->_optionsDefault[$storeId] : $this->_options[$storeId]);
00063         if ($withEmpty) {
00064             array_unshift($options, array('label'=>'', 'value'=>''));
00065         }
00066         return $options;
00067     }

getFlatColums (  ) 

Retrieve Column(s) for Flat

Returns:
array

Reimplemented from Mage_Eav_Model_Entity_Attribute_Source_Abstract.

Definition at line 146 of file Table.php.

00147     {
00148         $columns = array();
00149         $columns[$this->getAttribute()->getAttributeCode()] = array(
00150             'type'      => 'int',
00151             'unsigned'  => false,
00152             'is_null'   => true,
00153             'default'   => null,
00154             'extra'     => null
00155         );
00156         if ($this->getAttribute()->getFrontend()->getInputType() != 'multiselect') {
00157             $columns[$this->getAttribute()->getAttributeCode() . '_value'] = array(
00158                 'type'      => 'varchar(255)',
00159                 'unsigned'  => false,
00160                 'is_null'   => true,
00161                 'default'   => null,
00162                 'extra'     => null
00163             );
00164         }
00165 
00166         return $columns;
00167     }

getFlatIndexes (  ) 

Retrieve Indexes for Flat

Returns:
array

Reimplemented from Mage_Eav_Model_Entity_Attribute_Source_Abstract.

Definition at line 174 of file Table.php.

00175     {
00176         $indexes = array();
00177 
00178         $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode());
00179         $indexes[$index] = array(
00180             'type'      => 'index',
00181             'fields'    => array($this->getAttribute()->getAttributeCode())
00182         );
00183 
00184         $sortable   = $this->getAttribute()->getUsedForSortBy();
00185         if ($sortable and $this->getAttribute()->getFrontend()->getInputType() != 'multiselect') {
00186             $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode()) . '_VALUE';
00187             $indexes[$index] = array(
00188                 'type'      => 'index',
00189                 'fields'    => array($this->getAttribute()->getAttributeCode() . '_value')
00190             );
00191         }
00192 
00193         return $indexes;
00194     }

getFlatUpdateSelect ( store  ) 

Retrieve Select For Flat Attribute update

Parameters:
Mage_Eav_Model_Entity_Attribute_Abstract $attribute
int $store
Returns:
Varien_Db_Select|null

Reimplemented from Mage_Eav_Model_Entity_Attribute_Source_Abstract.

Definition at line 203 of file Table.php.

00204     {
00205         return Mage::getResourceModel('eav/entity_attribute_option')
00206             ->getFlatUpdateSelect($this->getAttribute(), $store);
00207     }

getOptionText ( value  ) 

Get a text for option value

Parameters:
string|integer $value
Returns:
string

Reimplemented from Mage_Eav_Model_Entity_Attribute_Source_Abstract.

Reimplemented in Mage_Customer_Model_Customer_Attribute_Source_Store, and Mage_Customer_Model_Customer_Attribute_Source_Website.

Definition at line 75 of file Table.php.

00076     {
00077         $isMultiple = false;
00078         if (strpos($value, ',')) {
00079             $isMultiple = true;
00080             $value = explode(',', $value);
00081         }
00082 
00083         $options = $this->getAllOptions(false);
00084 
00085         if ($isMultiple) {
00086             $values = array();
00087             foreach ($options as $item) {
00088                 if (in_array($item['value'], $value)) {
00089                     $values[] = $item['label'];
00090                 }
00091             }
00092             return $values;
00093         }
00094         else {
00095             foreach ($options as $item) {
00096                 if ($item['value'] == $value) {
00097                     return $item['label'];
00098                 }
00099             }
00100             return false;
00101         }
00102     }


Member Data Documentation

$_optionsDefault = array() [protected]

Definition at line 35 of file Table.php.


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

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