1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Eav
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Eav Form Fieldset Resource Collection
30: *
31: * @category Mage
32: * @package Mage_Eav
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Eav_Model_Resource_Form_Fieldset_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: /**
38: * Store scope ID
39: *
40: * @var int
41: */
42: protected $_storeId;
43:
44: /**
45: * Initialize collection model
46: *
47: */
48: protected function _construct()
49: {
50: $this->_init('eav/form_fieldset');
51: }
52:
53: /**
54: * Add Form Type filter to collection
55: *
56: * @param Mage_Eav_Model_Form_Type|int $type
57: * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection
58: */
59: public function addTypeFilter($type)
60: {
61: if ($type instanceof Mage_Eav_Model_Form_Type) {
62: $type = $type->getId();
63: }
64:
65: return $this->addFieldToFilter('type_id', $type);
66: }
67:
68: /**
69: * Set order by fieldset sort order
70: *
71: * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection
72: */
73: public function setSortOrder()
74: {
75: $this->setOrder('sort_order', self::SORT_ORDER_ASC);
76: return $this;
77: }
78:
79: /**
80: * Retrieve label store scope
81: *
82: * @return int
83: */
84: public function getStoreId()
85: {
86: if (is_null($this->_storeId)) {
87: return Mage::app()->getStore()->getId();
88: }
89: return $this->_storeId;
90: }
91:
92: /**
93: * Set store scope ID
94: *
95: * @param int $storeId
96: * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection
97: */
98: public function setStoreId($storeId)
99: {
100: $this->_storeId = $storeId;
101: return $this;
102: }
103:
104: /**
105: * Initialize select object
106: *
107: * @return Mage_Eav_Model_Resource_Form_Fieldset_Collection
108: */
109: protected function _initSelect()
110: {
111: parent::_initSelect();
112: $select = $this->getSelect();
113: $select->join(
114: array('default_label' => $this->getTable('eav/form_fieldset_label')),
115: 'main_table.fieldset_id = default_label.fieldset_id AND default_label.store_id = 0',
116: array());
117: if ($this->getStoreId() == 0) {
118: $select->columns('label', 'default_label');
119: } else {
120: $labelExpr = $select->getAdapter()
121: ->getIfNullSql('store_label.label', 'default_label.label');
122: $joinCondition = $this->getConnection()
123: ->quoteInto(
124: 'main_table.fieldset_id = store_label.fieldset_id AND store_label.store_id = ?',
125: (int)$this->getStoreId());
126: $select->joinLeft(
127: array('store_label' => $this->getTable('eav/form_fieldset_label')),
128: $joinCondition,
129: array('label' => $labelExpr)
130: );
131: }
132:
133: return $this;
134: }
135: }
136: