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_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00035 {
00036
00037
00038
00039
00040
00041 protected function _construct()
00042 {
00043 $this->_init('downloadable/sample');
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 public function addProductToFilter($product)
00053 {
00054 if (empty($product)) {
00055 $this->addFieldToFilter('product_id', '');
00056 } elseif (is_array($product)) {
00057 $this->addFieldToFilter('product_id', array('in' => $product));
00058 } elseif ($product instanceof Mage_Catalog_Model_Product) {
00059 $this->addFieldToFilter('product_id', $product->getId());
00060 } else {
00061 $this->addFieldToFilter('product_id', $product);
00062 }
00063
00064 return $this;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 public function addTitleToResult($storeId=0)
00074 {
00075 $this->getSelect()
00076 ->joinLeft(array('default_title_table' => $this->getTable('downloadable/sample_title')),
00077 '`default_title_table`.sample_id=`main_table`.sample_id AND `default_title_table`.store_id = 0',
00078 array('default_title' => 'title'))
00079 ->joinLeft(array('store_title_table' => $this->getTable('downloadable/sample_title')),
00080 '`store_title_table`.sample_id=`main_table`.sample_id AND `store_title_table`.store_id = ' . intval($storeId),
00081 array('store_title' => 'title','title' => new Zend_Db_Expr('IFNULL(`store_title_table`.title, `default_title_table`.title)')))
00082 ->order('main_table.sort_order ASC')
00083 ->order('title ASC');
00084
00085 return $this;
00086 }
00087
00088 }