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 Model
30: *
31: * @method Mage_Eav_Model_Resource_Form_Fieldset _getResource()
32: * @method Mage_Eav_Model_Resource_Form_Fieldset getResource()
33: * @method int getTypeId()
34: * @method Mage_Eav_Model_Form_Fieldset setTypeId(int $value)
35: * @method string getCode()
36: * @method Mage_Eav_Model_Form_Fieldset setCode(string $value)
37: * @method int getSortOrder()
38: * @method Mage_Eav_Model_Form_Fieldset setSortOrder(int $value)
39: *
40: * @category Mage
41: * @package Mage_Eav
42: * @author Magento Core Team <core@magentocommerce.com>
43: */
44: class Mage_Eav_Model_Form_Fieldset extends Mage_Core_Model_Abstract
45: {
46: /**
47: * Prefix of model events names
48: *
49: * @var string
50: */
51: protected $_eventPrefix = 'eav_form_fieldset';
52:
53: /**
54: * Initialize resource model
55: *
56: */
57: protected function _construct()
58: {
59: $this->_init('eav/form_fieldset');
60: }
61:
62: /**
63: * Retrieve resource instance wrapper
64: *
65: * @return Mage_Eav_Model_Mysql4_Form_Fieldset
66: */
67: protected function _getResource()
68: {
69: return parent::_getResource();
70: }
71:
72: /**
73: * Retrieve resource collection instance wrapper
74: *
75: * @return Mage_Eav_Model_Mysql4_Form_Fieldset_Collection
76: */
77: public function getCollection()
78: {
79: return parent::getCollection();
80: }
81:
82: /**
83: * Validate data before save data
84: *
85: * @throws Mage_Core_Exception
86: * @return Mage_Eav_Model_Form_Fieldset
87: */
88: protected function _beforeSave()
89: {
90: if (!$this->getTypeId()) {
91: Mage::throwException(Mage::helper('eav')->__('Invalid form type.'));
92: }
93: if (!$this->getStoreId() && $this->getLabel()) {
94: $this->setStoreLabel($this->getStoreId(), $this->getLabel());
95: }
96:
97: return parent::_beforeSave();
98: }
99:
100: /**
101: * Retrieve fieldset labels for stores
102: *
103: * @return array
104: */
105: public function getLabels()
106: {
107: if (!$this->hasData('labels')) {
108: $this->setData('labels', $this->_getResource()->getLabels($this));
109: }
110: return $this->_getData('labels');
111: }
112:
113: /**
114: * Set fieldset store labels
115: * Input array where key - store_id and value = label
116: *
117: * @param array $labels
118: * @return Mage_Eav_Model_Form_Fieldset
119: */
120: public function setLabels(array $labels)
121: {
122: return $this->setData('labels', $labels);
123: }
124:
125: /**
126: * Set fieldset store label
127: *
128: * @param int $storeId
129: * @param string $label
130: * @return Mage_Eav_Model_Form_Fieldset
131: */
132: public function setStoreLabel($storeId, $label)
133: {
134: $labels = $this->getLabels();
135: $labels[$storeId] = $label;
136:
137: return $this->setLabels($labels);
138: }
139:
140: /**
141: * Retrieve label store scope
142: *
143: * @return int
144: */
145: public function getStoreId()
146: {
147: if (!$this->hasStoreId()) {
148: $this->setData('store_id', Mage::app()->getStore()->getId());
149: }
150: return $this->_getData('store_id');
151: }
152: }
153: