Changeset 20597


Ignore:
Timestamp:
2011/03/11 10:38:31 (13 years ago)
Author:
kimoto
Message:

ソースコード整形
冗長な処理を削除
整合性が取れてない変数の処理が多くて追いきれない・・・

File:
1 edited

Legend:

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

    r20595 r20597  
    7171        parent::init(); 
    7272 
    73         $masterData = new SC_DB_MasterData_Ex(); 
    74         $this->arrSTATUS = $masterData->getMasterData("mtb_status"); 
    75         $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image"); 
    76         $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date"); 
    77         $this->arrPRODUCTLISTMAX = $masterData->getMasterData("mtb_product_list_max"); 
     73        $masterData                 = new SC_DB_MasterData_Ex(); 
     74        $this->arrSTATUS            = $masterData->getMasterData("mtb_status"); 
     75        $this->arrSTATUS_IMAGE      = $masterData->getMasterData("mtb_status_image"); 
     76        $this->arrDELIVERYDATE      = $masterData->getMasterData("mtb_delivery_date"); 
     77        $this->arrPRODUCTLISTMAX    = $masterData->getMasterData("mtb_product_list_max"); 
    7878    } 
    7979 
     
    9595     */ 
    9696    function action() { 
    97         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     97        $objQuery   =& SC_Query_Ex::getSingletonInstance(); 
    9898        $objProduct = new SC_Product_Ex(); 
    9999 
     
    104104        //表示条件の取得 
    105105        $this->arrSearchData = array( 
    106             'category_id' => $this->lfGetCategoryId(intval($this->arrForm['category_id'])), 
    107             'maker_id'=>intval($this->arrForm['maker_id']), 
    108             'name'=>$this->arrForm['name'] 
     106            'category_id'   => $this->lfGetCategoryId(intval($this->arrForm['category_id'])), 
     107            'maker_id'      => intval($this->arrForm['maker_id']), 
     108            'name'          => $this->arrForm['name'] 
    109109        ); 
    110110        $this->orderby = $this->arrForm['orderby']; 
    111111 
    112112        //ページング設定 
    113         $this->tpl_pageno = $this->arrForm['pageno']; 
    114         $this->disp_number = $this->lfGetDisplayNum($this->arrForm['disp_number']); 
     113        $this->tpl_pageno   = $this->arrForm['pageno']; 
     114        $this->disp_number  = $this->lfGetDisplayNum($this->arrForm['disp_number']); 
    115115 
    116116        // 画面に表示するサブタイトルの設定 
    117         $this->tpl_subtitle = $this->lfGetPageTitle($this->mode,$this->arrSearchData['category_id']); 
     117        $this->tpl_subtitle = $this->lfGetPageTitle($this->mode, $this->arrSearchData['category_id']); 
    118118 
    119119        // 画面に表示する検索条件を設定 
    120         $this->arrSearch = $this->lfGetSearchConditionDisp($this->arrSearchData); 
     120        $this->arrSearch    = $this->lfGetSearchConditionDisp($this->arrSearchData); 
    121121 
    122122        // 商品一覧データの取得 
    123123        $arrSearchCondition = $this->lfGetSearchCondition($this->arrSearchData); 
    124         $this->tpl_linemax = $this->lfGetProductAllNum($arrSearchCondition); 
    125         $urlParam = "category_id={$this->arrSearchData['category_id']}&pageno=#page#"; 
    126         $this->objNavi = new SC_PageNavi_Ex($this->tpl_pageno, $this->tpl_linemax, $this->disp_number, 'fnNaviPage', NAVI_PMAX, $urlParam, SC_Display_Ex::detectDevice() !== DEVICE_TYPE_MOBILE); 
    127         $this->arrProducts = $this->lfGetProductsList($arrSearchCondition, $this->disp_number, $this->objNavi->start_row, $this->tpl_linemax, $objProduct); 
     124        $this->tpl_linemax  = $this->lfGetProductAllNum($arrSearchCondition); 
     125        $urlParam           = "category_id={$this->arrSearchData['category_id']}&pageno=#page#"; 
     126        $this->objNavi      = new SC_PageNavi_Ex($this->tpl_pageno, $this->tpl_linemax, $this->disp_number, 'fnNaviPage', NAVI_PMAX, $urlParam, SC_Display_Ex::detectDevice() !== DEVICE_TYPE_MOBILE); 
     127        $this->arrProducts  = $this->lfGetProductsList($arrSearchCondition, $this->disp_number, $this->objNavi->start_row, $this->tpl_linemax, $objProduct); 
    128128        //商品一覧の表示処理 
    129         $strnavi = $this->objNavi->strnavi; 
     129        $strnavi            = $this->objNavi->strnavi; 
    130130        // 表示文字列 
    131         $this->tpl_strnavi = empty($strnavi) ? " " : $strnavi; 
     131        $this->tpl_strnavi  = empty($strnavi) ? " " : $strnavi; 
    132132 
    133133        // 規格1クラス名 
    134         $this->tpl_class_name1 = $objProduct->className1; 
     134        $this->tpl_class_name1  = $objProduct->className1; 
    135135 
    136136        // 規格2クラス名 
    137         $this->tpl_class_name2 = $objProduct->className2; 
     137        $this->tpl_class_name2  = $objProduct->className2; 
    138138 
    139139        // 規格1 
    140         $this->arrClassCat1 = $objProduct->classCats1; 
     140        $this->arrClassCat1     = $objProduct->classCats1; 
    141141 
    142142        // 規格1が設定されている 
     
    145145        $this->tpl_classcat_find2 = $objProduct->classCat2_find; 
    146146 
    147         $this->tpl_stock_find = $objProduct->stock_find; 
     147        $this->tpl_stock_find       = $objProduct->stock_find; 
    148148        $this->tpl_product_class_id = $objProduct->product_class_id; 
    149         $this->tpl_product_type = $objProduct->product_type; 
     149        $this->tpl_product_type     = $objProduct->product_type; 
    150150 
    151151        // 商品ステータスを取得 
     
    162162        if ( $target_product_id > 0) { 
    163163            // 商品IDの正当性チェック 
    164             if (!SC_Utils_Ex::sfIsInt($this->arrForm['product_id']) || !SC_Helper_DB_Ex::sfIsRecord("dtb_products", "product_id", $this->arrForm['product_id'], "del_flg = 0 AND status = 1")) { 
     164            if (!SC_Utils_Ex::sfIsInt($this->arrForm['product_id']) 
     165                || !SC_Helper_DB_Ex::sfIsRecord("dtb_products", "product_id", $this->arrForm['product_id'], "del_flg = 0 AND status = 1")) { 
    165166                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); 
    166167            } 
    167168 
    168169            // 入力内容のチェック 
    169             $arrErr = $this->lfCheckError($target_product_id,$this->arrForm,$this->tpl_classcat_find1,$this->tpl_classcat_find2); 
    170             if (count($arrErr) == 0) { 
     170            $arrErr = $this->lfCheckError($target_product_id, $this->arrForm, $this->tpl_classcat_find1, $this->tpl_classcat_find2); 
     171            if (empty($arrErr)) { 
    171172                $this->lfAddCart($this->arrForm, $_SERVER['HTTP_REFERER']); 
    172173                SC_Response_Ex::sendRedirect(CART_URLPATH); 
    173174                exit; 
    174175            } 
    175             $js_fnOnLoad .= $this->lfSetSelectedData($this->arrProducts,$this->arrForm,$arrErr,$target_product_id); 
    176         } 
    177  
    178         // ページャ用データ設定(モバイル) 
    179         if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) { 
    180             $this->tpl_previous_page = $this->objNavi->arrPagenavi['before']; 
    181             $this->tpl_next_page =  $this->objNavi->arrPagenavi['next']; 
    182         } 
    183  
    184         $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'; 
    185         $this->tpl_onload .= 'fnOnLoad(); '; 
    186  
    187         $this->tpl_rnd = SC_Utils_Ex::sfGetRandomString(3); 
     176            $js_fnOnLoad .= $this->lfSetSelectedData($this->arrProducts, $this->arrForm, $arrErr, $target_product_id); 
     177        } 
     178 
     179        $this->tpl_javascript   .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'; 
     180        $this->tpl_onload       .= 'fnOnLoad(); '; 
     181 
     182        $this->tpl_rnd          = SC_Utils_Ex::sfGetRandomString(3); 
    188183    } 
    189184 
     
    203198     */ 
    204199    function lfGetCategoryId($category_id) { 
     200 
    205201        // 指定なしの場合、0 を返す 
    206         if ( 
    207             strlen($category_id) == 0 
    208             || (String) $category_id == '0' 
    209         ) { 
    210             return 0; 
    211         } 
     202        if (empty($category_id)) return 0; 
    212203 
    213204        // 正当性チェック 
    214         if ( 
    215             !SC_Utils_Ex::sfIsInt($category_id) 
    216                 || SC_Utils_Ex::sfIsZeroFilling($category_id) 
     205        if (!SC_Utils_Ex::sfIsInt($category_id) 
     206            || SC_Utils_Ex::sfIsZeroFilling($category_id) 
    217207            || !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0') 
    218         ) { 
     208            ) { 
    219209            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND); 
    220     } 
     210        } 
    221211 
    222212        // 指定されたカテゴリIDを元に正しいカテゴリIDを取得する。 
     
    231221 
    232222    /* 商品一覧の表示 */ 
    233     function lfGetProductsList($searchCondition,$disp_number,$startno,$linemax,&$objProduct) { 
     223    function lfGetProductsList($searchCondition, $disp_number, $startno, $linemax, &$objProduct) { 
    234224 
    235225        $arrval_order = array(); 
     
    251241                if (strlen($searchCondition["where_category"]) >= 1) { 
    252242                    $dtb_product_categories = "(SELECT * FROM dtb_product_categories WHERE ".$searchCondition["where_category"].")"; 
    253                     $arrval_order = array_merge($searchCondition['arrvalCategory'], $searchCondition['arrvalCategory']); 
     243                    $arrval_order           = array_merge($searchCondition['arrvalCategory'], $searchCondition['arrvalCategory']); 
    254244                } else { 
    255245                    $dtb_product_categories = 'dtb_product_categories'; 
     
    316306        // 規格を設定 
    317307        $objProduct->setProductsClassByProductIds($arrProduct_id); 
    318         $arrProducts += array('productStatus'=>$objProduct->getProductStatus($arrProduct_id)); 
     308        $arrProducts += array('productStatus' => $objProduct->getProductStatus($arrProduct_id)); 
    319309        return $arrProducts; 
    320310    } 
    321311 
    322312    /* 入力内容のチェック */ 
    323     function lfCheckError($product_id,&$arrForm,$tpl_classcat_find1,$tpl_classcat_find2) { 
     313    function lfCheckError($product_id, &$arrForm, $tpl_classcat_find1, $tpl_classcat_find2) { 
    324314 
    325315        // 入力データを渡す。 
     
    347337    function lfGetDisplayNum($display_number) { 
    348338        // 表示件数 
    349         if (!isset($display_number) 
    350             OR !SC_Utils_Ex::sfIsInt($display_number) 
    351         ) { 
    352             //最小表示件数を選択 
    353             return current(array_keys($this->arrPRODUCTLISTMAX)); 
    354         } 
    355         return $display_number; 
     339        return (SC_Utils_Ex::sfIsInt($display_number)) 
     340            ? $display_number 
     341            : current(array_keys($this->arrPRODUCTLISTMAX)); 
    356342    } 
    357343 
     
    361347     * @return str 
    362348     */ 
    363     function lfGetPageTitle($mode,$category_id = 0){ 
     349    function lfGetPageTitle($mode, $category_id = 0){ 
    364350        if ($mode == 'search') { 
    365351            return "検索結果"; 
     
    370356            return $arrCat['name']; 
    371357        } 
    372         return ""; 
    373358    } 
    374359 
     
    379364     */ 
    380365    function lfGetSearchConditionDisp($arrSearchData){ 
    381         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    382         $arrSearch = array('category'=>"指定なし",'maker'=>"指定なし",'name'=>"指定なし"); 
     366        $objQuery   =& SC_Query_Ex::getSingletonInstance(); 
     367        $arrSearch  = array('category' => '指定なし', 'maker' => '指定なし', 'name' => '指定なし'); 
    383368        // カテゴリー検索条件 
    384369        if ($arrSearchData['category_id'] > 0) { 
    385             $arrSearch['category'] = $objQuery->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?", array($arrSearchData['category_id'])); 
     370            $arrSearch['category']  = $objQuery->get('category_name', 'dtb_category', 'category_id = ?', array($arrSearchData['category_id'])); 
    386371        } 
    387372 
    388373        // メーカー検索条件 
    389374        if (strlen($arrSearchData['maker_id']) > 0) { 
    390             $arrSearch['maker'] = $objQuery->getOne("SELECT name FROM dtb_maker WHERE maker_id = ?", array($arrSearchData['maker_id'])); 
     375            $arrSearch['maker']     = $objQuery->get('name', 'dtb_maker', 'maker_id = ?', array($arrSearchData['maker_id'])); 
    391376        } 
    392377 
    393378        // 商品名検索条件 
    394379        if (strlen($arrSearchData['name']) > 0) { 
    395             $arrSearch['name'] = $arrSearchData['name']; 
     380            $arrSearch['name']      = $arrSearchData['name']; 
    396381        } 
    397382        return $arrSearch; 
     
    405390    function lfGetProductAllNum($searchCondition){ 
    406391        // 検索結果対象となる商品の数を取得 
    407         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     392        $objQuery   =& SC_Query_Ex::getSingletonInstance(); 
    408393        $objQuery->setWhere($searchCondition['where']); 
    409394        $objProduct = new SC_Product_Ex(); 
     
    418403    function lfGetSearchCondition($arrSearchData){ 
    419404        $searchCondition = array( 
    420             'where'=>"", 
    421             'arrval'=>array(), 
    422             "where_category"=>"", 
    423             'arrvalCategory'=>array() 
     405            'where'             => "", 
     406            'arrval'            => array(), 
     407            "where_category"    => "", 
     408            'arrvalCategory'    => array() 
    424409        ); 
    425410 
     
    452437        foreach ($names as $val) { 
    453438            if ( strlen($val) > 0 ) { 
    454                 $searchCondition['where'] .= " AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) "; 
    455                 $searchCondition['arrval'][] = "%$val%"; 
    456                 $searchCondition['arrval'][] = "%$val%"; 
     439                $searchCondition['where']    .= " AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) "; 
     440                $searchCondition['arrval'][]  = "%$val%"; 
     441                $searchCondition['arrval'][]  = "%$val%"; 
    457442            } 
    458443        } 
     
    460445        // メーカーらのWHERE文字列取得 
    461446        if ($arrSearchData['maker_id']) { 
    462             $searchCondition['where'] .= " AND alldtl.maker_id = ? "; 
     447            $searchCondition['where']   .= " AND alldtl.maker_id = ? "; 
    463448            $searchCondition['arrval'][] = $arrSearchData['maker_id']; 
    464449        } 
     
    471456     * @return str 
    472457     */ 
    473     function lfSetSelectedData(&$arrProducts,$arrForm,$arrErr,$product_id){ 
     458    function lfSetSelectedData(&$arrProducts, $arrForm, $arrErr, $product_id){ 
    474459        $js_fnOnLoad = ""; 
    475460        foreach (array_keys($arrProducts) as $key) { 
    476461            if ($arrProducts[$key]['product_id'] == $product_id) { 
    477                 $arrProducts[$key]['product_class_id'] = $arrForm['product_class_id']; 
     462 
     463                $arrProducts[$key]['product_class_id']  = $arrForm['product_class_id']; 
    478464                $arrProducts[$key]['classcategory_id1'] = $arrForm['classcategory_id1']; 
    479465                $arrProducts[$key]['classcategory_id2'] = $arrForm['classcategory_id2']; 
    480                 $arrProducts[$key]['quantity'] = $arrForm['quantity']; 
    481                 $arrProducts[$key]['arrErr'] = $arrErr; 
     466                $arrProducts[$key]['quantity']          = $arrForm['quantity']; 
     467                $arrProducts[$key]['arrErr']            = $arrErr; 
    482468                $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProducts[$key]['product_id']}, '{$arrForm['classcategory_id2']}');"; 
    483469            } 
Note: See TracChangeset for help on using the changeset viewer.