Changeset 22796 for branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php
- Timestamp:
- 2013/05/02 18:11:36 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSV.php
r22578 r22796 34 34 * FIXME 同一商品IDで商品規格違いを登録できない。(更新は可能) 35 35 */ 36 class LC_Page_Admin_Products_UploadCSV extends LC_Page_Admin_Ex 37 { 36 class LC_Page_Admin_Products_UploadCSV extends LC_Page_Admin_Ex { 38 37 39 38 // }}} … … 61 60 * @return void 62 61 */ 63 function init() 64 { 62 function init() { 65 63 parent::init(); 66 64 $this->tpl_mainpage = 'products/upload_csv.tpl'; … … 76 74 $this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date'); 77 75 $this->arrProductType = $masterData->getMasterData('mtb_product_type'); 78 $this->arrMaker = SC_Helper_ Maker_Ex::getIDValueList();79 $this->arrPayments = SC_Helper_ Payment_Ex::getIDValueList();76 $this->arrMaker = SC_Helper_DB_Ex::sfGetIDValueList('dtb_maker', 'maker_id', 'name'); 77 $this->arrPayments = SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', 'payment_method'); 80 78 $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); 81 79 $this->arrAllowedTag = $masterData->getMasterData('mtb_allowed_tag'); … … 88 86 * @return void 89 87 */ 90 function process() 91 { 88 function process() { 92 89 $this->action(); 93 90 $this->sendResponse(); … … 99 96 * @return void 100 97 */ 101 function action() 102 { 98 function action() { 103 99 104 100 $this->objDb = new SC_Helper_DB_Ex(); … … 125 121 $objFormParam = new SC_FormParam_Ex(); 126 122 $this->lfInitParam($objFormParam, $arrCSVFrame); 127 128 $this->max_upload_csv_size = SC_Utils_Ex::getUnitDataSize(CSV_SIZE);129 123 130 124 $objFormParam->setHtmlDispNameArray(); … … 148 142 * @return void 149 143 */ 150 function addRowResult($line_count, $message) 151 { 144 function addRowResult($line_count, $message) { 152 145 $this->arrRowResult[] = $line_count . '行目:' . $message; 153 146 } … … 160 153 * @return void 161 154 */ 162 function addRowErr($line_count, $message) 163 { 155 function addRowErr($line_count, $message) { 164 156 $this->arrRowErr[] = $line_count . '行目:' . $message; 165 157 } 166 158 167 159 /** 168 * CSVファイルを読み込んで、保存処理を行う169 *170 * @param $objFormParam171 * @param $fp CSVファイルポインタ172 * @param $objQuery 保存を行うためのクエリ(指定がない場合、テストのみを行う)173 * @return boolean errFlag. 読み込みに失敗した場合true174 */175 function lfReadCSVFile(&$objFormParam, &$fp, $objQuery = null)176 {177 $dry_run = ($objQuery===null) ? true : false;178 // 登録対象の列数179 $col_max_count = $objFormParam->getCount();180 // 行数181 $line_count = 0;182 // 処理に失敗した場合にtrue183 $errFlag = false;184 185 while (!feof($fp)) {186 $arrCSV = fgetcsv($fp, CSV_LINE_MAX);187 188 // 行カウント189 $line_count++;190 // ヘッダ行はスキップ191 if ($line_count == 1) {192 continue;193 }194 // 空行はスキップ195 if (empty($arrCSV)) {196 continue;197 }198 // 列数が多すぎる場合はエラー、列数が少ない場合は未設定として配列を補う199 $col_count = count($arrCSV);200 if ($col_count > $col_max_count) {201 $this->addRowErr($line_count, '※ 項目数が' . $col_count . '個検出されました。項目数は' . $col_max_count . '個になります。');202 $errFlag = true;203 break;204 } elseif ($col_count < $col_max_count) {205 $arrCSV = array_pad($arrCSV, $col_max_count, "");206 if (!$dry_run) {207 $this->addRowResult($line_count, ($col_count + 1) . "項目以降を空欄として読み込みました");208 }209 }210 211 // シーケンス配列を格納する。212 $objFormParam->setParam($arrCSV, true);213 $arrRet = $objFormParam->getHashArray();214 $objFormParam->setParam($arrRet);215 // 入力値の変換216 $objFormParam->convParam();217 218 // <br>なしでエラー取得する。219 $arrCSVErr = $this->lfCheckError($objFormParam);220 if (count($arrCSVErr) > 0) {221 foreach ($arrCSVErr as $err) {222 $this->addRowErr($line_count, $err);223 }224 $errFlag = true;225 break;226 }227 228 if (!$dry_run) {229 $this->lfRegistProduct($objQuery, $line_count, $objFormParam);230 $arrParam = $objFormParam->getHashArray();231 232 $this->addRowResult($line_count, '商品ID:'.$arrParam['product_id'] . ' / 商品名:' . $arrParam['name']);233 }234 SC_Utils_Ex::extendTimeOut();235 }236 return $errFlag;237 }238 239 /**240 160 * CSVアップロードを実行します. 241 161 * 242 162 * @return void 243 163 */ 244 function doUploadCsv(&$objFormParam, &$objUpFile) 245 { 164 function doUploadCsv(&$objFormParam, &$objUpFile) { 246 165 // ファイルアップロードのチェック 247 166 $this->arrErr['csv_file'] = $objUpFile->makeTempFile('csv_file'); … … 271 190 $this->arrFormKeyList = $objFormParam->getKeyList(); 272 191 192 // 登録対象の列数 193 $col_max_count = $objFormParam->getCount(); 194 // 行数 195 $line_count = 0; 196 273 197 $objQuery =& SC_Query_Ex::getSingletonInstance(); 274 198 $objQuery->begin(); 275 199 276 // CSVからの読み込み、入力エラーチェック 277 $errFlag = $this->lfReadCSVFile($objFormParam, $fp); 278 if (!$errFlag) { 279 rewind($fp); 280 // CSVからの読み込み、保存 281 $errFlag = $this->lfReadCSVFile($objFormParam, $fp, $objQuery); 200 $errFlag = false; 201 $all_line_checked = false; 202 203 while (!feof($fp)) { 204 $arrCSV = fgetcsv($fp, CSV_LINE_MAX); 205 206 // 全行入力チェック後に、ファイルポインターを先頭に戻す 207 if (feof($fp) && !$all_line_checked) { 208 rewind($fp); 209 $line_count = 0; 210 $all_line_checked = true; 211 continue; 212 } 213 214 // 行カウント 215 $line_count++; 216 // ヘッダ行はスキップ 217 if ($line_count == 1) { 218 continue; 219 } 220 // 空行はスキップ 221 if (empty($arrCSV)) { 222 continue; 223 } 224 // 列数が異なる場合はエラー 225 $col_count = count($arrCSV); 226 if ($col_max_count != $col_count) { 227 $this->addRowErr($line_count, '※ 項目数が' . $col_count . '個検出されました。項目数は' . $col_max_count . '個になります。'); 228 $errFlag = true; 229 break; 230 } 231 // シーケンス配列を格納する。 232 $objFormParam->setParam($arrCSV, true); 233 $arrRet = $objFormParam->getHashArray(); 234 $objFormParam->setParam($arrRet); 235 // 入力値の変換 236 $objFormParam->convParam(); 237 // <br>なしでエラー取得する。 238 $arrCSVErr = $this->lfCheckError($objFormParam); 239 240 // 入力エラーチェック 241 if (count($arrCSVErr) > 0) { 242 foreach ($arrCSVErr as $err) { 243 $this->addRowErr($line_count, $err); 244 } 245 $errFlag = true; 246 break; 247 } 248 249 if ($all_line_checked) { 250 $this->lfRegistProduct($objQuery, $line_count, $objFormParam); 251 $arrParam = $objFormParam->getHashArray(); 252 253 $this->addRowResult($line_count, '商品ID:'.$arrParam['product_id'] . ' / 商品名:' . $arrParam['name']); 254 } 255 SC_Utils_Ex::extendTimeOut(); 282 256 } 283 257 … … 304 278 * @return void 305 279 */ 306 function destroy() 307 { 280 function destroy() { 308 281 parent::destroy(); 309 282 } … … 314 287 * @return void 315 288 */ 316 function lfInitFile(&$objUpFile) 317 { 289 function lfInitFile(&$objUpFile) { 318 290 $objUpFile->addFile('CSVファイル', 'csv_file', array('csv'), CSV_SIZE, true, 0, 0, false); 319 291 } … … 325 297 * @return void 326 298 */ 327 function lfInitParam(&$objFormParam, &$arrCSVFrame) 328 { 299 function lfInitParam(&$objFormParam, &$arrCSVFrame) { 329 300 // 固有の初期値調整 330 301 $arrCSVFrame = $this->lfSetParamDefaultValue($arrCSVFrame); … … 371 342 * @return void 372 343 */ 373 function lfCheckError(&$objFormParam) 374 { 344 function lfCheckError(&$objFormParam) { 375 345 // 入力データを渡す。 376 346 $arrRet = $objFormParam->getHashArray(); … … 393 363 * @return void 394 364 */ 395 function lfInitTableInfo() 396 { 365 function lfInitTableInfo() { 397 366 $objQuery =& SC_Query_Ex::getSingletonInstance(); 398 367 $this->arrProductColumn = $objQuery->listTableFields('dtb_products'); … … 409 378 * @return void 410 379 */ 411 function lfRegistProduct($objQuery, $line = '', &$objFormParam) 412 { 380 function lfRegistProduct($objQuery, $line = '', &$objFormParam) { 413 381 $objProduct = new SC_Product_Ex(); 414 382 // 登録データ対象取得 415 383 $arrList = $objFormParam->getHashArray(); 416 417 384 // 登録時間を生成(DBのCURRENT_TIMESTAMPだとcommitした際、すべて同一の時間になってしまう) 418 385 $arrList['update_date'] = $this->lfGetDbFormatTimeWithLine($line); … … 480 447 * @return void 481 448 */ 482 function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) 483 { 449 function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) { 484 450 $objProduct = new SC_Product_Ex(); 485 486 // FIXME: dtb_csvテーブルの中で古いカラム名(右辺)が設定されている。sfArrayIntersectKeysでフィルタされてしまうので、名称を変更する必要がある487 if (array_key_exists('classcategory_id', $arrList) && $arrList['classcategory_id'] != '') {488 $arrList['classcategory_id1'] = $arrList['classcategory_id'];489 }490 if (array_key_exists('parent_classcategory_id', $arrList) && $arrList['classcategory_id'] != '') {491 $arrList['classcategory_id2'] = $arrList['parent_classcategory_id'];492 }493 494 451 // 商品規格登録情報を生成する。 495 452 // 商品規格テーブルのカラムに存在しているもののうち、Form投入設定されていないデータは上書きしない。 496 453 $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $this->arrProductClassColumn); 497 498 // 商品IDが設定されており、規格IDが設定されていなければ、既存の規格ID取得を試みる(product_class_idは必須入力項目ではない)499 if ($product_class_id == '' && $product_id != '') {500 $product_class_id = SC_Utils_Ex::sfGetProductClassId($product_id, $sqlval['classcategory_id1'], $sqlval['classcategory_id2']);501 $sqlval['product_class_id'] = $product_class_id;502 }503 454 504 455 if ($product_class_id == '') { … … 532 483 * @return void 533 484 */ 534 function lfRegistReccomendProducts($objQuery, $arrList, $product_id) 535 { 485 function lfRegistReccomendProducts($objQuery, $arrList, $product_id) { 536 486 $objQuery->delete('dtb_recommend_products', 'product_id = ?', array($product_id)); 537 487 for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { … … 561 511 * @return array $arrCSVFrame CSV構造配列 562 512 */ 563 function lfSetParamDefaultValue(&$arrCSVFrame) 564 { 513 function lfSetParamDefaultValue(&$arrCSVFrame) { 565 514 foreach ($arrCSVFrame as $key => $val) { 566 515 switch ($val['col']) { … … 592 541 * @return $sqlval 登録情報配列 593 542 */ 594 function lfSetProductDefaultData(&$sqlval) 595 { 543 function lfSetProductDefaultData(&$sqlval) { 596 544 //新規登録時のみ設定する項目 597 545 if ($sqlval['product_id'] == '') { … … 617 565 * @return $sqlval 登録情報配列 618 566 */ 619 function lfSetProductClassDefaultData(&$sqlval, $upload_flg) 620 { 567 function lfSetProductClassDefaultData(&$sqlval, $upload_flg) { 621 568 //新規登録時のみ設定する項目 622 569 if ($sqlval['product_class_id'] == '') { … … 637 584 638 585 // 在庫無制限フラグ列を利用する場合、 639 if (array_key_exists('stock_unlimited', $sqlval) and $sqlval['stock_unlimited'] != '') {586 if (array_key_exists('stock_unlimited', $sqlval)) { 640 587 // 在庫無制限フラグ = 無制限の場合、 641 588 if ($sqlval['stock_unlimited'] == UNLIMITED_FLG_UNLIMITED) { … … 669 616 * @return array エラー配列 670 617 */ 671 function lfCheckErrorDetail($item, $arrErr) 672 { 618 function lfCheckErrorDetail($item, $arrErr) { 673 619 // 規格IDの存在チェック 674 620 // FIXME 規格分類ID自体のが有効かを主眼においたチェックをすべきと感じる。 … … 688 634 $arrErr['product_class_id'] = '※ 指定の商品IDと商品規格IDの組合せは正しくありません。'; 689 635 } 690 691 // product_class_idは(product_id, classcategory_id1, classcategory_id2)に対して一意。既に異なるproduct_class_idが存在した場合はエラー 692 $classcategory_id1 = $item['classcategory_id'] ? $item['classcategory_id'] : 0; 693 $classcategory_id2 = $item['parent_classcategory_id'] ? $item['parent_classcategory_id'] : 0; 694 $product_class_id = SC_Utils_Ex::sfGetProductClassId($item['product_id'], $classcategory_id1, $classcategory_id2); 695 if ($product_class_id && $product_class_id != $item['product_class_id']) { 696 $arrErr['product_class_id'] = '※ 指定の商品ID/規格分類と、商品規格IDの組合せは正しくありません。'; 697 } 698 } 636 } 699 637 } 700 638 // 表示ステータスの存在チェック … … 764 702 // ダウンロード商品チェック 765 703 if (array_search('product_type_id', $this->arrFormKeyList) !== FALSE 766 && $item['product_type_id'] != PRODUCT_TYPE_DOWNLOAD704 && $item['product_type_id'] == PRODUCT_TYPE_NORMAL 767 705 ) { 768 706 //実商品の場合 769 707 if ($item['down_filename'] != '') { 770 $arrErr['down_filename'] = '※ ダウンロード商品ではない場合、ダウンロードファイル名は入力できません。';708 $arrErr['down_filename'] = '※ 実商品の場合はダウンロードファイル名は入力できません。'; 771 709 } 772 710 if ($item['down_realfilename'] != '') { 773 $arrErr['down_realfilename'] = '※ ダウンロード商品ではない場合、ダウンロード商品用ファイルアップロードは入力できません。';711 $arrErr['down_realfilename'] = '※ 実商品の場合はダウンロード商品用ファイルアップロードは入力できません。'; 774 712 } 775 713 } elseif (array_search('product_type_id', $this->arrFormKeyList) !== FALSE … … 796 734 * @return string $time DB保存用の時間文字列 797 735 */ 798 function lfGetDbFormatTimeWithLine($line_no = '') 799 { 736 function lfGetDbFormatTimeWithLine($line_no = '') { 800 737 $time = date('Y-m-d H:i:s'); 801 738 // 秒以下を生成 … … 816 753 * @return boolean true:有効なデータがある false:有効ではない 817 754 */ 818 function lfIsArrayRecordMulti($arr, $keyname, $item, $delimiter = ',') 819 { 755 function lfIsArrayRecordMulti($arr, $keyname, $item, $delimiter = ',') { 820 756 if (array_search($keyname, $this->arrFormKeyList) === FALSE) { 821 757 return true; … … 848 784 * @return boolean true:有効なデータがある false:有効ではない 849 785 */ 850 function lfIsDbRecordMulti($table, $tblkey, $keyname, $item, $delimiter = ',') 851 { 786 function lfIsDbRecordMulti($table, $tblkey, $keyname, $item, $delimiter = ',') { 852 787 if (array_search($keyname, $this->arrFormKeyList) === FALSE) { 853 788 return true; … … 880 815 * @return boolean true:有効なデータがある false:有効ではない 881 816 */ 882 function lfIsDbRecord($table, $keyname, $item) 883 { 817 function lfIsDbRecord($table, $keyname, $item) { 884 818 if (array_search($keyname, $this->arrFormKeyList) !== FALSE //入力対象である 885 819 && $item[$keyname] != '' // 空ではない … … 899 833 * @return boolean true:有効なデータがある false:有効ではない 900 834 */ 901 function lfIsArrayRecord($arr, $keyname, $item) 902 { 835 function lfIsArrayRecord($arr, $keyname, $item) { 903 836 if (array_search($keyname, $this->arrFormKeyList) !== FALSE //入力対象である 904 837 && $item[$keyname] != '' // 空ではない
Note: See TracChangeset
for help on using the changeset viewer.