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 Element 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_Element_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: /**
38: * Initialize collection model
39: */
40: protected function _construct()
41: {
42: $this->_init('eav/form_element');
43: }
44:
45: /**
46: * Add Form Type filter to collection
47: *
48: * @param Mage_Eav_Model_Form_Type|int $type
49: * @return Mage_Eav_Model_Resource_Form_Element_Collection
50: */
51: public function addTypeFilter($type)
52: {
53: if ($type instanceof Mage_Eav_Model_Form_Type) {
54: $type = $type->getId();
55: }
56:
57: return $this->addFieldToFilter('type_id', $type);
58: }
59:
60: /**
61: * Add Form Fieldset filter to collection
62: *
63: * @param Mage_Eav_Model_Form_Fieldset|int $fieldset
64: * @return Mage_Eav_Model_Resource_Form_Element_Collection
65: */
66: public function addFieldsetFilter($fieldset)
67: {
68: if ($fieldset instanceof Mage_Eav_Model_Form_Fieldset) {
69: $fieldset = $fieldset->getId();
70: }
71:
72: return $this->addFieldToFilter('fieldset_id', $fieldset);
73: }
74:
75: /**
76: * Add Attribute filter to collection
77: *
78: * @param Mage_Eav_Model_Entity_Attribute_Abstract|int $attribute
79: *
80: * @return Mage_Eav_Model_Resource_Form_Element_Collection
81: */
82: public function addAttributeFilter($attribute)
83: {
84: if ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) {
85: $attribute = $attribute->getId();
86: }
87:
88: return $this->addFieldToFilter('attribute_id', $attribute);
89: }
90:
91: /**
92: * Set order by element sort order
93: *
94: * @return Mage_Eav_Model_Resource_Form_Element_Collection
95: */
96: public function setSortOrder()
97: {
98: $this->setOrder('sort_order', self::SORT_ORDER_ASC);
99:
100: return $this;
101: }
102:
103: /**
104: * Join attribute data
105: *
106: * @return Mage_Eav_Model_Resource_Form_Element_Collection
107: */
108: protected function _joinAttributeData()
109: {
110: $this->getSelect()->join(
111: array('eav_attribute' => $this->getTable('eav/attribute')),
112: 'main_table.attribute_id = eav_attribute.attribute_id',
113: array('attribute_code', 'entity_type_id')
114: );
115:
116: return $this;
117: }
118:
119: /**
120: * Load data (join attribute data)
121: *
122: * @param boolean $printQuery
123: * @param boolean $logQuery
124: * @return Mage_Eav_Model_Resource_Form_Element_Collection
125: */
126: public function load($printQuery = false, $logQuery = false)
127: {
128: if (!$this->isLoaded()) {
129: $this->_joinAttributeData();
130: }
131: return parent::load($printQuery, $logQuery);
132: }
133: }
134: