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_Adminhtml
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: * Catalog fieldset element renderer
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element
35: extends Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
36: {
37: /**
38: * Initialize block template
39: */
40: protected function _construct()
41: {
42: $this->setTemplate('catalog/form/renderer/fieldset/element.phtml');
43: }
44:
45: /**
46: * Retrieve data object related with form
47: *
48: * @return Mage_Catalog_Model_Product || Mage_Catalog_Model_Category
49: */
50: public function getDataObject()
51: {
52: return $this->getElement()->getForm()->getDataObject();
53: }
54:
55: /**
56: * Retireve associated with element attribute object
57: *
58: * @return Mage_Catalog_Model_Resource_Eav_Attribute
59: */
60: public function getAttribute()
61: {
62: return $this->getElement()->getEntityAttribute();
63: }
64:
65: /**
66: * Retrieve associated attribute code
67: *
68: * @return string
69: */
70: public function getAttributeCode()
71: {
72: return $this->getAttribute()->getAttributeCode();
73: }
74:
75: /**
76: * Check "Use default" checkbox display availability
77: *
78: * @return bool
79: */
80: public function canDisplayUseDefault()
81: {
82: if ($attribute = $this->getAttribute()) {
83: if (!$attribute->isScopeGlobal()
84: && $this->getDataObject()
85: && $this->getDataObject()->getId()
86: && $this->getDataObject()->getStoreId()) {
87: return true;
88: }
89: }
90: return false;
91: }
92:
93: /**
94: * Check default value usage fact
95: *
96: * @return bool
97: */
98: public function usedDefault()
99: {
100: $attributeCode = $this->getAttribute()->getAttributeCode();
101: $defaultValue = $this->getDataObject()->getAttributeDefaultValue($attributeCode);
102:
103: if (!$this->getDataObject()->getExistsStoreValueFlag($attributeCode)) {
104: return true;
105: } else if ($this->getElement()->getValue() == $defaultValue &&
106: $this->getDataObject()->getStoreId() != $this->_getDefaultStoreId()
107: ) {
108: return false;
109: }
110: if ($defaultValue === false && !$this->getAttribute()->getIsRequired() && $this->getElement()->getValue()) {
111: return false;
112: }
113: return $defaultValue === false;
114: }
115:
116: /**
117: * Disable field in default value using case
118: *
119: * @return Mage_Adminhtml_Block_Catalog_Form_Renderer_Fieldset_Element
120: */
121: public function checkFieldDisable()
122: {
123: if ($this->canDisplayUseDefault() && $this->usedDefault()) {
124: $this->getElement()->setDisabled(true);
125: }
126: return $this;
127: }
128:
129: /**
130: * Retrieve label of attribute scope
131: *
132: * GLOBAL | WEBSITE | STORE
133: *
134: * @return string
135: */
136: public function getScopeLabel()
137: {
138: $html = '';
139: $attribute = $this->getElement()->getEntityAttribute();
140: if (!$attribute || Mage::app()->isSingleStoreMode() || $attribute->getFrontendInput()=='gallery') {
141: return $html;
142: }
143: if ($attribute->isScopeGlobal()) {
144: $html .= Mage::helper('adminhtml')->__('[GLOBAL]');
145: } elseif ($attribute->isScopeWebsite()) {
146: $html .= Mage::helper('adminhtml')->__('[WEBSITE]');
147: } elseif ($attribute->isScopeStore()) {
148: $html .= Mage::helper('adminhtml')->__('[STORE VIEW]');
149: }
150:
151: return $html;
152: }
153:
154: /**
155: * Retrieve element label html
156: *
157: * @return string
158: */
159: public function getElementLabelHtml()
160: {
161: $element = $this->getElement();
162: $label = $element->getLabel();
163: if (!empty($label)) {
164: $element->setLabel($this->__($label));
165: }
166: return $element->getLabelHtml();
167: }
168:
169: /**
170: * Retrieve element html
171: *
172: * @return string
173: */
174: public function getElementHtml()
175: {
176: return $this->getElement()->getElementHtml();
177: }
178:
179: /**
180: * Default sore ID getter
181: *
182: * @return integer
183: */
184: protected function _getDefaultStoreId()
185: {
186: return Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID;
187: }
188: }
189: