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 class Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Samples extends Mage_Adminhtml_Block_Widget
00035 {
00036
00037
00038
00039
00040 public function __construct()
00041 {
00042 parent::__construct();
00043 $this->setTemplate('downloadable/product/edit/downloadable/samples.phtml');
00044 }
00045
00046
00047
00048
00049
00050
00051 public function getProduct()
00052 {
00053 return Mage::registry('current_product');
00054 }
00055
00056
00057
00058
00059
00060
00061 public function isReadonly()
00062 {
00063 return $this->getProduct()->getDownloadableReadonly();
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 public function getAddButtonHtml()
00073 {
00074 $addButton = $this->getLayout()->createBlock('adminhtml/widget_button')
00075 ->setData(array(
00076 'label' => Mage::helper('downloadable')->__('Add New Row'),
00077 'id' => 'add_sample_item',
00078 'class' => 'add',
00079 ));
00080 return $addButton->toHtml();
00081 }
00082
00083
00084
00085
00086
00087
00088 public function getSampleData()
00089 {
00090 $samplesArr = array();
00091 $samples = $this->getProduct()->getTypeInstance(true)->getSamples($this->getProduct());
00092 foreach ($samples as $item) {
00093 $tmpSampleItem = array(
00094 'sample_id' => $item->getId(),
00095 'title' => $item->getTitle(),
00096 'sample_url' => $item->getSampleUrl(),
00097 'sample_type' => $item->getSampleType(),
00098 'sort_order' => $item->getSortOrder(),
00099 );
00100 $file = Mage::helper('downloadable/file')->getFilePath(
00101 Mage_Downloadable_Model_Sample::getBasePath(), $item->getSampleFile()
00102 );
00103 if ($item->getSampleFile() && is_file($file)) {
00104 $tmpSampleItem['file_save'] = array(
00105 array(
00106 'file' => $item->getSampleFile(),
00107 'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
00108 'size' => filesize($file),
00109 'status' => 'old'
00110 ));
00111 }
00112 if ($this->getProduct() && $item->getStoreTitle()) {
00113 $tmpSampleItem['store_title'] = $item->getStoreTitle();
00114 }
00115 $samplesArr[] = new Varien_Object($tmpSampleItem);
00116 }
00117
00118 return $samplesArr;
00119 }
00120
00121
00122
00123
00124
00125
00126 public function getUsedDefault()
00127 {
00128 return is_null($this->getProduct()->getAttributeDefaultValue('samples_title'));
00129 }
00130
00131
00132
00133
00134
00135
00136 public function getSamplesTitle()
00137 {
00138 return Mage::getStoreConfig(Mage_Downloadable_Model_Sample::XML_PATH_SAMPLES_TITLE);
00139 }
00140
00141
00142
00143
00144
00145 protected function _prepareLayout()
00146 {
00147 $this->setChild(
00148 'upload_button',
00149 $this->getLayout()->createBlock('adminhtml/widget_button')
00150 ->addData(array(
00151 'id' => '',
00152 'label' => Mage::helper('adminhtml')->__('Upload Files'),
00153 'type' => 'button',
00154 'onclick' => 'Downloadable.massUploadByType(\'samples\')'
00155 ))
00156 );
00157 }
00158
00159
00160
00161
00162
00163
00164 public function getUploadButtonHtml()
00165 {
00166 return $this->getChild('upload_button')->toHtml();
00167 }
00168
00169
00170
00171
00172
00173
00174 public function getConfigJson()
00175 {
00176 $this->getConfig()->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('downloadableadmin/file/upload', array('type' => 'samples', '_secure' => true)));
00177 $this->getConfig()->setParams(array('form_key' => $this->getFormKey()));
00178 $this->getConfig()->setFileField('samples');
00179 $this->getConfig()->setFilters(array(
00180 'all' => array(
00181 'label' => Mage::helper('adminhtml')->__('All Files'),
00182 'files' => array('*.*')
00183 )
00184 ));
00185 $this->getConfig()->setReplaceBrowseWithRemove(true);
00186 $this->getConfig()->setWidth('32');
00187 $this->getConfig()->setHideUploadButton(true);
00188 return Zend_Json::encode($this->getConfig()->getData());
00189 }
00190
00191
00192
00193
00194
00195
00196 public function getConfig()
00197 {
00198 if(is_null($this->_config)) {
00199 $this->_config = new Varien_Object();
00200 }
00201
00202 return $this->_config;
00203 }
00204 }