Ignore:
Timestamp:
2009/12/07 21:43:13 (14 years ago)
Author:
Seasoft
Message:
  • #519(SCUtils::sfInsertProductClass内のSQL文の見直し)の改修
  • メソッド移動 SC_Utils#sfInsertProductClass → LC_Page_Admin_Products_Product#lfInsertDummyProductClass
  • メソッド削除 LC_Page_Admin_Products_Product#lfCheckNonClass (SC_Helper_DB#sfHasProductClass でまかなう)
  • メソッド追加 SC_Helper_DB#sfHasProductClass
  • メソッド追加 SC_Utils#sfArrayIntersectKeys
  • 用語統一 (複製 ← コピー)
  • phpDocumentor 準拠コメント追加
Location:
branches/comu-ver2/data/class
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/class/helper/SC_Helper_DB.php

    r18380 r18435  
    19421942        } 
    19431943    } 
     1944 
     1945    /** 
     1946     * 商品規格を設定しているか 
     1947     * 
     1948     * @param integer $product_id 商品ID 
     1949     * @return bool 商品規格が存在する場合:true, それ以外:false 
     1950     */ 
     1951    function sfHasProductClass($product_id) { 
     1952        if (!SC_Utils_Ex::sfIsInt($product_id)) return false; 
     1953 
     1954        $objQuery  = new SC_Query(); 
     1955        $where = 'product_id = ? AND (classcategory_id1 <> 0 OR classcategory_id2 <> 0)'; 
     1956        $count = $objQuery->count('dtb_products_class', $where, array($product_id)); 
     1957 
     1958        return $count >= 1; 
     1959    } 
    19441960} 
    19451961?> 
  • branches/comu-ver2/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php

    r18415 r18435  
    9898 
    9999        // 規格の有り無し判定 
    100         $this->tpl_nonclass = $this->lfCheckNonClass($_POST['product_id']); 
     100        $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['product_id']); 
    101101 
    102102        // 検索パラメータの引き継ぎ 
     
    148148            case 'edit': 
    149149                if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){ 
    150                     $this->tpl_nonclass = $this->lfCheckNonClass($_POST['copy_product_id']); 
     150                    $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['copy_product_id']); 
    151151                } 
    152152 
     
    320320    function lfGetProduct($product_id) { 
    321321        $objQuery = new SC_Query(); 
     322        $objDb = new SC_Helper_DB_Ex(); 
     323 
    322324        $col = "*"; 
    323325        $table = "vw_products_nonclass AS noncls "; 
     
    332334        array($product_id)); 
    333335        //編集時に規格IDが変わってしまうのを防ぐために規格が登録されていなければ規格IDを取得する 
    334         if( $this->lfCheckNonClass($_POST['product_id']) ){ 
     336        if (!$objDb->sfHasProductClass($_POST['product_id'])) { 
    335337            $arrRet[0]['product_class_id'] = SC_Utils::sfGetProductClassId($product_id,"0","0"); 
    336338        } 
     
    433435        } 
    434436 
    435         if($arrList['product_id'] == "") { 
     437        // 新規登録(複製時を含む) 
     438        if ($arrList['product_id'] == "") { 
    436439            // product_id 取得(PostgreSQLの場合) 
    437440            if(DB_TYPE=='pgsql'){ 
     
    449452            } 
    450453 
     454            $arrList['product_id'] = $product_id; 
     455 
    451456            // カテゴリを更新 
    452457            $objDb->updateProductCategories($arrList['category_id'], $product_id); 
    453458 
    454             // コピー商品の場合には規格もコピーする 
     459            // 複製商品の場合には規格も複製する 
    455460            if($_POST["copy_product_id"] != "" and SC_Utils_Ex::sfIsInt($_POST["copy_product_id"])){ 
    456461 
    457462                if($this->tpl_nonclass) 
    458463                { 
    459                     //規格なしの場合、コピーは価格等の入力が発生しているため、その内容で追加登録を行う 
    460                     $arrList['product_id'] = $product_id; 
     464                    //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う 
    461465                    $this->lfCopyProductClass($arrList, $objQuery); 
    462466                } 
    463467                else 
    464468                { 
    465                     //規格がある場合のコピーは複製元の内容で追加登録を行う 
     469                    //規格がある場合の複製は複製元の内容で追加登録を行う 
    466470                    // dtb_products_class のカラムを取得 
    467471                    $dbFactory = SC_DB_DBFactory_Ex::getInstance(); 
     
    469473                    $arrColList_tmp = array_flip($arrColList); 
    470474 
    471                     // コピーしない列 
     475                    // 複製しない列 
    472476                    unset($arrColList[$arrColList_tmp["product_class_id"]]);     //規格ID 
    473477                    unset($arrColList[$arrColList_tmp["product_id"]]);           //商品ID 
     
    479483                } 
    480484            } 
    481         } else { 
     485        } 
     486        // 更新 
     487        else { 
    482488            $product_id = $arrList['product_id']; 
    483489            // 削除要求のあった既存ファイルの削除 
     
    496502        if( $_POST["copy_product_id"] == "" ){ 
    497503            // 規格登録 
    498             SC_Utils_Ex::sfInsertProductClass($objQuery, $arrList, $product_id , $arrList['product_class_id'] ); 
     504            $this->lfInsertDummyProductClass($arrList); 
    499505        } 
    500506 
     
    643649        // Form用配列を渡す。 
    644650        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL); 
    645     } 
    646  
    647     /* 規格あり判定用(規格が登録されていない場合:TRUE) */ 
    648     function lfCheckNonClass($product_id) { 
    649         if(SC_Utils_Ex::sfIsInt($product_id)) { 
    650             $objQuery  = new SC_Query(); 
    651             $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id1 <> 0"; 
    652             $count = $objQuery->count("dtb_products_class", $where, array($product_id)); 
    653             if($count > 0) { 
    654                 return false; 
    655             } 
    656         } 
    657         return true; 
    658651    } 
    659652 
     
    753746        $objQuery->begin(); 
    754747        $err_flag = false; 
    755         //非編集項目はコピー、編集項目は上書きして登録 
     748        //非編集項目は複製、編集項目は上書きして登録 
    756749        foreach($arrProductClass as $records) 
    757750        { 
     
    786779        return !$err_flag; 
    787780    } 
     781 
     782    /** 
     783     * 規格を設定していない商品を商品規格テーブルに登録 
     784     * 
     785     * @param array $arrList 
     786     * @return void 
     787     */ 
     788    function lfInsertDummyProductClass($arrList) { 
     789        $objQuery  = new SC_Query(); 
     790        $objDb = new SC_Helper_DB_Ex(); 
     791 
     792        $product_id = $arrList['product_id']; 
     793        // 規格登録してある商品の場合、処理しない 
     794        if ($objDb->sfHasProductClass($product_id)) return; 
     795 
     796        // 既存規格の削除 
     797        $where = 'product_id = ?'; 
     798        $objQuery->delete('dtb_products_class', $where, array($product_id)); 
     799 
     800        // 配列の添字を定義 
     801        $checkArray = array('product_class_id', 'product_id', 'product_code', 'stock', 'stock_unlimited', 'price01', 'price02'); 
     802        $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray); 
     803        $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray); 
     804 
     805        if (strlen($sqlval['product_class_id']) == 0) { 
     806            unset($sqlval['product_class_id']); 
     807        } 
     808        $sqlval['classcategory_id1'] = '0'; 
     809        $sqlval['classcategory_id2'] = '0'; 
     810        $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? '1' : '0'; 
     811        $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0'; 
     812        $sqlval['create_date'] = 'now()'; 
     813 
     814        // INSERTの実行 
     815        $objQuery->insert('dtb_products_class', $sqlval); 
     816    } 
    788817} 
    789818?> 
  • branches/comu-ver2/data/class/util/SC_Utils.php

    r18427 r18435  
    786786    } 
    787787 
    788     /* 規格の登録 */ 
    789     function sfInsertProductClass($objQuery, $arrList, $product_id , $product_class_id = "") { 
    790         // すでに規格登録があるかどうかをチェックする。 
    791         $where = "product_id = ? AND classcategory_id1 <> 0 AND classcategory_id2 <> 0"; 
    792         $count = $objQuery->count("dtb_products_class", $where,  array($product_id)); 
    793  
    794         // すでに規格登録がない場合 
    795         if($count == 0) { 
    796             // 既存規格の削除 
    797             $where = "product_id = ?"; 
    798             $objQuery->delete("dtb_products_class", $where, array($product_id)); 
    799  
    800             // 配列の添字を定義 
    801             $checkArray = array("product_code", "stock", "stock_unlimited", "price01", "price02"); 
    802             $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); 
    803  
    804             $sqlval['product_id'] = $product_id; 
    805             if(strlen($product_class_id ) > 0 ){ 
    806                 $sqlval['product_class_id'] = $product_class_id; 
    807             } 
    808             $sqlval['classcategory_id1'] = '0'; 
    809             $sqlval['classcategory_id2'] = '0'; 
    810             $sqlval['product_code'] = $arrList["product_code"]; 
    811             $sqlval['stock'] = $arrList["stock"]; 
    812             $sqlval['stock_unlimited'] = ($arrList["stock_unlimited"]) ? '1' : '0'; 
    813             $sqlval['price01'] = $arrList['price01']; 
    814             $sqlval['price02'] = $arrList['price02']; 
    815             $sqlval['creator_id'] = $_SESSION['member_id']; 
    816             $sqlval['create_date'] = "now()"; 
    817  
    818             if($_SESSION['member_id'] == "") { 
    819                 $sqlval['creator_id'] = '0'; 
    820             } 
    821  
    822             // INSERTの実行 
    823             $objQuery->insert("dtb_products_class", $sqlval); 
    824         } 
    825     } 
    826  
    827788    function sfGetProductClassId($product_id, $classcategory_id1, $classcategory_id2) { 
    828789        $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?"; 
     
    16801641        } 
    16811642        return $array; 
     1643    } 
     1644 
     1645    /** 
     1646     * $arrSrc のうち、キーが $arrKey に含まれるものを返す 
     1647     * 
     1648     * $arrSrc に含まない要素は返されない。 
     1649     * 
     1650     * @param array $arrSrc 
     1651     * @param array $arrKey 
     1652     * @return array 
     1653     */ 
     1654    function sfArrayIntersectKeys($arrSrc, $arrKey) { 
     1655        $arrRet = array(); 
     1656        foreach ($arrKey as $key) { 
     1657            if (isset($arrSrc[$key])) $arrRet[$key] = $arrSrc[$key]; 
     1658        } 
     1659        return $arrRet; 
    16821660    } 
    16831661 
Note: See TracChangeset for help on using the changeset viewer.