Ignore:
Timestamp:
2013/05/02 18:11:36 (11 years ago)
Author:
h_yoshimoto
Message:

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

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  
    3434 * FIXME 同一商品IDで商品規格違いを登録できない。(更新は可能) 
    3535 */ 
    36 class LC_Page_Admin_Products_UploadCSV extends LC_Page_Admin_Ex  
    37 { 
     36class LC_Page_Admin_Products_UploadCSV extends LC_Page_Admin_Ex { 
    3837 
    3938    // }}} 
     
    6160     * @return void 
    6261     */ 
    63     function init() 
    64     { 
     62    function init() { 
    6563        parent::init(); 
    6664        $this->tpl_mainpage = 'products/upload_csv.tpl'; 
     
    7674        $this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date'); 
    7775        $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'); 
    8078        $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); 
    8179        $this->arrAllowedTag = $masterData->getMasterData('mtb_allowed_tag'); 
     
    8886     * @return void 
    8987     */ 
    90     function process() 
    91     { 
     88    function process() { 
    9289        $this->action(); 
    9390        $this->sendResponse(); 
     
    9996     * @return void 
    10097     */ 
    101     function action() 
    102     { 
     98    function action() { 
    10399 
    104100        $this->objDb = new SC_Helper_DB_Ex(); 
     
    125121        $objFormParam = new SC_FormParam_Ex(); 
    126122        $this->lfInitParam($objFormParam, $arrCSVFrame); 
    127  
    128         $this->max_upload_csv_size = SC_Utils_Ex::getUnitDataSize(CSV_SIZE); 
    129123 
    130124        $objFormParam->setHtmlDispNameArray(); 
     
    148142     * @return void 
    149143     */ 
    150     function addRowResult($line_count, $message) 
    151     { 
     144    function addRowResult($line_count, $message) { 
    152145        $this->arrRowResult[] = $line_count . '行目:' . $message; 
    153146    } 
     
    160153     * @return void 
    161154     */ 
    162     function addRowErr($line_count, $message) 
    163     { 
     155    function addRowErr($line_count, $message) { 
    164156        $this->arrRowErr[] = $line_count . '行目:' . $message; 
    165157    } 
    166158 
    167159    /** 
    168      * CSVファイルを読み込んで、保存処理を行う 
    169      * 
    170      * @param $objFormParam 
    171      * @param $fp CSVファイルポインタ 
    172      * @param $objQuery 保存を行うためのクエリ(指定がない場合、テストのみを行う) 
    173      * @return boolean errFlag. 読み込みに失敗した場合true 
    174      */ 
    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         // 処理に失敗した場合にtrue 
    183         $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     /** 
    240160     * CSVアップロードを実行します. 
    241161     * 
    242162     * @return void 
    243163     */ 
    244     function doUploadCsv(&$objFormParam, &$objUpFile) 
    245     { 
     164    function doUploadCsv(&$objFormParam, &$objUpFile) { 
    246165        // ファイルアップロードのチェック 
    247166        $this->arrErr['csv_file'] = $objUpFile->makeTempFile('csv_file'); 
     
    271190        $this->arrFormKeyList = $objFormParam->getKeyList(); 
    272191 
     192        // 登録対象の列数 
     193        $col_max_count = $objFormParam->getCount(); 
     194        // 行数 
     195        $line_count = 0; 
     196 
    273197        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    274198        $objQuery->begin(); 
    275199 
    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(); 
    282256        } 
    283257 
     
    304278     * @return void 
    305279     */ 
    306     function destroy() 
    307     { 
     280    function destroy() { 
    308281        parent::destroy(); 
    309282    } 
     
    314287     * @return void 
    315288     */ 
    316     function lfInitFile(&$objUpFile) 
    317     { 
     289    function lfInitFile(&$objUpFile) { 
    318290        $objUpFile->addFile('CSVファイル', 'csv_file', array('csv'), CSV_SIZE, true, 0, 0, false); 
    319291    } 
     
    325297     * @return void 
    326298     */ 
    327     function lfInitParam(&$objFormParam, &$arrCSVFrame) 
    328     { 
     299    function lfInitParam(&$objFormParam, &$arrCSVFrame) { 
    329300        // 固有の初期値調整 
    330301        $arrCSVFrame = $this->lfSetParamDefaultValue($arrCSVFrame); 
     
    371342     * @return void 
    372343     */ 
    373     function lfCheckError(&$objFormParam) 
    374     { 
     344    function lfCheckError(&$objFormParam) { 
    375345        // 入力データを渡す。 
    376346        $arrRet =  $objFormParam->getHashArray(); 
     
    393363     * @return void 
    394364     */ 
    395     function lfInitTableInfo() 
    396     { 
     365    function lfInitTableInfo() { 
    397366        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    398367        $this->arrProductColumn = $objQuery->listTableFields('dtb_products'); 
     
    409378     * @return void 
    410379     */ 
    411     function lfRegistProduct($objQuery, $line = '', &$objFormParam) 
    412     { 
     380    function lfRegistProduct($objQuery, $line = '', &$objFormParam) { 
    413381        $objProduct = new SC_Product_Ex(); 
    414382        // 登録データ対象取得 
    415383        $arrList = $objFormParam->getHashArray(); 
    416  
    417384        // 登録時間を生成(DBのCURRENT_TIMESTAMPだとcommitした際、すべて同一の時間になってしまう) 
    418385        $arrList['update_date'] = $this->lfGetDbFormatTimeWithLine($line); 
     
    480447     * @return void 
    481448     */ 
    482     function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) 
    483     { 
     449    function lfRegistProductClass($objQuery, $arrList, $product_id, $product_class_id) { 
    484450        $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  
    494451        // 商品規格登録情報を生成する。 
    495452        // 商品規格テーブルのカラムに存在しているもののうち、Form投入設定されていないデータは上書きしない。 
    496453        $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         } 
    503454 
    504455        if ($product_class_id == '') { 
     
    532483     * @return void 
    533484     */ 
    534     function lfRegistReccomendProducts($objQuery, $arrList, $product_id) 
    535     { 
     485    function lfRegistReccomendProducts($objQuery, $arrList, $product_id) { 
    536486        $objQuery->delete('dtb_recommend_products', 'product_id = ?', array($product_id)); 
    537487        for ($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) { 
     
    561511     * @return array $arrCSVFrame CSV構造配列 
    562512     */ 
    563     function lfSetParamDefaultValue(&$arrCSVFrame) 
    564     { 
     513    function lfSetParamDefaultValue(&$arrCSVFrame) { 
    565514        foreach ($arrCSVFrame as $key => $val) { 
    566515            switch ($val['col']) { 
     
    592541     * @return $sqlval 登録情報配列 
    593542     */ 
    594     function lfSetProductDefaultData(&$sqlval) 
    595     { 
     543    function lfSetProductDefaultData(&$sqlval) { 
    596544        //新規登録時のみ設定する項目 
    597545        if ($sqlval['product_id'] == '') { 
     
    617565     * @return $sqlval 登録情報配列 
    618566     */ 
    619     function lfSetProductClassDefaultData(&$sqlval, $upload_flg) 
    620     { 
     567    function lfSetProductClassDefaultData(&$sqlval, $upload_flg) { 
    621568        //新規登録時のみ設定する項目 
    622569        if ($sqlval['product_class_id'] == '') { 
     
    637584 
    638585        // 在庫無制限フラグ列を利用する場合、 
    639         if (array_key_exists('stock_unlimited', $sqlval) and $sqlval['stock_unlimited'] != '') { 
     586        if (array_key_exists('stock_unlimited', $sqlval)) { 
    640587            // 在庫無制限フラグ = 無制限の場合、 
    641588            if ($sqlval['stock_unlimited'] == UNLIMITED_FLG_UNLIMITED) { 
     
    669616     * @return array エラー配列 
    670617     */ 
    671     function lfCheckErrorDetail($item, $arrErr) 
    672     { 
     618    function lfCheckErrorDetail($item, $arrErr) { 
    673619        // 規格IDの存在チェック 
    674620        // FIXME 規格分類ID自体のが有効かを主眼においたチェックをすべきと感じる。 
     
    688634                    $arrErr['product_class_id'] = '※ 指定の商品IDと商品規格IDの組合せは正しくありません。'; 
    689635                } 
    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            } 
    699637        } 
    700638        // 表示ステータスの存在チェック 
     
    764702        // ダウンロード商品チェック 
    765703        if (array_search('product_type_id', $this->arrFormKeyList) !== FALSE 
    766             && $item['product_type_id'] != PRODUCT_TYPE_DOWNLOAD 
     704            && $item['product_type_id'] == PRODUCT_TYPE_NORMAL 
    767705        ) { 
    768706            //実商品の場合 
    769707            if ($item['down_filename'] != '') { 
    770                 $arrErr['down_filename'] = '※ ダウンロード商品ではない場合、ダウンロードファイル名は入力できません。'; 
     708                $arrErr['down_filename'] = '※ 実商品の場合はダウンロードファイル名は入力できません。'; 
    771709            } 
    772710            if ($item['down_realfilename'] != '') { 
    773                 $arrErr['down_realfilename'] = '※ ダウンロード商品ではない場合、ダウンロード商品用ファイルアップロードは入力できません。'; 
     711                $arrErr['down_realfilename'] = '※ 実商品の場合はダウンロード商品用ファイルアップロードは入力できません。'; 
    774712            } 
    775713        } elseif (array_search('product_type_id', $this->arrFormKeyList) !== FALSE 
     
    796734     * @return string $time DB保存用の時間文字列 
    797735     */ 
    798     function lfGetDbFormatTimeWithLine($line_no = '') 
    799     { 
     736    function lfGetDbFormatTimeWithLine($line_no = '') { 
    800737        $time = date('Y-m-d H:i:s'); 
    801738        // 秒以下を生成 
     
    816753     * @return boolean true:有効なデータがある false:有効ではない 
    817754     */ 
    818     function lfIsArrayRecordMulti($arr, $keyname, $item, $delimiter = ',') 
    819     { 
     755    function lfIsArrayRecordMulti($arr, $keyname, $item, $delimiter = ',') { 
    820756        if (array_search($keyname, $this->arrFormKeyList) === FALSE) { 
    821757            return true; 
     
    848784     * @return boolean true:有効なデータがある false:有効ではない 
    849785     */ 
    850     function lfIsDbRecordMulti($table, $tblkey, $keyname, $item, $delimiter = ',') 
    851     { 
     786    function lfIsDbRecordMulti($table, $tblkey, $keyname, $item, $delimiter = ',') { 
    852787        if (array_search($keyname, $this->arrFormKeyList) === FALSE) { 
    853788            return true; 
     
    880815     * @return boolean true:有効なデータがある false:有効ではない 
    881816     */ 
    882     function lfIsDbRecord($table, $keyname, $item) 
    883     { 
     817    function lfIsDbRecord($table, $keyname, $item) { 
    884818        if (array_search($keyname, $this->arrFormKeyList) !== FALSE  //入力対象である 
    885819            && $item[$keyname] != ''   // 空ではない 
     
    899833     * @return boolean true:有効なデータがある false:有効ではない 
    900834     */ 
    901     function lfIsArrayRecord($arr, $keyname, $item) 
    902     { 
     835    function lfIsArrayRecord($arr, $keyname, $item) { 
    903836        if (array_search($keyname, $this->arrFormKeyList) !== FALSE //入力対象である 
    904837            && $item[$keyname] != '' // 空ではない 
Note: See TracChangeset for help on using the changeset viewer.