00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content extends Mage_Adminhtml_Block_Widget
00036 {
00037
00038 public function __construct()
00039 {
00040 parent::__construct();
00041 $this->setTemplate('catalog/product/helper/gallery.phtml');
00042 }
00043
00044 protected function _prepareLayout()
00045 {
00046 $this->setChild('uploader',
00047 $this->getLayout()->createBlock('adminhtml/media_uploader')
00048 );
00049
00050 $this->getUploader()->getConfig()
00051 ->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/catalog_product_gallery/upload'))
00052 ->setFileField('image')
00053 ->setFilters(array(
00054 'images' => array(
00055 'label' => Mage::helper('adminhtml')->__('Images (.gif, .jpg, .png)'),
00056 'files' => array('*.gif', '*.jpg','*.jpeg', '*.png')
00057 )
00058 ));
00059
00060 return parent::_prepareLayout();
00061 }
00062
00063
00064
00065
00066
00067
00068 public function getUploader()
00069 {
00070 return $this->getChild('uploader');
00071 }
00072
00073
00074
00075
00076
00077
00078 public function getUploaderHtml()
00079 {
00080 return $this->getChildHtml('uploader');
00081 }
00082
00083 public function getJsObjectName()
00084 {
00085 return $this->getHtmlId() . 'JsObject';
00086 }
00087
00088 public function getAddImagesButton()
00089 {
00090 return $this->getButtonHtml(
00091 Mage::helper('catalog')->__('Add New Images'),
00092 $this->getJsObjectName() . '.showUploader()',
00093 'add',
00094 $this->getHtmlId() . '_add_images_button'
00095 );
00096 }
00097
00098 public function getImagesJson()
00099 {
00100 if(is_array($this->getElement()->getValue())) {
00101 $value = $this->getElement()->getValue();
00102 if(count($value['images'])>0) {
00103 foreach ($value['images'] as &$image) {
00104 $image['url'] = Mage::getSingleton('catalog/product_media_config')
00105 ->getMediaUrl($image['file']);
00106 }
00107 return Zend_Json::encode($value['images']);
00108 }
00109 }
00110 return '[]';
00111 }
00112
00113 public function getImagesValuesJson()
00114 {
00115 $values = array();
00116 foreach ($this->getMediaAttributes() as $attribute) {
00117
00118 $values[$attribute->getAttributeCode()] = $this->getElement()->getDataObject()->getData(
00119 $attribute->getAttributeCode()
00120 );
00121 }
00122 return Zend_Json::encode($values);
00123 }
00124
00125
00126
00127
00128
00129
00130 public function getImageTypes()
00131 {
00132 $imageTypes = array();
00133 foreach ($this->getMediaAttributes() as $attribute) {
00134
00135 $imageTypes[$attribute->getAttributeCode()] = array(
00136 'label' => $attribute->getFrontend()->getLabel() . ' '
00137 . Mage::helper('catalog')->__($this->getElement()->getScopeLabel($attribute)),
00138 'field' => $this->getElement()->getAttributeFieldName($attribute)
00139 );
00140 }
00141 return $imageTypes;
00142 }
00143
00144 public function hasUseDefault()
00145 {
00146 foreach ($this->getMediaAttributes() as $attribute) {
00147 if($this->getElement()->canDisplayUseDefault($attribute)) {
00148 return true;
00149 }
00150 }
00151
00152 return false;
00153 }
00154
00155
00156
00157
00158
00159
00160 public function getMediaAttributes()
00161 {
00162 return $this->getElement()->getDataObject()->getMediaAttributes();
00163 }
00164
00165 public function getImageTypesJson()
00166 {
00167 return Zend_Json::encode($this->getImageTypes());
00168 }
00169
00170 }