- Timestamp:
- 2011/02/19 17:07:29 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/pages/products/LC_Page_Products_List.php
r20197 r20199 95 95 */ 96 96 function action() { 97 $objQuery = new SC_Query();//$this->queryにしたい97 $objQuery =& SC_Query::getSingletonInstance(); 98 98 $objDb = new SC_Helper_DB_Ex();//$this->helperDBにしたい 99 $objProduct = new SC_Product(); 99 100 100 101 $this->arrForm = $_GET; … … 104 105 //表示条件の取得 105 106 $this->arrSearchData = array( 106 'category_id' => $this->lfGetCategoryId($this->arrForm['category_id'] ,&$objDb),107 'category_id' => $this->lfGetCategoryId($this->arrForm['category_id']), 107 108 'maker_id'=>$this->arrForm['maker_id'], 108 109 'name'=>$this->arrForm['name'] … … 113 114 $this->tpl_pageno = $this->arrForm['pageno']; 114 115 $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); 115 118 116 119 // 画面に表示するサブタイトルの設定 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']); 118 121 119 122 // 画面に表示する検索条件を設定 120 $this->arrSearch = $this->lfGetSearchCondition ($this->arrSearchData,$objQuery);123 $this->arrSearch = $this->lfGetSearchConditionDisp($this->arrSearchData); 121 124 //この辺までは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 126 163 127 164 //onloadスクリプトを設定 … … 133 170 if (intval($this->arrForm['product_id']) > 0) { 134 171 // 商品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")) { 136 173 SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); 137 174 } … … 203 240 * @return integer カテゴリID 204 241 */ 205 function lfGetCategoryId($category_id ,&$objDb) {242 function lfGetCategoryId($category_id) { 206 243 // 指定なしの場合、0 を返す 207 244 if ( … … 216 253 !SC_Utils_Ex::sfIsInt($category_id) 217 254 || 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') 219 256 ) { 220 257 SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND); … … 222 259 223 260 // 指定されたカテゴリIDを元に正しいカテゴリIDを取得する。 224 $arrCategory_id = $objDb->sfGetCategoryId('', $category_id);261 $arrCategory_id = SC_Helper_DB_Ex::sfGetCategoryId('', $category_id); 225 262 226 263 if (empty($arrCategory_id)) { … … 232 269 233 270 /* 商品一覧の表示 */ 234 function lfGetProductsList($ objDb) {235 $arrval = array(); 271 function lfGetProductsList($searchCondition,$disp_number,$startno,$linemax,&$objProduct) { 272 236 273 $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 296 275 $objQuery =& SC_Query::getSingletonInstance(); 297 276 // 表示順序 … … 308 287 309 288 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"]; 313 292 } else { 314 293 $dtb_product_categories = 'dtb_product_categories'; … … 343 322 } 344 323 // 取得範囲の指定(開始行番号、行数のセット) 345 $objQuery->setLimitOffset($ this->disp_number, $startno);346 $objQuery->setWhere($ where);324 $objQuery->setLimitOffset($disp_number, $startno); 325 $objQuery->setWhere($searchCondition["where"]); 347 326 348 327 // 表示すべき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だけを指定して情報を取得。 < 謎の処理 352 331 $where = ""; 353 332 if (is_array($arrProduct_id) && !empty($arrProduct_id)) { … … 370 349 $arrProducts[] = $arrProducts2[$product_id]; 371 350 } 372 351 373 352 // 規格を設定 374 353 $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)); 401 355 return $arrProducts; 402 356 } … … 466 420 * @return str 467 421 */ 468 function lfGetPageTitle($mode,$category_id = 0 ,$objDb){422 function lfGetPageTitle($mode,$category_id = 0){ 469 423 if ($mode == 'search') { 470 424 return "検索結果"; … … 472 426 return "全商品"; 473 427 } else { 474 $arrCat = $objDb->sfGetCat($category_id);428 $arrCat = SC_Helper_DB_Ex::sfGetCat($category_id); 475 429 return $arrCat['name']; 476 430 } … … 479 433 480 434 /** 481 * 検索条件の設定435 * 表示用検索条件の設定 482 436 * 483 437 * @return array 484 438 */ 485 function lfGetSearchCondition($arrSearchData,$objQuery){ 439 function lfGetSearchConditionDisp($arrSearchData){ 440 $objQuery =& SC_Query::getSingletonInstance(); 486 441 $arrSearch = array('category'=>"指定なし",'maker'=>"指定なし",'name'=>"指定なし"); 487 442 // カテゴリー検索条件 … … 501 456 return $arrSearch; 502 457 } 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 } 503 526 } 504 527 ?>
Note: See TracChangeset
for help on using the changeset viewer.