Mage_Downloadable_Model_Mysql4_Link Class Reference

Inheritance diagram for Mage_Downloadable_Model_Mysql4_Link:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 saveItemTitleAndPrice ($linkObject)
 deleteItems ($items)
 getSearchableData ($productId, $storeId)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 34 of file Link.php.


Member Function Documentation

_construct (  )  [protected]

Initialize connection and define resource

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Link.php.

00041     {
00042         $this->_init('downloadable/link', 'link_id');
00043     }

deleteItems ( items  ) 

Delete data by item(s)

Parameters:
Mage_Downloadable_Model_Link|array|int $items
Returns:
Mage_Downloadable_Model_Mysql4_Link

Definition at line 115 of file Link.php.

00116     {
00117         $where = '';
00118         if ($items instanceof Mage_Downloadable_Model_Link) {
00119             $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $items->getId());
00120         }
00121         elseif (is_array($items)) {
00122             $where = $this->_getReadAdapter()->quoteInto('link_id in (?)', $items);
00123         }
00124         else {
00125             $where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $items);
00126         }
00127         if ($where) {
00128             $this->_getWriteAdapter()->delete(
00129                 $this->getTable('downloadable/link'), $where);
00130             $this->_getWriteAdapter()->delete(
00131                 $this->getTable('downloadable/link_title'), $where);
00132             $this->_getWriteAdapter()->delete(
00133                 $this->getTable('downloadable/link_price'), $where);
00134         }
00135         return $this;
00136     }

getSearchableData ( productId,
storeId 
)

Retrieve links searchable data

Parameters:
int $productId
int $storeId
Returns:
array

Definition at line 145 of file Link.php.

00146     {
00147         $select = $this->_getReadAdapter()->select()
00148             ->from(array('link' => $this->getMainTable()), null)
00149             ->join(
00150                 array('link_title_default' => $this->getTable('downloadable/link_title')),
00151                 'link_title_default.link_id=link.link_id AND link_title_default.store_id=0',
00152                 array())
00153             ->joinLeft(
00154                 array('link_title_store' => $this->getTable('downloadable/link_title')),
00155                 'link_title_store.link_id=link.link_id AND link_title_store.store_id=' . intval($storeId),
00156                 array('title' => 'IFNULL(link_title_store.title, link_title_default.title)'))
00157             ->where('link.product_id=?', $productId);
00158         if (!$searchData = $this->_getReadAdapter()->fetchCol($select)) {
00159             $searchData = array();
00160         }
00161         return $searchData;
00162     }

saveItemTitleAndPrice ( linkObject  ) 

Save title and price of link item

Parameters:
Mage_Downloadable_Model_Link $linkObject
Returns:
Mage_Downloadable_Model_Mysql4_link

Definition at line 51 of file Link.php.

00052     {
00053         $stmt = $this->_getReadAdapter()->select()
00054             ->from($this->getTable('downloadable/link_title'))
00055             ->where('link_id = ?', $linkObject->getId())
00056             ->where('store_id = ?', $linkObject->getStoreId());
00057         if ($this->_getReadAdapter()->fetchOne($stmt)) {
00058             $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) .
00059                 ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $linkObject->getStoreId());
00060             if ($linkObject->getUseDefaultTitle()) {
00061                 $this->_getWriteAdapter()->delete(
00062                     $this->getTable('downloadable/link_title'), $where);
00063             } else {
00064                 $this->_getWriteAdapter()->update(
00065                     $this->getTable('downloadable/link_title'),
00066                     array('title' => $linkObject->getTitle()), $where);
00067             }
00068         } else {
00069             if (!$linkObject->getUseDefaultTitle()) {
00070                 $this->_getWriteAdapter()->insert(
00071                     $this->getTable('downloadable/link_title'),
00072                     array(
00073                         'link_id' => $linkObject->getId(),
00074                         'store_id' => $linkObject->getStoreId(),
00075                         'title' => $linkObject->getTitle(),
00076                     ));
00077             }
00078         }
00079         $stmt = null;
00080         $stmt = $this->_getReadAdapter()->select()
00081             ->from($this->getTable('downloadable/link_price'))
00082             ->where('link_id = ?', $linkObject->getId())
00083             ->where('website_id = ?', $linkObject->getWebsiteId());
00084         if ($this->_getReadAdapter()->fetchOne($stmt)) {
00085             $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) .
00086                 ' AND ' . $this->_getReadAdapter()->quoteInto('website_id = ?', $linkObject->getWebsiteId());
00087             if ($linkObject->getUseDefaultPrice()) {
00088                 $this->_getReadAdapter()->delete(
00089                     $this->getTable('downloadable/link_price'), $where);
00090             } else {
00091                 $this->_getWriteAdapter()->update(
00092                     $this->getTable('downloadable/link_price'),
00093                     array('price' => $linkObject->getPrice()), $where);
00094             }
00095         } else {
00096             if (!$linkObject->getUseDefaultPrice()) {
00097                 $this->_getWriteAdapter()->insert(
00098                     $this->getTable('downloadable/link_price'),
00099                     array(
00100                         'link_id' => $linkObject->getId(),
00101                         'website_id' => $linkObject->getWebsiteId(),
00102                         'price' => $linkObject->getPrice()
00103                     ));
00104             }
00105         }
00106         return $this;
00107     }


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

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