Changeset 20199


Ignore:
Timestamp:
2011/02/19 17:07:29 (13 years ago)
Author:
tao
Message:

refs #982 リファクタリング 商品一覧の表示まで

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

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/helper/SC_Helper_DB.php

    r20180 r20199  
    509509            $category_id = (int) $category_id; 
    510510            $product_id = (int) $product_id; 
    511             if (SC_Utils_Ex::sfIsInt($category_id) && $category_id != 0 && $this->sfIsRecord("dtb_category","category_id", $category_id)) { 
     511            if (SC_Utils_Ex::sfIsInt($category_id) && $category_id != 0 && SC_Helper_DB_Ex::sfIsRecord("dtb_category","category_id", $category_id)) { 
    512512                $this->g_category_id = array($category_id); 
    513             } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) { 
     513            } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && SC_Helper_DB_Ex::sfIsRecord("dtb_products","product_id", $product_id, $status)) { 
    514514                $objQuery =& SC_Query::getSingletonInstance(); 
    515515                $where = "product_id = ?"; 
     
    829829        $arrChildren[] = $id; 
    830830 
    831         $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); 
     831        $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); 
    832832 
    833833        while(count($arrRet) > 0) { 
    834834            $arrChildren = array_merge($arrChildren, $arrRet); 
    835             $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet); 
     835            $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet); 
    836836        } 
    837837 
     
    917917    function sfGetCatWhere($category_id) { 
    918918        // 子カテゴリIDの取得 
    919         $arrRet = $this->sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id); 
     919        $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray("dtb_category", "parent_category_id", "category_id", $category_id); 
    920920        $tmp_where = ""; 
    921921        foreach ($arrRet as $val) { 
  • branches/version-2_5-dev/data/class/pages/products/LC_Page_Products_List.php

    r20197 r20199  
    9595     */ 
    9696    function action() { 
    97         $objQuery = new SC_Query();//$this->queryにしたい 
     97        $objQuery =& SC_Query::getSingletonInstance(); 
    9898        $objDb = new SC_Helper_DB_Ex();//$this->helperDBにしたい 
     99        $objProduct = new SC_Product(); 
    99100 
    100101        $this->arrForm = $_GET; 
     
    104105        //表示条件の取得 
    105106        $this->arrSearchData = array( 
    106             'category_id' => $this->lfGetCategoryId($this->arrForm['category_id'],&$objDb), 
     107            'category_id' => $this->lfGetCategoryId($this->arrForm['category_id']), 
    107108            'maker_id'=>$this->arrForm['maker_id'], 
    108109            'name'=>$this->arrForm['name'] 
     
    113114        $this->tpl_pageno = $this->arrForm['pageno']; 
    114115        $this->disp_number = $this->lfGetDisplayNum($this->arrForm['disp_number']); 
     116        $urlParam = "category_id={$this->arrSearchData['category_id']}&pageno=#page#"; 
     117        $this->objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $this->disp_number, "fnNaviPage", NAVI_PMAX, $urlParam); 
    115118 
    116119        // 画面に表示するサブタイトルの設定 
    117         $this->tpl_subtitle = $this->lfGetPageTitle($this->mode,$this->arrSearchData['category_id'],$objDb); 
     120        $this->tpl_subtitle = $this->lfGetPageTitle($this->mode,$this->arrSearchData['category_id']); 
    118121 
    119122        // 画面に表示する検索条件を設定 
    120         $this->arrSearch = $this->lfGetSearchCondition($this->arrSearchData,$objQuery); 
     123        $this->arrSearch = $this->lfGetSearchConditionDisp($this->arrSearchData); 
    121124        //この辺まではinit()に書いちゃダメなのかな? 
    122 //2011-02-17 ここまでやった 
    123  
    124         // 商品一覧の表示処理 
    125         $this->arrProducts = $this->lfGetProductsList($objDb); 
     125 
     126        // 商品一覧データの取得 
     127        $searchCondition = $this->lfGetSearchCondition($arrSearchData); 
     128        $this->tpl_linemax = $this->lfGetProductAllNum($searchCondition); 
     129        $this->arrProducts = $this->lfGetProductsList($searchCondition,$this->disp_number,$this->objNavi->start_row,$this->tpl_linemax,&$objProduct); 
     130         
     131        //商品一覧の表示処理 
     132        $strnavi = $this->objNavi->strnavi; 
     133        // 表示文字列 
     134        $this->tpl_strnavi = empty($strnavi) ? " " : $strnavi; 
     135 
     136        // 規格1クラス名 
     137        $this->tpl_class_name1 = $objProduct->className1; 
     138 
     139        // 規格2クラス名 
     140        $this->tpl_class_name2 = $objProduct->className2; 
     141 
     142        // 規格1 
     143        $this->arrClassCat1 = $objProduct->classCats1; 
     144 
     145        // 規格1が設定されている 
     146        $this->tpl_classcat_find1 = $objProduct->classCat1_find; 
     147        // 規格2が設定されている 
     148        $this->tpl_classcat_find2 = $objProduct->classCat2_find; 
     149 
     150        $this->tpl_stock_find = $objProduct->stock_find; 
     151        $this->tpl_product_class_id = $objProduct->product_class_id; 
     152        $this->tpl_product_type = $objProduct->product_type; 
     153 
     154        // 商品ステータスを取得 
     155        $this->productStatus = $this->arrProducts["productStatus"]; 
     156        unset($this->arrProducts["productStatus"]); 
     157 
     158        $productsClassCategories = $objProduct->classCategories; 
     159 
     160        $objJson = new Services_JSON(); 
     161        $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($productsClassCategories) . '; '; 
     162         
    126163 
    127164        //onloadスクリプトを設定 
     
    133170        if (intval($this->arrForm['product_id']) > 0) { 
    134171            // 商品IDの正当性チェック 
    135             if (!SC_Utils_Ex::sfIsInt($this->arrForm['product_id']) || !$objDb->sfIsRecord("dtb_products", "product_id", $this->arrForm['product_id'], "del_flg = 0 AND status = 1")) { 
     172            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")) { 
    136173                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); 
    137174            } 
     
    203240     * @return integer カテゴリID 
    204241     */ 
    205     function lfGetCategoryId($category_id,&$objDb) { 
     242    function lfGetCategoryId($category_id) { 
    206243        // 指定なしの場合、0 を返す 
    207244        if ( 
     
    216253            !SC_Utils_Ex::sfIsInt($category_id) 
    217254                || SC_Utils_Ex::sfIsZeroFilling($category_id) 
    218             || !$objDb->sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0') 
     255            || !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0') 
    219256        ) { 
    220257            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND); 
     
    222259 
    223260        // 指定されたカテゴリIDを元に正しいカテゴリIDを取得する。 
    224         $arrCategory_id = $objDb->sfGetCategoryId('', $category_id); 
     261        $arrCategory_id = SC_Helper_DB_Ex::sfGetCategoryId('', $category_id); 
    225262 
    226263        if (empty($arrCategory_id)) { 
     
    232269 
    233270    /* 商品一覧の表示 */ 
    234     function lfGetProductsList($objDb) { 
    235         $arrval = array(); 
     271    function lfGetProductsList($searchCondition,$disp_number,$startno,$linemax,&$objProduct) { 
     272 
    236273        $arrval_order = array(); 
    237         $arrval_category = array(); 
    238  
    239         // カテゴリからのWHERE文字列取得 
    240         if ($this->arrSearchData['category_id'] != 0) { 
    241             list($where_category, $arrval_category) = $objDb->sfGetCatWhere($this->arrSearchData['category_id']); 
    242         } 
    243         // ▼対象商品IDの抽出 
    244         // 商品検索条件の作成(未削除、表示) 
    245         $where = "alldtl.del_flg = 0 AND alldtl.status = 1 "; 
    246  
    247         // 在庫無し商品の非表示 
    248         if (NOSTOCK_HIDDEN === true) { 
    249             $where .= ' AND (stock >= 1 OR stock_unlimited = 1)'; 
    250         } 
    251  
    252         if (strlen($where_category) >= 1) { 
    253             $where .= " AND T2.$where_category"; 
    254             $arrval = array_merge($arrval, $arrval_category); 
    255         } 
    256  
    257         // 商品名をwhere文に 
    258         $name = $this->arrSearchData['name']; 
    259         $name = ereg_replace(",", "", $name);// XXX 
    260         // 全角スペースを半角スペースに変換 
    261         $name = str_replace(' ', ' ', $name); 
    262         // スペースでキーワードを分割 
    263         $names = preg_split("/ +/", $name); 
    264         // 分割したキーワードを一つずつwhere文に追加 
    265         foreach ($names as $val) { 
    266             if ( strlen($val) > 0 ) { 
    267                 $where .= " AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) "; 
    268                 $arrval[] = "%$val%"; 
    269                 $arrval[] = "%$val%"; 
    270             } 
    271         } 
    272  
    273         // メーカーらのWHERE文字列取得 
    274         if ($this->arrSearchData['maker_id']) { 
    275             $where .= " AND alldtl.maker_id = ? "; 
    276             $arrval[] = $this->arrSearchData['maker_id']; 
    277         } 
    278  
    279         // 検索結果対象となる商品の数を取得 
    280         $objQuery =& SC_Query::getSingletonInstance(); 
    281         $objQuery->setWhere($where); 
    282         $objProduct = new SC_Product(); 
    283         $linemax = $objProduct->findProductCount($objQuery, $arrval); 
    284         $this->tpl_linemax = $linemax;   // 何件が該当しました。表示用 
    285  
    286         // ページ送りの取得 
    287         $urlParam = "category_id={$this->arrSearchData['category_id']}&pageno=#page#"; 
    288         $this->objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $this->disp_number, "fnNaviPage", NAVI_PMAX, $urlParam); 
    289         $strnavi = $this->objNavi->strnavi; 
    290  
    291         // 表示文字列 
    292         $this->tpl_strnavi = empty($strnavi) ? " " : $strnavi; 
    293         $startno = $this->objNavi->start_row;                 // 開始行 
    294  
    295         $objProduct = new SC_Product(); 
     274 
    296275        $objQuery =& SC_Query::getSingletonInstance(); 
    297276        // 表示順序 
     
    308287 
    309288            default: 
    310                 if (strlen($where_category) >= 1) { 
    311                     $dtb_product_categories = "(SELECT * FROM dtb_product_categories WHERE $where_category)"; 
    312                     $arrval_order = array_merge($arrval_category, $arrval_category); 
     289                if (strlen($searchCondition["where_category"]) >= 1) { 
     290                    $dtb_product_categories = "(SELECT * FROM dtb_product_categories WHERE ".$searchCondition["where_category"].")"; 
     291                    $arrval_order = $searchCondition["arrvalCategory"]; 
    313292                } else { 
    314293                    $dtb_product_categories = 'dtb_product_categories'; 
     
    343322        } 
    344323        // 取得範囲の指定(開始行番号、行数のセット) 
    345         $objQuery->setLimitOffset($this->disp_number, $startno); 
    346         $objQuery->setWhere($where); 
     324        $objQuery->setLimitOffset($disp_number, $startno); 
     325        $objQuery->setWhere($searchCondition["where"]); 
    347326 
    348327         // 表示すべきIDとそのIDの並び順を一気に取得 
    349         $arrProduct_id = $objProduct->findProductIdsOrder($objQuery, array_merge($arrval, $arrval_order)); 
    350  
    351         // 取得した表示すべきIDだけを指定して情報を取得。 
     328        $arrProduct_id = $objProduct->findProductIdsOrder($objQuery, array_merge($searchCondition["arrval"], $arrval_order)); 
     329 
     330        // 取得した表示すべきIDだけを指定して情報を取得。 < 謎の処理 
    352331        $where = ""; 
    353332        if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 
     
    370349            $arrProducts[] = $arrProducts2[$product_id]; 
    371350        } 
    372  
     351         
    373352        // 規格を設定 
    374353        $objProduct->setProductsClassByProductIds($arrProduct_id); 
    375  
    376         // 規格1クラス名 
    377         $this->tpl_class_name1 = $objProduct->className1; 
    378  
    379         // 規格2クラス名 
    380         $this->tpl_class_name2 = $objProduct->className2; 
    381  
    382         // 規格1 
    383         $this->arrClassCat1 = $objProduct->classCats1; 
    384  
    385         // 規格1が設定されている 
    386         $this->tpl_classcat_find1 = $objProduct->classCat1_find; 
    387         // 規格2が設定されている 
    388         $this->tpl_classcat_find2 = $objProduct->classCat2_find; 
    389  
    390         $this->tpl_stock_find = $objProduct->stock_find; 
    391         $this->tpl_product_class_id = $objProduct->product_class_id; 
    392         $this->tpl_product_type = $objProduct->product_type; 
    393  
    394         // 商品ステータスを取得 
    395         $this->productStatus = $objProduct->getProductStatus($arrProduct_id); 
    396  
    397         $productsClassCategories = $objProduct->classCategories; 
    398  
    399         $objJson = new Services_JSON(); 
    400         $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($productsClassCategories) . '; '; 
     354        $arrProducts += array("productStatus"=>$objProduct->getProductStatus($arrProduct_id));      
    401355        return $arrProducts; 
    402356    } 
     
    466420     * @return str 
    467421     */     
    468     function lfGetPageTitle($mode,$category_id = 0,$objDb){ 
     422    function lfGetPageTitle($mode,$category_id = 0){ 
    469423        if ($mode == 'search') { 
    470424            return "検索結果"; 
     
    472426            return "全商品"; 
    473427        } else { 
    474             $arrCat = $objDb->sfGetCat($category_id); 
     428            $arrCat = SC_Helper_DB_Ex::sfGetCat($category_id); 
    475429            return $arrCat['name']; 
    476430        } 
     
    479433 
    480434    /** 
    481      * 検索条件の設定 
     435     * 表示用検索条件の設定 
    482436     * 
    483437     * @return array 
    484438     */     
    485     function lfGetSearchCondition($arrSearchData,$objQuery){ 
     439    function lfGetSearchConditionDisp($arrSearchData){ 
     440        $objQuery =& SC_Query::getSingletonInstance(); 
    486441        $arrSearch = array('category'=>"指定なし",'maker'=>"指定なし",'name'=>"指定なし"); 
    487442        // カテゴリー検索条件 
     
    501456        return $arrSearch; 
    502457    } 
     458     
     459    /** 
     460     * 該当件数の取得 
     461     * 
     462     * @return int 
     463     */     
     464    function lfGetProductAllNum($searchCondition){ 
     465        // 検索結果対象となる商品の数を取得 
     466        $objQuery =& SC_Query::getSingletonInstance(); 
     467        $objQuery->setWhere($searchCondition["where"]); 
     468        $objProduct = new SC_Product(); 
     469        return $objProduct->findProductCount($objQuery, $searchCondition["arrval"]); 
     470    } 
     471     
     472    /** 
     473     * 検索条件のwhere文とかを取得 
     474     * 
     475     * @return array 
     476     */     
     477    function lfGetSearchCondition($arrSearchData){ 
     478        $searchCondition = array( 
     479            "where"=>"", 
     480            "arrval"=>array(), 
     481            "where_category"=>"", 
     482            "arrvalCategory"=>array() 
     483        ); 
     484         
     485        // カテゴリからのWHERE文字列取得 
     486        if ($arrSearchData["category_id"] != 0) { 
     487            list($searchCondition["where_category"], $searchCondition["arrvalCategory"]) = SC_Helper_DB_Ex::sfGetCatWhere($arrSearchData["category_id"]); 
     488        } 
     489        // ▼対象商品IDの抽出 
     490        // 商品検索条件の作成(未削除、表示) 
     491        $searchCondition["where"] = "alldtl.del_flg = 0 AND alldtl.status = 1 "; 
     492 
     493        // 在庫無し商品の非表示 
     494        if (NOSTOCK_HIDDEN === true) { 
     495            $searchCondition["where"] .= ' AND (stock >= 1 OR stock_unlimited = 1)'; 
     496        } 
     497 
     498        if (strlen($searchCondition["where_category"]) >= 1) { 
     499            $searchCondition["where"] .= " AND T2.".$searchCondition["where_category"]; 
     500            $searchCondition["arrval"] = array_merge($searchCondition["arrval"], $searchCondition["arrvalCategory"]); 
     501        } 
     502 
     503        // 商品名をwhere文に 
     504        $name = $arrSearchData['name']; 
     505        $name = ereg_replace(",", "", $name);// XXX 
     506        // 全角スペースを半角スペースに変換 
     507        $name = str_replace(' ', ' ', $name); 
     508        // スペースでキーワードを分割 
     509        $names = preg_split("/ +/", $name); 
     510        // 分割したキーワードを一つずつwhere文に追加 
     511        foreach ($names as $val) { 
     512            if ( strlen($val) > 0 ) { 
     513                $searchCondition["where"] .= " AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) "; 
     514                $searchCondition["arrval"][] = "%$val%"; 
     515                $searchCondition["arrval"][] = "%$val%"; 
     516            } 
     517        } 
     518 
     519        // メーカーらのWHERE文字列取得 
     520        if ($arrSearchData['maker_id']) { 
     521            $searchCondition["where"] .= " AND alldtl.maker_id = ? "; 
     522            $searchCondition["arrval"][] = $arrSearchData['maker_id']; 
     523        } 
     524        return $searchCondition; 
     525    } 
    503526} 
    504527?> 
Note: See TracChangeset for help on using the changeset viewer.