Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links Class Reference

Inheritance diagram for Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links:

Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 __construct ()
 getProduct ()
 getPurchasedSeparatelyAttribute ()
 getPurchasedSeparatelySelect ()
 getAddButtonHtml ()
 getLinksTitle ()
 getUsedDefault ()
 getIsPriceWebsiteScope ()
 getLinkData ()
 getPriceValue ($value)
 getConfigMaxDownloads ()
 getUploadButtonHtml ()
 getConfigJson ($type='links')
 getConfig ()

Protected Member Functions

 _prepareLayout ()

Protected Attributes

 $_purchasedSeparatelyAttribute = null


Detailed Description

Definition at line 34 of file Links.php.


Constructor & Destructor Documentation

__construct (  ) 

Class constructor

Reimplemented from Varien_Object.

Definition at line 47 of file Links.php.

00048     {
00049         parent::__construct();
00050         $this->setTemplate('downloadable/product/edit/downloadable/links.phtml');
00051     }


Member Function Documentation

_prepareLayout (  )  [protected]

Prepare block Layout

Reimplemented from Mage_Core_Block_Abstract.

Definition at line 236 of file Links.php.

00237     {
00238         $this->setChild(
00239             'upload_button',
00240             $this->getLayout()->createBlock('adminhtml/widget_button')
00241                 ->addData(array(
00242                     'id'      => '',
00243                     'label'   => Mage::helper('adminhtml')->__('Upload Files'),
00244                     'type'    => 'button',
00245                     'onclick' => 'Downloadable.massUploadByType(\'links\');Downloadable.massUploadByType(\'linkssample\')'
00246                 ))
00247         );
00248     }

getAddButtonHtml (  ) 

Retrieve Add button HTML

Returns:
string

Definition at line 101 of file Links.php.

00102     {
00103         $addButton = $this->getLayout()->createBlock('adminhtml/widget_button')
00104             ->setData(array(
00105                 'label' => Mage::helper('downloadable')->__('Add New Row'),
00106                 'id' => 'add_link_item',
00107                 'class' => 'add',
00108             ));
00109         return $addButton->toHtml();
00110     }

getConfig (  ) 

Retrive config object

Returns:
Varien_Config

Definition at line 287 of file Links.php.

00288     {
00289         if(is_null($this->_config)) {
00290             $this->_config = new Varien_Object();
00291         }
00292 
00293         return $this->_config;
00294     }

getConfigJson ( type = 'links'  ) 

Retrive config json

Returns:
string

Definition at line 265 of file Links.php.

00266     {
00267         $this->getConfig()->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('downloadableadmin/file/upload', array('type' => $type, '_secure' => true)));
00268         $this->getConfig()->setParams(array('form_key' => $this->getFormKey()));
00269         $this->getConfig()->setFileField($type);
00270         $this->getConfig()->setFilters(array(
00271             'all'    => array(
00272                 'label' => Mage::helper('adminhtml')->__('All Files'),
00273                 'files' => array('*.*')
00274             )
00275         ));
00276         $this->getConfig()->setReplaceBrowseWithRemove(true);
00277         $this->getConfig()->setWidth('32');
00278         $this->getConfig()->setHideUploadButton(true);
00279         return Zend_Json::encode($this->getConfig()->getData());
00280     }

getConfigMaxDownloads (  ) 

Retrieve max downloads value from config

Returns:
int

Definition at line 227 of file Links.php.

getIsPriceWebsiteScope (  ) 

Return true if price in website scope

Returns:
bool

Definition at line 137 of file Links.php.

00138     {
00139         $scope =  (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);
00140         if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
00141             return true;
00142         }
00143         return false;
00144     }

getLinkData (  ) 

Return array of links

Returns:
array

Definition at line 151 of file Links.php.

00152     {
00153         $linkArr = array();
00154         $links = $this->getProduct()->getTypeInstance(true)->getLinks($this->getProduct());
00155         $priceWebsiteScope = $this->getIsPriceWebsiteScope();
00156         foreach ($links as $item) {
00157             $tmpLinkItem = array(
00158                 'link_id' => $item->getId(),
00159                 'title' => $item->getTitle(),
00160                 'price' => $this->getPriceValue($item->getPrice()),
00161                 'number_of_downloads' => $item->getNumberOfDownloads(),
00162                 'is_shareable' => $item->getIsShareable(),
00163                 'link_url' => $item->getLinkUrl(),
00164                 'link_type' => $item->getLinkType(),
00165                 'sample_file' => $item->getSampleFile(),
00166                 'sample_url' => $item->getSampleUrl(),
00167                 'sample_type' => $item->getSampleType(),
00168                 'sort_order' => $item->getSortOrder()
00169             );
00170             $file = Mage::helper('downloadable/file')->getFilePath(
00171                 Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile()
00172             );
00173             if ($item->getLinkFile() && is_file($file)) {
00174                 $name = '<a href="' . $this->getUrl('downloadableadmin/product_edit/link', array('id' => $item->getId(), '_secure' => true)) . '">' .
00175                     Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile()) .
00176                     '</a>';
00177                 $tmpLinkItem['file_save'] = array(
00178                     array(
00179                         'file' => $item->getLinkFile(),
00180                         'name' => $name,
00181                         'size' => filesize($file),
00182                         'status' => 'old'
00183                     ));
00184             }
00185             $sampleFile = Mage::helper('downloadable/file')->getFilePath(
00186                 Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile()
00187             );
00188             if ($item->getSampleFile() && is_file($sampleFile)) {
00189                 $tmpLinkItem['sample_file_save'] = array(
00190                     array(
00191                         'file' => $item->getSampleFile(),
00192                         'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
00193                         'size' => filesize($sampleFile),
00194                         'status' => 'old'
00195                     ));
00196             }
00197             if ($item->getNumberOfDownloads() == '0') {
00198                 $tmpLinkItem['is_unlimited'] = ' checked="checked"';
00199             }
00200             if ($this->getProduct()->getStoreId() && $item->getStoreTitle()) {
00201                 $tmpLinkItem['store_title'] = $item->getStoreTitle();
00202             }
00203             if ($this->getProduct()->getStoreId() && $priceWebsiteScope) {
00204                 $tmpLinkItem['website_price'] = $item->getWebsitePrice();
00205             }
00206             $linkArr[] = new Varien_Object($tmpLinkItem);
00207         }
00208         return $linkArr;
00209     }

getLinksTitle (  ) 

Retrieve default links title

Returns:
string

Definition at line 117 of file Links.php.

getPriceValue ( value  ) 

Return formated price with two digits after decimal point

Parameters:
decimal $value
Returns:
decimal

Definition at line 217 of file Links.php.

00218     {
00219         return number_format($value, 2, null, '');
00220     }

getProduct (  ) 

Get product that is being edited

Returns:
Mage_Catalog_Model_Product

Definition at line 58 of file Links.php.

00059     {
00060         return Mage::registry('product');
00061     }

getPurchasedSeparatelyAttribute (  ) 

Retrieve Purchased Separately Attribute object

Returns:
Mage_Catalog_Model_Resource_Eav_Attribute

Definition at line 68 of file Links.php.

00069     {
00070         if (is_null($this->_purchasedSeparatelyAttribute)) {
00071             $_attributeCode = 'links_purchased_separately';
00072 
00073             $this->_purchasedSeparatelyAttribute = Mage::getModel('eav/entity_attribute')
00074                 ->loadByCode('catalog_product', $_attributeCode);
00075         }
00076 
00077         return $this->_purchasedSeparatelyAttribute;
00078     }

getPurchasedSeparatelySelect (  ) 

Retrieve Purchased Separately HTML select

Returns:
string

Definition at line 85 of file Links.php.

00086     {
00087         $select = $this->getLayout()->createBlock('adminhtml/html_select')
00088             ->setName('product[links_purchased_separately]')
00089             ->setId('downloadable_link_purchase_type')
00090             ->setOptions(Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray())
00091             ->setValue($this->getProduct()->getLinksPurchasedSeparately());
00092 
00093         return $select->getHtml();
00094     }

getUploadButtonHtml (  ) 

Retrieve Upload button HTML

Returns:
string

Definition at line 255 of file Links.php.

00256     {
00257         return $this->getChild('upload_button')->toHtml();
00258     }

getUsedDefault (  ) 

Check exists defined links title

Returns:
bool

Definition at line 127 of file Links.php.

00128     {
00129         return is_null($this->getProduct()->getAttributeDefaultValue('links_title'));
00130     }


Member Data Documentation

$_purchasedSeparatelyAttribute = null [protected]

Definition at line 41 of file Links.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:07 2009 for Magento by  doxygen 1.5.8