- Timestamp:
- 2010/12/18 20:04:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/helper/SC_Helper_CSV.php
r19730 r19742 120 120 $data = $objCSV->lfGetCSV("dtb_order", $where, $option, $arrval, $arrCsvOutputCols, $arrCsvOutputConvs); 121 121 } 122 123 // CSV作成 コールバック関数 124 function cbOutputProductCSV($data) { 125 $line = $this->sfArrayToCSV($data); 126 $line = mb_convert_encoding($line, 'SJIS-Win'); 127 $line .= "\r\n"; 128 fwrite($this->fpOutput, $line); 129 return true; 130 } 122 131 123 132 // CSVを送信する。(商品) 124 function sfDownloadProductsCsv($where, $arrval, $order ) {133 function sfDownloadProductsCsv($where, $arrval, $order, $is_download = false) { 125 134 126 135 // CSV出力タイトル行の作成 … … 131 140 $objQuery = new SC_Query(); 132 141 $objQuery->setOrder($order); 133 134 /* 135 * FIXME 136 * パフォーマンスが出ないため, 137 * SC_Product::getProductsClassByProductIds() を使用した実装に変更 138 */ 139 $dataRows = $objQuery->select( 140 SC_Utils_Ex::sfGetCommaList($arrOutputCols, true, array('category_id')) 141 ,'vw_product_class AS prdcls' 142 ,$where 143 ,$arrval 144 ); 145 146 // 規格分類名一覧 147 if (in_array('classcategory_id1', $arrOutputCols) || in_array('classcategory_id2', $arrOutputCols)) { 148 $objDb = new SC_Helper_DB_Ex(); 149 $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); 150 } 151 152 $outputArray = array(); 153 154 // ヘッダ行 155 $outputArray[] = $arrOutput['disp_name']; 156 157 $objQuery = new SC_Query(); 158 // データ行 159 foreach ($dataRows as $row) { 160 // 規格名1 161 if (in_array('classcategory_id1', $arrOutputCols)) { 162 $row['classcategory_id1'] = $arrClassCatName[$row['classcategory_id1']]; 163 } 164 165 // 規格名2 166 if (in_array('classcategory_id2', $arrOutputCols)) { 167 $row['classcategory_id2'] = $arrClassCatName[$row['classcategory_id2']]; 168 } 169 170 // カテゴリID 171 if (in_array('category_id', $arrOutputCols)) { 172 $row['category_id'] = $objQuery->getCol( 173 "category_id", 174 "dtb_product_categories", 175 "product_id = ?", 176 array($row['product_id']) 177 ); 178 } 179 180 $outputArray[] = $row; 181 } 182 183 // CSVを送信する。 184 #$this->lfDownloadCsv($outputArray); 185 return $this->lfGetCsv2($outputArray); 186 187 // 成功終了 188 #return true; 142 143 $objProduct = new SC_Product(); 144 $cols = SC_Utils_Ex::sfGetCommaList($arrOutputCols, true); 145 $sql = $objQuery->getSql($cols, $objProduct->prdclsSQL(),$where); 146 $header = $this->sfArrayToCSV($arrOutput['disp_name']); 147 $header = mb_convert_encoding($header, 'SJIS-Win'); 148 $header .= "\r\n"; 149 150 //テンポラリファイル作成 151 // TODO: パフォーマンス向上には、ストリームを使うようにすると良い 152 // 環境要件がバージョン5.1以上になったら使うように変えても良いかと 153 // fopen('php://temp/maxmemory:'. (5*1024*1024), 'r+'); 154 $tmp_filename = tempnam(CSV_TEMP_DIR, 'product_csv'); 155 $this->fpOutput = fopen($tmp_filename, "w+"); 156 157 fwrite($this->fpOutput, $header); 158 159 $objQuery->doCallbackAll(array(&$this, 'cbOutputProductCSV'), $sql, $arrval); 160 161 fclose($this->fpOutput); 162 163 if($is_download) { 164 // CSVを送信する。 165 $this->lfDownloadCSVFile($tmp_filename,"product_"); 166 $res = true; 167 }else{ 168 $res = SC_Utils_Ex::sfReadFile($tmp_filename); 169 } 170 171 //テンポラリファイル削除 172 unlink($tmp_filename); 173 return $res; 189 174 } 190 175 … … 498 483 } 499 484 } 485 486 /** 487 * CSVファイルを送信する。 488 */ 489 function lfDownloadCSVFile($filepath, $prefix = "") { 490 $file_name = $prefix . date("YmdHis") . ".csv"; 491 492 /* HTTPヘッダの出力 */ 493 Header("Content-disposition: attachment; filename=${file_name}"); 494 Header("Content-type: application/octet-stream; name=${file_name}"); 495 Header("Cache-Control: "); 496 Header("Pragma: "); 497 498 /* データを出力 */ 499 // file_get_contentsはメモリマッピングも自動的に使ってくれるので高速&省メモリ 500 echo file_get_contents($filepath); 501 } 500 502 501 503 /**
Note: See TracChangeset
for help on using the changeset viewer.