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_Model_Mysql4_Sample extends Mage_Core_Model_Mysql4_Abstract
00035 {
00036
00037
00038
00039
00040 protected function _construct()
00041 {
00042 $this->_init('downloadable/sample', 'sample_id');
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 public function saveItemTitle($sampleObject)
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 }
00081
00082
00083
00084
00085
00086
00087
00088 public function deleteItems($items)
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 }
00108
00109
00110
00111
00112
00113
00114
00115
00116 public function getSearchableData($productId, $storeId)
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 }
00134 }