Mage_Downloadable_Model_Mysql4_Sample Class Reference

Inheritance diagram for Mage_Downloadable_Model_Mysql4_Sample:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 saveItemTitle ($sampleObject)
 deleteItems ($items)
 getSearchableData ($productId, $storeId)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 34 of file Sample.php.


Member Function Documentation

_construct (  )  [protected]

Initialize connection

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Sample.php.

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

deleteItems ( items  ) 

Delete data by item(s)

Parameters:
Mage_Downloadable_Model_Sample|array|int $items
Returns:
Mage_Downloadable_Model_Mysql4_Sample

Definition at line 88 of file Sample.php.

00089     {
00090         $where = '';
00091         if ($items instanceof Mage_Downloadable_Model_Sample) {
00092             $where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $items->getId());
00093         }
00094         elseif (is_array($items)) {
00095             $where = $this->_getReadAdapter()->quoteInto('sample_id in (?)', $items);
00096         }
00097         else {
00098             $where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $items);
00099         }
00100         if ($where) {
00101             $this->_getReadAdapter()->delete(
00102                 $this->getTable('downloadable/sample'),$where);
00103             $this->_getReadAdapter()->delete(
00104                 $this->getTable('downloadable/sample_title'), $where);
00105         }
00106         return $this;
00107     }

getSearchableData ( productId,
storeId 
)

Retrieve links searchable data

Parameters:
int $productId
int $storeId
Returns:
array

Definition at line 116 of file Sample.php.

00117     {
00118         $select = $this->_getReadAdapter()->select()
00119             ->from(array('sample' => $this->getMainTable()), null)
00120             ->join(
00121                 array('sample_title_default' => $this->getTable('downloadable/sample_title')),
00122                 'sample_title_default.sample_id=sample.sample_id AND sample_title_default.store_id=0',
00123                 array())
00124             ->joinLeft(
00125                 array('sample_title_store' => $this->getTable('downloadable/sample_title')),
00126                 'sample_title_store.sample_id=sample.sample_id AND sample_title_store.store_id=' . intval($storeId),
00127                 array('title' => 'IFNULL(sample_title_store.title, sample_title_default.title)'))
00128             ->where('sample.product_id=?', $productId);
00129         if (!$searchData = $this->_getReadAdapter()->fetchCol($select)) {
00130             $searchData = array();
00131         }
00132         return $searchData;
00133     }

saveItemTitle ( sampleObject  ) 

Save title of sample item in store scope

Parameters:
Mage_Downloadable_Model_Sample $sampleObject
Returns:
Mage_Downloadable_Model_Mysql4_Sample

Definition at line 51 of file Sample.php.

00052     {
00053         $stmt = $this->_getReadAdapter()->select()
00054             ->from($this->getTable('downloadable/sample_title'))
00055             ->where('sample_id = ?', $sampleObject->getId())
00056             ->where('store_id = ?', $sampleObject->getStoreId());
00057         if ($this->_getReadAdapter()->fetchOne($stmt)) {
00058             $where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $sampleObject->getId()) .
00059                 ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $sampleObject->getStoreId());
00060             if ($sampleObject->getUseDefaultTitle()) {
00061                 $this->_getWriteAdapter()->delete(
00062                     $this->getTable('downloadable/sample_title'), $where);
00063             } else {
00064                 $this->_getWriteAdapter()->update(
00065                     $this->getTable('downloadable/sample_title'),
00066                     array('title' => $sampleObject->getTitle()), $where);
00067             }
00068         } else {
00069             if (!$sampleObject->getUseDefaultTitle()) {
00070                 $this->_getWriteAdapter()->insert(
00071                     $this->getTable('downloadable/sample_title'),
00072                     array(
00073                         'sample_id' => $sampleObject->getId(),
00074                         'store_id' => $sampleObject->getStoreId(),
00075                         'title' => $sampleObject->getTitle(),
00076                     ));
00077             }
00078         }
00079         return $this;
00080     }


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

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