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 class Mage_Eav_Model_Mysql4_Entity_Attribute_Option_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00035 {
00036 protected $_optionValueTable;
00037
00038 public function _construct()
00039 {
00040 $this->_init('eav/entity_attribute_option');
00041 $this->_optionValueTable = Mage::getSingleton('core/resource')->getTableName('eav/attribute_option_value');
00042 }
00043
00044 public function setAttributeFilter($setId)
00045 {
00046 $this->getSelect()->where('main_table.attribute_id=?', $setId);
00047 return $this;
00048 }
00049
00050 public function setStoreFilter($storeId=null, $useDefaultValue=true)
00051 {
00052 if (is_null($storeId)) {
00053 $storeId = Mage::app()->getStore()->getId();
00054 }
00055 $sortBy = 'store_default_value';
00056 if ($useDefaultValue) {
00057 $this->getSelect()
00058 ->join(array('store_default_value'=>$this->_optionValueTable),
00059 'store_default_value.option_id=main_table.option_id',
00060 array('default_value'=>'value'))
00061 ->joinLeft(array('store_value'=>$this->_optionValueTable),
00062 'store_value.option_id=main_table.option_id AND '.$this->getConnection()->quoteInto('store_value.store_id=?', $storeId),
00063 array('store_value'=>'value',
00064 'value' => new Zend_Db_Expr('IFNULL(store_value.value,store_default_value.value)')))
00065 ->where($this->getConnection()->quoteInto('store_default_value.store_id=?', 0));
00066 }
00067 else {
00068 $sortBy = 'store_value';
00069 $this->getSelect()
00070 ->joinLeft(array('store_value'=>$this->_optionValueTable),
00071 'store_value.option_id=main_table.option_id AND '.$this->getConnection()->quoteInto('store_value.store_id=?', $storeId),
00072 'value')
00073 ->where($this->getConnection()->quoteInto('store_value.store_id=?', $storeId));
00074 }
00075 $this->setOrder("{$sortBy}.value", 'ASC');
00076
00077 return $this;
00078 }
00079
00080 public function setIdFilter($id)
00081 {
00082 if (is_array($id)) {
00083 $this->getSelect()->where('main_table.option_id IN (?)', $id);
00084 }
00085 else {
00086 $this->getSelect()->where('main_table.option_id=?', $id);
00087 }
00088 return $this;
00089 }
00090
00091 public function toOptionArray($valueKey = 'value')
00092 {
00093 return $this->_toOptionArray('option_id', $valueKey);
00094 }
00095
00096 public function setPositionOrder($dir = 'ASC', $sortAlpha = false)
00097 {
00098 $this->setOrder('main_table.sort_order', $dir);
00099
00100 if ($sortAlpha) {
00101 $this->getSelect()->joinLeft(array('sort_alpha_value' => $this->_optionValueTable),
00102 'sort_alpha_value.option_id=main_table.option_id AND sort_alpha_value.store_id=0', 'value'
00103 );
00104 $this->setOrder('sort_alpha_value.value', $dir);
00105 }
00106 return $this;
00107 }
00108 }