1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content extends Mage_Adminhtml_Block_Widget
36: {
37:
38: public function __construct()
39: {
40: parent::__construct();
41: $this->setTemplate('catalog/product/helper/gallery.phtml');
42: }
43:
44: protected function _prepareLayout()
45: {
46: $this->setChild('uploader',
47: $this->getLayout()->createBlock('adminhtml/media_uploader')
48: );
49:
50: $this->getUploader()->getConfig()
51: ->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/catalog_product_gallery/upload'))
52: ->setFileField('image')
53: ->setFilters(array(
54: 'images' => array(
55: 'label' => Mage::helper('adminhtml')->__('Images (.gif, .jpg, .png)'),
56: 'files' => array('*.gif', '*.jpg','*.jpeg', '*.png')
57: )
58: ));
59:
60: Mage::dispatchEvent('catalog_product_gallery_prepare_layout', array('block' => $this));
61:
62: return parent::_prepareLayout();
63: }
64:
65: 66: 67: 68: 69:
70: public function getUploader()
71: {
72: return $this->getChild('uploader');
73: }
74:
75: 76: 77: 78: 79:
80: public function getUploaderHtml()
81: {
82: return $this->getChildHtml('uploader');
83: }
84:
85: public function getJsObjectName()
86: {
87: return $this->getHtmlId() . 'JsObject';
88: }
89:
90: public function getAddImagesButton()
91: {
92: return $this->getButtonHtml(
93: Mage::helper('catalog')->__('Add New Images'),
94: $this->getJsObjectName() . '.showUploader()',
95: 'add',
96: $this->getHtmlId() . '_add_images_button'
97: );
98: }
99:
100: public function getImagesJson()
101: {
102: if(is_array($this->getElement()->getValue())) {
103: $value = $this->getElement()->getValue();
104: if(count($value['images'])>0) {
105: foreach ($value['images'] as &$image) {
106: $image['url'] = Mage::getSingleton('catalog/product_media_config')
107: ->getMediaUrl($image['file']);
108: }
109: return Mage::helper('core')->jsonEncode($value['images']);
110: }
111: }
112: return '[]';
113: }
114:
115: public function getImagesValuesJson()
116: {
117: $values = array();
118: foreach ($this->getMediaAttributes() as $attribute) {
119:
120: $values[$attribute->getAttributeCode()] = $this->getElement()->getDataObject()->getData(
121: $attribute->getAttributeCode()
122: );
123: }
124: return Mage::helper('core')->jsonEncode($values);
125: }
126:
127: 128: 129: 130: 131:
132: public function getImageTypes()
133: {
134: $imageTypes = array();
135: foreach ($this->getMediaAttributes() as $attribute) {
136:
137: $imageTypes[$attribute->getAttributeCode()] = array(
138: 'label' => $attribute->getFrontend()->getLabel() . ' '
139: . Mage::helper('catalog')->__($this->getElement()->getScopeLabel($attribute)),
140: 'field' => $this->getElement()->getAttributeFieldName($attribute)
141: );
142: }
143: return $imageTypes;
144: }
145:
146: public function hasUseDefault()
147: {
148: foreach ($this->getMediaAttributes() as $attribute) {
149: if($this->getElement()->canDisplayUseDefault($attribute)) {
150: return true;
151: }
152: }
153:
154: return false;
155: }
156:
157: 158: 159: 160: 161:
162: public function getMediaAttributes()
163: {
164: return $this->getElement()->getDataObject()->getMediaAttributes();
165: }
166:
167: public function getImageTypesJson()
168: {
169: return Mage::helper('core')->jsonEncode($this->getImageTypes());
170: }
171:
172: }
173: