Changeset 20733


Ignore:
Timestamp:
2011/03/20 04:00:50 (13 years ago)
Author:
AMUAMU
Message:

#870 (CSVアップロードにおいて、CSV項目の種類・数を自由に変更出来る機能) カテゴリCSVの修正

Location:
branches/version-2_5-dev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/pages/admin/products/LC_Page_Admin_Products_UploadCSVCategory.php

    r20540 r20733  
    2424// {{{ requires 
    2525require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; 
     26require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_CSV_Ex.php'; 
    2627 
    2728/** 
     
    3637class LC_Page_Admin_Products_UploadCSVCategory extends LC_Page_Admin_Ex { 
    3738 
     39    // {{{ properties 
     40    /** エラー情報 **/ 
     41    var $arrErr; 
     42 
     43    /** 表示用項目 **/ 
     44    var $arrTitle; 
     45 
     46    /** 結果行情報 **/ 
     47    var $arrRowResult; 
     48 
     49    /** エラー行情報 **/ 
     50    var $arrRowErr; 
     51 
     52    /** TAGエラーチェックフィールド情報 */ 
     53    var $arrTagCheckItem; 
     54 
     55    /** テーブルカラム情報 (登録処理用) **/ 
     56    var $arrRegistColumn; 
     57 
     58    /** 登録フォームカラム情報 **/ 
     59    var $arrFormKeyList; 
     60 
    3861    // }}} 
    3962    // {{{ functions 
    40  
    41     var $arrErr; 
    42  
    43     var $arrTitle; 
    44  
    45     var $arrRowResult; 
    46  
    47     var $arrRowErr; 
    4863 
    4964    /** 
     
    5974        $this->tpl_subno    = 'upload_csv_category'; 
    6075        $this->tpl_subtitle = 'カテゴリ登録CSV'; 
     76        $this->csv_id = '5'; 
     77 
     78        $masterData = new SC_DB_MasterData_Ex(); 
     79        $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag"); 
     80        $this->arrTagCheckItem = array(); 
    6181    } 
    6282 
     
    7797     */ 
    7898    function action() { 
    79         $objDb        = new SC_Helper_DB_Ex(); 
    80         $objUpFile    = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); 
     99        // CSV管理ヘルパー 
     100        $objCSV = new SC_Helper_CSV_Ex(); 
     101        // CSV構造読み込み 
     102        $arrCSVFrame = $objCSV->sfGetCsvOutput($this->csv_id); 
     103 
     104        // CSV構造がインポート可能かのチェック 
     105        if(!$objCSV->sfIsImportCSVFrame($arrCSVFrame) ) { 
     106            // 無効なフォーマットなので初期状態に強制変更 
     107            $arrCSVFrame = $objCSV->sfGetCsvOutput($this->csv_id, '', array(), 'no'); 
     108            $this->tpl_is_format_default = true; 
     109        } 
     110        // CSV構造は更新可能なフォーマットかのフラグ取得 
     111        $this->tpl_is_update = $objCSV->sfIsUpdateCSVFrame($arrCSVFrame); 
     112 
     113        // CSVファイルアップロード情報の初期化 
     114        $objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); 
     115        $this->lfInitFile($objUpFile); 
     116 
     117        // パラメータ情報の初期化 
    81118        $objFormParam = new SC_FormParam_Ex(); 
    82  
    83         // ファイルオブジェクト初期化 
    84         $this->initFile($objUpFile); 
    85  
    86         // 入力パラメータ初期化 
    87         $this->initParam($objFormParam); 
     119        $this->lfInitParam($objFormParam, $arrCSVFrame); 
     120 
    88121        $objFormParam->setHtmlDispNameArray(); 
    89122        $this->arrTitle = $objFormParam->getHtmlDispNameArray(); 
    90123 
    91         switch ($this->getMode()) { 
     124        switch($this->getMode()) { 
    92125        case 'csv_upload': 
    93             $this->doUploadCsv($objFormParam, $objUpFile, $objDb); 
    94         break; 
     126            $this->doUploadCsv($objFormParam, $objUpFile); 
     127            break; 
    95128        default: 
    96         } 
     129            break; 
     130        } 
     131    } 
     132 
     133    /** 
     134     * 登録/編集結果のメッセージをプロパティへ追加する 
     135     * 
     136     * @param integer $line_count 行数 
     137     * @param stirng $message メッセージ 
     138     * @return void 
     139     */ 
     140    function addRowResult($line_count, $message) { 
     141        $this->arrRowResult[] = $line_count . "行目:" . $message; 
     142    } 
     143 
     144    /** 
     145     * 登録/編集結果のエラーメッセージをプロパティへ追加する 
     146     * 
     147     * @param integer $line_count 行数 
     148     * @param stirng $message メッセージ 
     149     * @return void 
     150     */ 
     151    function addRowErr($line_count, $message) { 
     152        $this->arrRowErr[] = $line_count . "行目:" . $message; 
    97153    } 
    98154 
     
    105161     * @return void 
    106162     */ 
    107     function doUploadCsv(&$objFormParam, &$objUpFile, &$objDb) { 
     163    function doUploadCsv(&$objFormParam, &$objUpFile) { 
    108164        // ファイルアップロードのチェック 
    109165        $objUpFile->makeTempFile('csv_file'); 
     
    113169            return; 
    114170        } 
    115  
    116171        // 一時ファイル名の取得 
    117172        $filepath = $objUpFile->getTempFilePath('csv_file'); 
     
    125180        } 
    126181 
     182        // 登録先テーブル カラム情報の初期化 
     183        $this->lfInitTableInfo(); 
     184 
     185        // 登録フォーム カラム情報 
     186        $this->arrFormKeyList = $objFormParam->getKeyList(); 
     187 
    127188        // 登録対象の列数 
    128189        $col_max_count = $objFormParam->getCount(); 
     
    130191        $line_count = 0; 
    131192 
    132         $objQuery = SC_Query_Ex::getSingletonInstance(); 
     193        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    133194        $objQuery->begin(); 
    134195 
    135         $errFlg = false; 
     196        $errFlag = false; 
    136197 
    137198        while (!feof($fp)) { 
    138             $arrRow = fgetcsv($fp, CSV_LINE_MAX); 
     199            $arrCSV = fgetcsv($fp, CSV_LINE_MAX); 
     200            // 行カウント 
    139201            $line_count++; 
    140  
    141202            // ヘッダ行はスキップ 
    142203            if ($line_count == 1) { 
     
    144205            } 
    145206            // 空行はスキップ 
    146             if (empty($arrRow)) { 
     207            if (empty($arrCSV)) { 
    147208                continue; 
    148209            } 
    149210            // 列数が異なる場合はエラー 
    150             $col_count = count($arrRow); 
     211            $col_count = count($arrCSV); 
    151212            if ($col_max_count != $col_count) { 
    152                 $errFlg = true; 
    153213                $this->addRowErr($line_count, "※ 項目数が" . $col_count . "個検出されました。項目数は" . $col_max_count . "個になります。"); 
     214                $errFlag = true; 
    154215                break; 
    155216            } 
    156             // 数値インデックスから, カラム名 => 値の連想配列へ変換 
    157             $objFormParam->setParam($arrRow, true); 
    158             $arrRow = $objFormParam->getHashArray(); 
    159             $objFormParam->setParam($arrRow); 
     217            // シーケンス配列を格納する。 
     218            $objFormParam->setParam($arrCSV, true); 
     219            $arrRet = $objFormParam->getHashArray(); 
     220            $objFormParam->setParam($arrRet); 
     221            // 入力値の変換 
    160222            $objFormParam->convParam(); 
    161             // 入力項目チェック 
    162             $arrErr = $objFormParam->checkError(); 
    163             if (count($arrErr) > 0) { 
    164                 foreach ($arrErr as $err) { 
     223            // <br>なしでエラー取得する。 
     224            $arrCSVErr = $this->lfCheckError($objFormParam); 
     225 
     226            // 入力エラーチェック 
     227            if (count($arrCSVErr) > 0) { 
     228                foreach ($arrCSVErr as $err) { 
    165229                    $this->addRowErr($line_count, $err); 
    166230                } 
    167                 $errFlg = true; 
     231                $errFlag = true; 
    168232                break; 
    169233            } 
    170234 
    171             // 親カテゴリIDがない場合はルートのカテゴリIDをセット 
    172             if ($arrRow['parent_category_id'] == '') { 
    173                 $arrRow['parent_category_id'] = 0; 
    174             } 
    175  
    176             // 親カテゴリIDの存在チェック 
    177             $count = $objQuery->count("dtb_category", "category_id = ?", array($arrRow['parent_category_id'])); 
    178             if ($arrRow['parent_category_id'] != 0 && $count == 0) { 
    179                 $errFlg = true; 
    180                 $this->addRowErr($line_count, "指定の親カテゴリID(" . $arrRow['parent_category_id'] . ")は、存在しません。"); 
    181                 break; 
    182             } 
    183  
    184             $count = $objQuery->count("dtb_category", "category_id = ?", array($arrRow['category_id'])); 
    185  
    186             // 編集 
    187             if ($count > 0) { 
    188                 // 重複チェック 
    189                 $where = "parent_category_id = ? AND category_id <> ? AND category_name = ?"; 
    190                 $count = $objQuery->count("dtb_category", 
    191                                 $where, 
    192                                 array($arrRow['parent_category_id'], 
    193                                       $arrRow['category_id'], 
    194                                       $arrRow['category_name'])); 
    195                 if ($count > 0) { 
    196                     $errFlg = true; 
    197                     $this->addRowErr($line_count, "既に同じ内容の登録が存在します。"); 
    198                     break; 
    199                 } 
    200  
    201                 // カテゴリ更新 
    202                 $arrCategory = array(); 
    203                 $arrCategory['category_name'] = $arrRow['category_name']; 
    204                 $arrCategory['update_date'] = 'NOW()'; 
    205                 $where = "category_id = ?"; 
    206                 $objQuery->update("dtb_category", $arrCategory, $where, array($arrRow['category_id'])); 
    207  
    208                 $message = "[更新] カテゴリID: " . $arrRow['category_id'] . " カテゴリ名 : " . $arrRow['category_name']; 
    209                 $this->addRowResult($line_count, $message); 
    210             // 登録 
    211             } else { 
    212                 // 登録数上限チェック 
    213                 $where = "del_flg = 0"; 
    214                 $count = $objQuery->count("dtb_category", $where); 
    215                 if ($count >= CATEGORY_MAX) { 
    216                     $errFlg = true; 
    217                     $this->addRowErr($line_count, "カテゴリの登録最大数を超えました。"); 
    218                     break; 
    219                 } 
    220                 // 階層上限チェック 
    221                 if ($this->isOverLevel($arrRow['parent_category_id'])) { 
    222                     $errFlg = true; 
    223                     $this->addRowErr($line_count, LEVEL_MAX . "階層以上の登録はできません。"); 
    224                     break; 
    225                 } 
    226                 // 重複チェック 
    227                 $where = "parent_category_id = ? AND category_name = ?"; 
    228                 $count = $objQuery->count("dtb_category", 
    229                                 $where, 
    230                                 array($arrRow['parent_category_id'], 
    231                                       $arrRow['category_name'])); 
    232                 if ($count > 0) { 
    233                     $errFlg = true; 
    234                     $this->addRowErr($line_count, "既に同じ内容の登録が存在します。"); 
    235                     break; 
    236                 } 
    237                 // カテゴリ登録 
    238                 $this->registerCategory($arrRow['parent_category_id'], 
    239                                         $arrRow['category_name'], 
    240                                         $_SESSION['member_id']); 
    241  
    242                 $message = "[登録] カテゴリ名 : " . $arrRow['category_name']; 
    243                 $this->addRowResult($line_count, $message); 
    244             } 
    245         } 
    246  
    247         fclose($fp); 
     235            $category_id = $this->lfRegistCategory($objQuery, $line_count, $objFormParam); 
     236            $this->addRowResult($line_count, "カテゴリID:".$category_id . " / カテゴリ名:" . $objFormParam->getValue('category_name')); 
     237        } 
    248238 
    249239        // 実行結果画面を表示 
    250240        $this->tpl_mainpage = 'products/upload_csv_category_complete.tpl'; 
     241 
     242        fclose($fp); 
    251243 
    252244        if ($errFlg) { 
     
    258250 
    259251        // カテゴリ件数を更新 
    260         $objDb->sfCountCategory($objQuery); 
    261         $objDb->sfCountMaker($objQuery); 
    262     } 
    263  
    264     /** 
    265      * 登録/編集結果のメッセージをプロパティへ追加する 
    266      * 
    267      * @param integer $line_count 行数 
    268      * @param stirng $message メッセージ 
    269      * @return void 
    270      */ 
    271     function addRowResult($line_count, $message) { 
    272         $this->arrRowResult[] = $line_count . "行目:" . $message; 
    273     } 
    274  
    275     /** 
    276      * 登録/編集結果のエラーメッセージをプロパティへ追加する 
    277      * 
    278      * @param integer $line_count 行数 
    279      * @param stirng $message メッセージ 
    280      * @return void 
    281      */ 
    282     function addRowErr($line_count, $message) { 
    283         $this->arrRowErr[] = $line_count . "行目:" . $message; 
    284     } 
    285  
    286     /** 
    287      * カテゴリの階層が上限を超えているかを判定する 
    288      * 
    289      * @param integer 親カテゴリID 
    290      * @param 超えている場合 true 
    291      */ 
    292     function isOverLevel($parent_category_id) { 
    293         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    294         $level = $objQuery->get('level', "dtb_category", "category_id = ?", array($parent_category_id)); 
    295         return $level >= LEVEL_MAX; 
     252        SC_Helper_DB_EX::sfCountCategory($objQuery); 
     253        return; 
    296254    } 
    297255 
     
    310268     * @return void 
    311269     */ 
    312     function initFile(&$objUpFile) { 
     270    function lfInitFile(&$objUpFile) { 
    313271        $objUpFile->addFile("CSVファイル", 'csv_file', array('csv'), CSV_SIZE, true, 0, 0, false); 
    314272    } 
     
    317275     * 入力情報の初期化を行う. 
    318276     * 
    319      * @param SC_FormParam $objFormParam  
    320      * @return void 
    321      */ 
    322     function initParam(&$objFormParam) { 
    323         $objFormParam->addParam("カテゴリID","category_id",INT_LEN,'n',array("MAX_LENGTH_CHECK","NUM_CHECK")); 
    324         $objFormParam->addParam("カテゴリ名","category_name",STEXT_LEN,'KVa',array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); 
    325         $objFormParam->addParam("親カテゴリID","parent_category_id",INT_LEN,'n',array("MAX_LENGTH_CHECK","NUM_CHECK")); 
     277     * @param array CSV構造設定配列 
     278     * @return void 
     279     */ 
     280    function lfInitParam(&$objFormParam, &$arrCSVFrame) { 
     281        // 固有の初期値調整 
     282        $arrCSVFrame = $this->lfSetParamDefaultValue($arrCSVFrame); 
     283        // CSV項目毎の処理 
     284        foreach($arrCSVFrame as $item) { 
     285            if($item['status'] == CSV_COLUMN_STATUS_FLG_DISABLE) continue; 
     286            //サブクエリ構造の場合は AS名 を使用 
     287            if(preg_match_all('/\(.+\) as (.+)$/i', $item['col'], $match, PREG_SET_ORDER)) { 
     288                $col = $match[0][1]; 
     289            }else{ 
     290                $col = $item['col']; 
     291            } 
     292            // HTML_TAG_CHECKは別途実行なので除去し、別保存しておく 
     293            if(strpos(strtoupper($item['error_check_types']), 'HTML_TAG_CHECK') !== FALSE) { 
     294                $this->arrTagCheckItem[] = $item; 
     295                $error_check_types = str_replace('HTML_TAG_CHECK', '', $item['error_check_types']); 
     296            }else{ 
     297                $error_check_types = $item['error_check_types']; 
     298            } 
     299            $arrErrorCheckTypes = explode(',', $error_check_types); 
     300            foreach($arrErrorCheckTypes as $key => $val) { 
     301                if(trim($val) == "") { 
     302                    unset($arrErrorCheckTypes[$key]); 
     303                }else{ 
     304                    $arrErrorCheckTypes[$key] = trim($val); 
     305                } 
     306            } 
     307            // パラメーター登録 
     308            $objFormParam->addParam( 
     309                    $item['disp_name'] 
     310                    , $col 
     311                    , constant($item['size_const_type']) 
     312                    , $item['mb_convert_kana_option'] 
     313                    , $arrErrorCheckTypes 
     314                    , $item['default'] 
     315                    , ($item['rw_flg'] != CSV_COLUMN_RW_FLG_READ_ONLY) ? true : false 
     316                    ); 
     317        } 
     318    }  
     319 
     320    /** 
     321     * 入力チェックを行う. 
     322     * 
     323     * @return void 
     324     */ 
     325    function lfCheckError(&$objFormParam) { 
     326        // 入力データを渡す。 
     327        $arrRet =  $objFormParam->getHashArray(); 
     328        $objErr = new SC_CheckError_Ex($arrRet); 
     329        $objErr->arrErr = $objFormParam->checkError(false); 
     330        // HTMLタグチェックの実行 
     331        foreach($this->arrTagCheckItem as $item) { 
     332            $objErr->doFunc(array( $item['disp_name'], $item['col'], $this->arrAllowedTag), array("HTML_TAG_CHECK")); 
     333        } 
     334        // このフォーム特有の複雑系のエラーチェックを行う 
     335        if(count($objErr->arrErr) == 0) { 
     336            $objErr->arrErr = $this->lfCheckErrorDetail($arrRet, $objErr->arrErr); 
     337        } 
     338        return $objErr->arrErr; 
     339    } 
     340 
     341    /** 
     342     * 保存先テーブル情報の初期化を行う. 
     343     * 
     344     * @return void 
     345     */ 
     346    function lfInitTableInfo() { 
     347        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     348        $this->arrRegistColumn = $objQuery->listTableFields('dtb_category'); 
     349    } 
     350 
     351    /** 
     352     * カテゴリ登録を行う. 
     353     * 
     354     * FIXME: 登録の実処理自体は、LC_Page_Admin_Products_Categoryと共通化して欲しい。 
     355     * 
     356     * @param SC_Query $objQuery SC_Queryインスタンス 
     357     * @param string|integer $line 処理中の行数 
     358     * @return integer カテゴリID 
     359     */ 
     360    function lfRegistCategory($objQuery, $line, &$objFormParam) { 
     361        // 登録データ対象取得 
     362        $arrList = $objFormParam->getHashArray(); 
     363        // 登録時間を生成(DBのnow()だとcommitした際、すべて同一の時間になってしまう) 
     364        $arrList['update_date'] = $this->lfGetDbFormatTimeWithLine($line); 
     365 
     366        // 登録情報を生成する。 
     367        // テーブルのカラムに存在しているもののうち、Form投入設定されていないデータは上書きしない。 
     368        $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $this->arrRegistColumn); 
     369 
     370        // 必須入力では無い項目だが、空文字では問題のある特殊なカラム値の初期値設定 
     371        $sqlval = $this->lfSetCategoryDefaultData($sqlval); 
     372 
     373        if($sqlval['category_id'] != "") { 
     374            // UPDATEの実行 
     375            $where = "category_id = ?"; 
     376            $objQuery->update("dtb_category", $sqlval, $where, array($sqlval['category_id'])); 
     377            $category_id = $sqlval['category_id']; 
     378            // TODO: 削除時処理 
     379        }else{ 
     380            // 新規登録 
     381            $category_id = $this->registerCategory($sqlval['parent_category_id'], 
     382                                        $sqlval['category_name'], 
     383                                        $_SESSION['member_id']); 
     384        } 
     385        return $category_id; 
     386    } 
     387 
     388    /** 
     389     * 初期値の設定 
     390     * 
     391     * @param array $arrCSVFrame CSV構造配列 
     392     * @return array $arrCSVFrame CSV構造配列 
     393     */ 
     394    function lfSetParamDefaultValue(&$arrCSVFrame) { 
     395        foreach($arrCSVFrame as $key => $val) { 
     396            switch($val['col']) { 
     397                case 'parent_category_id': 
     398                    $arrCSVFrame[$key]['default'] = '0'; 
     399                    break; 
     400                case 'del_flg': 
     401                    $arrCSVFrame[$key]['default'] = '0'; 
     402                    break; 
     403                default: 
     404                    break; 
     405            } 
     406        } 
     407        return $arrCSVFrame; 
     408    } 
     409 
     410    /** 
     411     * データ登録前に特殊な値の持ち方をする部分のデータ部分の初期値補正を行う 
     412     * 
     413     * @param array $sqlval 商品登録情報配列 
     414     * @return $sqlval 登録情報配列 
     415     */ 
     416    function lfSetCategoryDefaultData(&$sqlval) { 
     417        if($sqlval['del_flg'] == ""){ 
     418            $sqlval['del_flg'] = '0'; //有効 
     419        } 
     420        if($sqlval['creator_id'] == "") { 
     421            $sqlval['creator_id'] = $_SESSION['member_id']; 
     422        } 
     423        if($sqlval['parent_category_id'] == "") { 
     424            $sqlval['parent_category_id'] = (string)"0"; 
     425        } 
     426        return $sqlval; 
     427    } 
     428 
     429    /** 
     430     * このフォーム特有の複雑な入力チェックを行う. 
     431     * 
     432     * @param array 確認対象データ 
     433     * @param array エラー配列 
     434     * @return array エラー配列 
     435     */ 
     436    function lfCheckErrorDetail($item, $arrErr) { 
     437        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     438        // カテゴリIDの存在チェック 
     439        if(!$this->lfIsDbRecord('dtb_category', 'category_id', $item)) { 
     440            $arrErr['category_id'] = "※ 指定のカテゴリIDは、登録されていません。"; 
     441        } 
     442        // 親カテゴリIDの存在チェック 
     443        if(array_search('parent_category_id', $this->arrFormKeyList) !== FALSE 
     444                and $item['parent_category_id'] != "" 
     445                and $item['parent_category_id'] != "0" 
     446                and !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', array($item['parent_category_id'])) 
     447                ) { 
     448            $arrErr['parent_category_id'] = "※ 指定の親カテゴリID(" . $item['parent_category_id'] . ")は、存在しません。"; 
     449        } 
     450        // 削除フラグのチェック 
     451        if(array_search('del_flg', $this->arrFormKeyList) !== FALSE 
     452                and $item['del_flg'] != "") { 
     453            if(!($item['del_flg'] == "0" or $item['del_flg'] == "1")) { 
     454                $arrErr['del_flg'] = "※ 削除フラグは「0」(有効)、「1」(削除)のみが有効な値です。"; 
     455            } 
     456        } 
     457        // 重複チェック 同じカテゴリ内に同名の存在は許可されない 
     458        if(array_search('category_name', $this->arrFormKeyList) !== FALSE 
     459                and $item['category_name'] != "") { 
     460            $parent_category_id = $item['parent_category_id']; 
     461            if($parent_category_id == '') { 
     462                $parent_category_id = (string)'0'; 
     463            } 
     464            $where = "parent_category_id = ? AND category_id <> ? AND category_name = ?"; 
     465            $count = $objQuery->count('dtb_category', 
     466                        $where, 
     467                        array($parent_category_id, 
     468                                $item['category_id'], 
     469                                $item['category_name'])); 
     470            if($count > 0) { 
     471                $arrErr['category_name'] = "※ 既に同名のカテゴリが存在します。"; 
     472            } 
     473        } 
     474        // 登録数上限チェック 
     475        $where = "del_flg = 0"; 
     476        $count = $objQuery->count("dtb_category", $where); 
     477        if ($count >= CATEGORY_MAX) { 
     478            $item['category_name'] = "※ カテゴリの登録最大数を超えました。"; 
     479        } 
     480        // 階層上限チェック 
     481        if (array_search('parent_category_id', $this->arrFormKeyList) !== FALSE 
     482                and $item['parent_category_id'] != "") { 
     483            $level = $objQuery->get('level', "dtb_category", "category_id = ?", array($parent_category_id)); 
     484            if($level >= LEVEL_MAX) { 
     485                $arrErr['parent_category_id'] = "※ " . LEVEL_MAX . "階層以上の登録はできません。"; 
     486            } 
     487        } 
     488        return $arrErr; 
    326489    } 
    327490 
     
    332495     * @param string カテゴリ名 
    333496     * @param integer 作成者のID 
    334      * @return void 
     497     * @return integer カテゴリID 
    335498     */ 
    336499    function registerCategory($parent_category_id, $category_name, $creator_id) { 
     
    365528        $arrCategory['category_id'] = $objQuery->nextVal('dtb_category_category_id'); 
    366529        $objQuery->insert("dtb_category", $arrCategory); 
    367     } 
     530        return $arrCategory['category_id']; 
     531    } 
     532 
     533    /** 
     534     * 指定された行番号をmicrotimeに付与してDB保存用の時間を生成する。 
     535     * トランザクション内のnow()は全てcommit()時の時間に統一されてしまう為。 
     536     * 
     537     * @param string $line_no 行番号 
     538     * @return string $time DB保存用の時間文字列 
     539     */ 
     540    function lfGetDbFormatTimeWithLine($line_no = '') { 
     541        $time = date("Y-m-d H:i:s"); 
     542        // 秒以下を生成 
     543        if($line_no != '') { 
     544            $microtime = sprintf("%06d", $line_no); 
     545            $time .= ".$microtime"; 
     546        } 
     547        return $time; 
     548    } 
     549 
     550    /** 
     551     * 指定されたキーと値の有効性のDB確認 
     552     * 
     553     * @param string $table テーブル名 
     554     * @param string $keyname キー名 
     555     * @param array  $item 入力データ配列 
     556     * @return boolean true:有効なデータがある false:有効ではない 
     557     */ 
     558    function lfIsDbRecord($table, $keyname, $item) { 
     559        if(array_search($keyname, $this->arrFormKeyList) !== FALSE  //入力対象である 
     560                and $item[$keyname] != ""   // 空ではない 
     561                and !SC_Helper_DB_EX::sfIsRecord($table, $keyname, (array)$item[$keyname]) //DBに存在するか 
     562                ) { 
     563            return false; 
     564        } 
     565        return true; 
     566    } 
     567 
    368568} 
  • branches/version-2_5-dev/html/install/sql/insert_data.sql

    r20707 r20733  
    292292INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types) VALUES (196, 5, 'category_name', 'カテゴリ名', 2, 1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'KVa', 'STEXT_LEN', 'SPTAB_CHECK,MAX_LENGTH_CHECK,EXIST_CHECK'); 
    293293INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types) VALUES (197, 5, 'parent_category_id', '親カテゴリID', 3, 1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'n', 'INT_LEN', 'NUM_CHECK,MAX_LENGTH_CHECK,EXIST_CHECK'); 
    294 INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types) VALUES (198, 5, 'level', '階層', 4, 1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'n', 'INT_LEN', 'NUM_CHECK,MAX_LENGTH_CHECK'); 
    295 INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types) VALUES (199, 5, 'rank', '表示ランク', 5, 1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'n', 'INT_LEN', 'NUM_CHECK,MAX_LENGTH_CHECK'); 
     294INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types) VALUES (198, 5, 'level', '階層', NULL, 2, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'n', 'INT_LEN', 'NUM_CHECK,MAX_LENGTH_CHECK'); 
     295INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types) VALUES (199, 5, 'rank', '表示ランク', NULL, 2, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'n', 'INT_LEN', 'NUM_CHECK,MAX_LENGTH_CHECK'); 
     296INSERT INTO dtb_csv (no, csv_id, col, disp_name, rank, rw_flg, status, create_date, update_date, mb_convert_kana_option, size_const_type, error_check_types) VALUES (200, 5, 'del_flg', '削除フラグ', NULL, 1, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'n', 'INT_LEN', 'NUM_CHECK,MAX_LENGTH_CHECK'); 
    296297 
    297298INSERT INTO dtb_deliv (deliv_id, product_type_id, name, service_name, confirm_url, rank, status, del_flg, creator_id, create_date, update_date) VALUES (1, 1, 'サンプル業者', 'サンプル業者', NULL, 2, 1, 0, 2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP); 
Note: See TracChangeset for help on using the changeset viewer.