*/ class Mage_Eav_Model_Resource_Form_Fieldset_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { /** * Store scope ID * * @var int */ protected $_storeId; /** * Initialize collection model * */ protected function _construct() { $this->_init('eav/form_fieldset'); } /** * Add Form Type filter to collection * * @param Mage_Eav_Model_Form_Type|int $type * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection */ public function addTypeFilter($type) { if ($type instanceof Mage_Eav_Model_Form_Type) { $type = $type->getId(); } return $this->addFieldToFilter('type_id', $type); } /** * Set order by fieldset sort order * * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection */ public function setSortOrder() { $this->setOrder('sort_order', self::SORT_ORDER_ASC); return $this; } /** * Retrieve label store scope * * @return int */ public function getStoreId() { if (is_null($this->_storeId)) { return Mage::app()->getStore()->getId(); } return $this->_storeId; } /** * Set store scope ID * * @param int $storeId * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection */ public function setStoreId($storeId) { $this->_storeId = $storeId; return $this; } /** * Initialize select object * * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection */ protected function _initSelect() { parent::_initSelect(); $select = $this->getSelect(); $select->join( array('default_label' => $this->getTable('eav/form_fieldset_label')), 'main_table.fieldset_id = default_label.fieldset_id AND default_label.store_id = 0', array()); if ($this->getStoreId() == 0) { $select->columns('label', 'default_label'); } else { $labelExpr = $select->getAdapter() ->getIfNullSql('store_label.label', 'default_label.label'); $joinCondition = $this->getConnection() ->quoteInto( 'main_table.fieldset_id = store_label.fieldset_id AND store_label.store_id = ?', (int)$this->getStoreId()); $select->joinLeft( array('store_label' => $this->getTable('eav/form_fieldset_label')), $joinCondition, array('label' => $labelExpr) ); } return $this; } }