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