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: class Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Samples
35: extends Mage_Adminhtml_Block_Widget
36: {
37: 38: 39: 40:
41: public function __construct()
42: {
43: parent::__construct();
44: $this->setTemplate('downloadable/product/edit/downloadable/samples.phtml');
45: }
46:
47: 48: 49: 50: 51:
52: public function getProduct()
53: {
54: return Mage::registry('current_product');
55: }
56:
57: 58: 59: 60: 61:
62: public function isReadonly()
63: {
64: return $this->getProduct()->getDownloadableReadonly();
65: }
66:
67:
68: 69: 70: 71: 72:
73: public function getAddButtonHtml()
74: {
75: $addButton = $this->getLayout()->createBlock('adminhtml/widget_button')
76: ->setData(array(
77: 'label' => Mage::helper('downloadable')->__('Add New Row'),
78: 'id' => 'add_sample_item',
79: 'class' => 'add',
80: ));
81: return $addButton->toHtml();
82: }
83:
84: 85: 86: 87: 88:
89: public function getSampleData()
90: {
91: $samplesArr = array();
92: $samples = $this->getProduct()->getTypeInstance(true)->getSamples($this->getProduct());
93: foreach ($samples as $item) {
94: $tmpSampleItem = array(
95: 'sample_id' => $item->getId(),
96: 'title' => $this->escapeHtml($item->getTitle()),
97: 'sample_url' => $item->getSampleUrl(),
98: 'sample_type' => $item->getSampleType(),
99: 'sort_order' => $item->getSortOrder(),
100: );
101: $file = Mage::helper('downloadable/file')->getFilePath(
102: Mage_Downloadable_Model_Sample::getBasePath(), $item->getSampleFile()
103: );
104: if ($item->getSampleFile() && !is_file($file)) {
105: Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
106: }
107: if ($item->getSampleFile() && is_file($file)) {
108: $tmpSampleItem['file_save'] = array(
109: array(
110: 'file' => $item->getSampleFile(),
111: 'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
112: 'size' => filesize($file),
113: 'status' => 'old'
114: ));
115: }
116: if ($this->getProduct() && $item->getStoreTitle()) {
117: $tmpSampleItem['store_title'] = $item->getStoreTitle();
118: }
119: $samplesArr[] = new Varien_Object($tmpSampleItem);
120: }
121:
122: return $samplesArr;
123: }
124:
125: 126: 127: 128: 129:
130: public function getUsedDefault()
131: {
132: return $this->getProduct()->getAttributeDefaultValue('samples_title') === false;
133: }
134:
135: 136: 137: 138: 139:
140: public function getSamplesTitle()
141: {
142: return Mage::getStoreConfig(Mage_Downloadable_Model_Sample::XML_PATH_SAMPLES_TITLE);
143: }
144:
145: 146: 147: 148:
149: protected function _prepareLayout()
150: {
151: $this->setChild(
152: 'upload_button',
153: $this->getLayout()->createBlock('adminhtml/widget_button')
154: ->addData(array(
155: 'id' => '',
156: 'label' => Mage::helper('adminhtml')->__('Upload Files'),
157: 'type' => 'button',
158: 'onclick' => 'Downloadable.massUploadByType(\'samples\')'
159: ))
160: );
161: }
162:
163: 164: 165: 166: 167:
168: public function getUploadButtonHtml()
169: {
170: return $this->getChild('upload_button')->toHtml();
171: }
172:
173: 174: 175: 176: 177:
178: public function getConfigJson()
179: {
180: $this->getConfig()->setUrl(Mage::getModel('adminhtml/url')
181: ->addSessionParam()
182: ->getUrl('*/downloadable_file/upload', array('type' => 'samples', '_secure' => true)));
183: $this->getConfig()->setParams(array('form_key' => $this->getFormKey()));
184: $this->getConfig()->setFileField('samples');
185: $this->getConfig()->setFilters(array(
186: 'all' => array(
187: 'label' => Mage::helper('adminhtml')->__('All Files'),
188: 'files' => array('*.*')
189: )
190: ));
191: $this->getConfig()->setReplaceBrowseWithRemove(true);
192: $this->getConfig()->setWidth('32');
193: $this->getConfig()->setHideUploadButton(true);
194: return Mage::helper('core')->jsonEncode($this->getConfig()->getData());
195: }
196:
197: 198: 199: 200: 201:
202: public function getConfig()
203: {
204: if(is_null($this->_config)) {
205: $this->_config = new Varien_Object();
206: }
207:
208: return $this->_config;
209: }
210: }
211: