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 Model
30: *
31: * @method Mage_Eav_Model_Resource_Form_Element _getResource()
32: * @method Mage_Eav_Model_Resource_Form_Element getResource()
33: * @method int getTypeId()
34: * @method Mage_Eav_Model_Form_Element setTypeId(int $value)
35: * @method int getFieldsetId()
36: * @method Mage_Eav_Model_Form_Element setFieldsetId(int $value)
37: * @method int getAttributeId()
38: * @method Mage_Eav_Model_Form_Element setAttributeId(int $value)
39: * @method int getSortOrder()
40: * @method Mage_Eav_Model_Form_Element setSortOrder(int $value)
41: *
42: * @category Mage
43: * @package Mage_Eav
44: * @author Magento Core Team <core@magentocommerce.com>
45: */
46: class Mage_Eav_Model_Form_Element extends Mage_Core_Model_Abstract
47: {
48: /**
49: * Prefix of model events names
50: *
51: * @var string
52: */
53: protected $_eventPrefix = 'eav_form_element';
54:
55: /**
56: * Initialize resource model
57: *
58: */
59: protected function _construct()
60: {
61: $this->_init('eav/form_element');
62: }
63:
64: /**
65: * Retrieve resource instance wrapper
66: *
67: * @return Mage_Eav_Model_Mysql4_Form_Element
68: */
69: protected function _getResource()
70: {
71: return parent::_getResource();
72: }
73:
74: /**
75: * Retrieve resource collection instance wrapper
76: *
77: * @return Mage_Eav_Model_Mysql4_Form_Element_Collection
78: */
79: public function getCollection()
80: {
81: return parent::getCollection();
82: }
83:
84: /**
85: * Validate data before save data
86: *
87: * @throws Mage_Core_Exception
88: * @return Mage_Eav_Model_Form_Element
89: */
90: protected function _beforeSave()
91: {
92: if (!$this->getTypeId()) {
93: Mage::throwException(Mage::helper('eav')->__('Invalid form type.'));
94: }
95: if (!$this->getAttributeId()) {
96: Mage::throwException(Mage::helper('eav')->__('Invalid EAV attribute.'));
97: }
98:
99: return parent::_beforeSave();
100: }
101:
102: /**
103: * Retrieve EAV Attribute instance
104: *
105: * @return Mage_Eav_Model_Entity_Attribute
106: */
107: public function getAttribute()
108: {
109: if (!$this->hasData('attribute')) {
110: $attribute = Mage::getSingleton('eav/config')
111: ->getAttribute($this->getEntityTypeId(), $this->getAttributeId());
112: $this->setData('attribute', $attribute);
113: }
114: return $this->_getData('attribute');
115: }
116: }
117: