Changeset 21256
- Timestamp:
- 2011/09/25 13:15:51 (13 years ago)
- Location:
- branches/version-2_11-dev/data/class
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/class/SC_Product.php
r21245 r21256 137 137 * 138 138 * @param SC_Query $objQuery SC_Query インスタンス 139 * @param array $arrVal 検索パラメーター(ソート条件)の配列140 139 * @return array 商品一覧の配列 141 140 */ 142 function lists(&$objQuery , $arrVal = array()) {141 function lists(&$objQuery) { 143 142 $col = <<< __EOS__ 144 143 product_id … … 165 164 ,update_date 166 165 __EOS__; 167 $ res = $objQuery->select($col, $this->alldtlSQL($objQuery->where),168 "", $arrVal);166 $where = 'dtb_products_class.del_flg = 0'; 167 $res = $objQuery->select($col, $this->alldtlSQL($where)); 169 168 return $res; 169 } 170 171 172 /** 173 * 商品IDを指定し、商品一覧を取得する 174 * 175 * SC_Query::setOrder() や SC_Query::setLimitOffset() を設定して, 商品一覧 176 * の配列を取得する. 177 * FIXME: 呼び出し元で設定した、SC_Query::setWhere() も有効に扱いたい。 178 * 179 * @param SC_Query $objQuery SC_Query インスタンス 180 * @param array|int $arrProductId 商品ID 181 * @return array 商品一覧の配列 182 */ 183 function getListByProductIds(&$objQuery, $arrProductId = array()) { 184 if (empty($arrProductId)) { 185 return array(); 186 } 187 188 $where = 'alldtl.product_id IN (' . implode(',', array_fill(0, count($arrProductId), '?')) . ')'; 189 $where .= ' AND alldtl.del_flg = 0'; 190 191 $objQuery->setWhere($where, $arrProductId); 192 $arrRet = $this->lists($objQuery); 193 return $arrRet; 170 194 } 171 195 -
branches/version-2_11-dev/data/class/SC_Query.php
r21254 r21256 35 35 36 36 var $instance; 37 var $option; 38 var $where; 37 var $option = ''; 38 var $where = ''; 39 var $arrWhereVal = array(); 39 40 var $conn; 40 var $groupby ;41 var $order ;41 var $groupby = ''; 42 var $order = ''; 42 43 var $force_run; 43 44 … … 82 83 $this->dbFactory = SC_DB_DBFactory_Ex::getInstance(); 83 84 $this->force_run = $force_run; 84 $this->where = "";85 $this->order = "";86 $this->groupby = "";87 $this->option = "";88 85 } 89 86 … … 101 98 $GLOBALS['_SC_Query_instance'] =& new SC_Query_Ex($dsn, $force_run, $new); 102 99 } 103 $GLOBALS['_SC_Query_instance']->where = ""; 104 $GLOBALS['_SC_Query_instance']->order = ""; 105 $GLOBALS['_SC_Query_instance']->groupby = ""; 106 $GLOBALS['_SC_Query_instance']->option = ""; 100 $GLOBALS['_SC_Query_instance']->where = ''; 101 $GLOBALS['_SC_Query_instance']->arrWhereVal = array(); 102 $GLOBALS['_SC_Query_instance']->order = ''; 103 $GLOBALS['_SC_Query_instance']->groupby = ''; 104 $GLOBALS['_SC_Query_instance']->option = ''; 107 105 return $GLOBALS['_SC_Query_instance']; 108 106 } … … 126 124 * @param string $table テーブル名 127 125 * @param string $where where句 128 * @param array $arr val プレースホルダ126 * @param array $arrWhereVal プレースホルダ 129 127 * @return integer 件数 130 128 */ 131 function count($table, $where = "", $arr val = array()) {129 function count($table, $where = "", $arrWhereVal = array()) { 132 130 if(strlen($where) <= 0) { 133 131 $sqlse = "SELECT COUNT(*) FROM $table"; … … 136 134 } 137 135 $sqlse = $this->dbFactory->sfChangeMySQL($sqlse); 138 return $this->getOne($sqlse, $arr val);136 return $this->getOne($sqlse, $arrWhereVal); 139 137 } 140 138 … … 145 143 * @param string $table テーブル名 146 144 * @param string $where WHERE句 147 * @param array $arr val プレースホルダ145 * @param array $arrWhereVal プレースホルダ 148 146 * @param integer $fetchmode 使用するフェッチモード。デフォルトは MDB2_FETCHMODE_ASSOC。 149 147 * @return array|null 150 148 */ 151 function select($col, $table, $where = "", $arr val = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) {152 $sqlse = $this->getSql($col, $table, $where );153 return $this->getAll($sqlse, $arr val, $fetchmode);149 function select($col, $table, $where = "", $arrWhereVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 150 $sqlse = $this->getSql($col, $table, $where, $arrWhereVal); 151 return $this->getAll($sqlse, $arrWhereVal, $fetchmode); 154 152 } 155 153 … … 279 277 * 構築した SELECT 文を取得する. 280 278 * 279 * クラス変数から WHERE 句を組み立てる場合、$arrWhereVal を経由してプレースホルダもクラス変数のもので上書きする。 281 280 * @param string $col SELECT 文に含めるカラム名 282 281 * @param string $table SELECT 文に含めるテーブル名 283 282 * @param string $where SELECT 文に含める WHERE 句 283 * @param mixed $arrWhereVal プレースホルダ(参照) 284 284 * @return string 構築済みの SELECT 文 285 285 */ 286 function getSql($col, $table, $where = '' ) {286 function getSql($col, $table, $where = '', &$arrWhereVal = null) { 287 287 $sqlse = "SELECT $col FROM $table"; 288 288 … … 292 292 } elseif (strlen($this->where) >= 1) { 293 293 $sqlse .= " WHERE " . $this->where; 294 if (empty($arrWhereVal)) { 295 $arrWhereVal = $this->arrWhereVal; 296 } 294 297 } 295 298 … … 388 391 * この関数で設定した値は SC_Query::getSql() で使用されます. 389 392 * 390 * @param string $str WHERE 句に付与する文字列 393 * @param string $where WHERE 句に付与する文字列 394 * @param mixed $arrWhereVal プレースホルダ 391 395 * @return SC_Query 自分自身のインスタンス 392 396 */ 393 function setWhere($str) { 394 $this->where = $str; 397 function setWhere($where = '', $arrWhereVal = array()) { 398 $this->where = $where; 399 $this->arrWhereVal = $arrWhereVal; 395 400 return $this; 396 401 } … … 489 494 * @param array $sqlval array('カラム名' => '値',...)の連想配列 490 495 * @param string $where WHERE句 491 * @param array $arr ValInWHERE句用のプレースホルダ配列 (従来は追加カラム用も兼ねていた)496 * @param array $arrWhereVal WHERE句用のプレースホルダ配列 (従来は追加カラム用も兼ねていた) 492 497 * @param array $arrRawSql 追加カラム 493 498 * @param array $arrRawSqlVal 追加カラム用のプレースホルダ配列 494 499 * @return 495 500 */ 496 function update($table, $sqlval, $where = "", $arr ValIn= array(), $arrRawSql = array(), $arrRawSqlVal = array()) {501 function update($table, $sqlval, $where = "", $arrWhereVal = array(), $arrRawSql = array(), $arrRawSqlVal = array()) { 497 502 $arrCol = array(); 498 503 $arrVal = array(); … … 528 533 $strcol = implode(', ', $arrCol); 529 534 530 if (is_array($arr ValIn)) { // 旧版との互換用535 if (is_array($arrWhereVal)) { // 旧版との互換用 531 536 // プレースホルダー用に配列を追加 532 $arrVal = array_merge($arrVal, $arr ValIn);537 $arrVal = array_merge($arrVal, $arrWhereVal); 533 538 } 534 539 … … 548 553 * @param string $col カラム名 549 554 * @param string $where 付与する WHERE 句 550 * @param array $arrval ブレースホルダに挿入する値555 * @param array $arrval プレースホルダに挿入する値 551 556 * @return integer MAX文の実行結果 552 557 */ … … 562 567 * @param string $col カラム名 563 568 * @param string $where 付与する WHERE 句 564 * @param array $arrval ブレースホルダに挿入する値569 * @param array $arrval プレースホルダに挿入する値 565 570 * @return integer MIN文の実行結果 566 571 */ … … 576 581 * @param string $col カラム名 577 582 * @param string $where 付与する WHERE 句 578 * @param array $arr val ブレースホルダに挿入する値583 * @param array $arrWhereVal プレースホルダに挿入する値 579 584 * @return mixed SQL の実行結果 580 585 */ 581 function get($col, $table, $where = "", $arr val = array()) {582 $sqlse = $this->getSql($col, $table, $where );586 function get($col, $table, $where = "", $arrWhereVal = array()) { 587 $sqlse = $this->getSql($col, $table, $where, $arrWhereVal); 583 588 // SQL文の実行 584 $ret = $this->getOne($sqlse, $arr val);589 $ret = $this->getOne($sqlse, $arrWhereVal); 585 590 return $ret; 586 591 } … … 590 595 * 591 596 * @param string $sql 実行する SQL 592 * @param array $arrval ブレースホルダに挿入する値597 * @param array $arrval プレースホルダに挿入する値 593 598 * @return mixed SQL の実行結果 594 599 */ … … 616 621 * @param string $col カラム名 617 622 * @param string $where WHERE句 618 * @param array $arr Val プレースホルダ配列623 * @param array $arrWhereVal プレースホルダ配列 619 624 * @param integer $fetchmode 使用するフェッチモード。デフォルトは MDB2_FETCHMODE_ASSOC。 620 625 * @return array array('カラム名' => '値', ...)の連想配列 621 626 */ 622 function getRow($col, $table, $where = "", $arr Val = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) {623 624 $sql = $this->getSql($col, $table, $where );627 function getRow($col, $table, $where = "", $arrWhereVal = array(), $fetchmode = MDB2_FETCHMODE_ASSOC) { 628 629 $sql = $this->getSql($col, $table, $where, $arrWhereVal); 625 630 $sql = $this->dbFactory->sfChangeMySQL($sql); 626 631 … … 630 635 } 631 636 632 $affected =& $this->execute($sth, $arr Val);637 $affected =& $this->execute($sth, $arrWhereVal); 633 638 if (PEAR::isError($affected) && $this->force_run) { 634 639 return; … … 639 644 640 645 /** 641 * SELECT 文の実行結果を 1 行のみ取得する.646 * SELECT 文の実行結果を 1列のみ取得する. 642 647 * 643 648 * @param string $table テーブル名 644 649 * @param string $col カラム名 645 650 * @param string $where 付与する WHERE 句 646 * @param array $arr val ブレースホルダに挿入する値651 * @param array $arrWhereVal プレースホルダに挿入する値 647 652 * @return array SQL の実行結果の配列 648 653 */ 649 function getCol($col, $table, $where = "", $arr val = array()) {650 $sql = $this->getSql($col, $table, $where );654 function getCol($col, $table, $where = "", $arrWhereVal = array()) { 655 $sql = $this->getSql($col, $table, $where, $arrWhereVal); 651 656 $sql = $this->dbFactory->sfChangeMySQL($sql); 652 657 … … 656 661 } 657 662 658 $affected =& $this->execute($sth, $arr val);663 $affected =& $this->execute($sth, $arrWhereVal); 659 664 if (PEAR::isError($affected) && $this->force_run) { 660 665 return; … … 722 727 * 723 728 * @param string $n 実行する SQL 文 724 * @param array $arr ブレースホルダに挿入する値729 * @param array $arr プレースホルダに挿入する値 725 730 * @param boolean $ignore_err MDB2切替で無効化されている (エラーが発生しても処理を続行する場合 true) 726 731 * @param mixed $types プレースホルダの型指定 デフォルトnull = string … … 830 835 * 831 836 * TODO MDB2 に対応するための暫定的な措置. 832 * ブレースホルダが使用できない実装があるため.837 * プレースホルダが使用できない実装があるため. 833 838 * 本来であれば, MDB2::prepare() を適切に使用するべき 834 839 * … … 845 850 * 846 851 * @param string $table テーブル名 847 * @param array ブレースホルダの連想配列852 * @param array プレースホルダの連想配列 848 853 * @return array テーブルに存在する列のみ抽出した連想配列 849 854 */ … … 885 890 * @access private 886 891 * @param MDB2_Statement_Common プリペアドステートメントインスタンス 887 * @param array $arrVal ブレースホルダに挿入する配列892 * @param array $arrVal プレースホルダに挿入する配列 888 893 * @return MDB2_Result 結果セットのインスタンス 889 894 */ 890 895 function execute(&$sth, $arrVal = array()) { 891 896 $timeStart = SC_Utils_Ex::sfMicrotimeFloat(); 892 $affected =& $sth->execute( $arrVal);897 $affected =& $sth->execute((array)$arrVal); 893 898 894 899 // 一定以上時間かかったSQLの場合、ログ出力する。 … … 947 952 * 948 953 * @param string $n 実行する SQL 文 949 * @param array $arr ブレースホルダに挿入する値954 * @param array $arr プレースホルダに挿入する値 950 955 * @param boolean エラーが発生しても処理を続行する場合 true 951 956 * @param mixed $types プレースホルダの型指定 デフォルトnull = string -
branches/version-2_11-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_RecommendSearch.php
r21250 r21256 213 213 214 214 /** 215 * 商品取得 215 216 * 216 * 商品取得 217 * @param array $arrProduct_id 217 * @param array $arrProductId 218 218 * @param SC_Product $objProduct 219 219 */ 220 function getProductList($arrProduct_id,&$objProduct){ 221 $where = ""; 222 if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 223 $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')'; 224 } else { 225 // 一致させない 226 $where = '0<>0'; 227 } 220 function getProductList($arrProductId, &$objProduct){ 228 221 $objQuery =& SC_Query_Ex::getSingletonInstance(); 229 $objQuery->setWhere($where); 222 230 223 // 表示順序 231 224 $order = "update_date DESC, product_id DESC"; 232 225 $objQuery->setOrder($order); 233 return $objProduct->lists($objQuery, $arrProduct_id); 226 227 return $objProduct->getListByProductIds($objQuery, $arrProductId); 234 228 } 235 229 } -
branches/version-2_11-dev/data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php
r20970 r21256 125 125 126 126 /** 127 * 商品取得 127 128 * 128 * 商品取得 129 * @param array $arrProduct_id 130 * @param SC_Product $objProduct 131 */ 132 function getProductList($arrProduct_id,&$objProduct){ 133 $where = ""; 134 if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 135 $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')'; 136 } else { 137 // 一致させない 138 $where = '0<>0'; 139 } 129 * @param array $arrProductId 130 * @param SC_Product $objProduct 131 */ 132 function getProductList($arrProductId, &$objProduct){ 140 133 $objQuery =& SC_Query_Ex::getSingletonInstance(); 141 $objQuery->setWhere($where); 142 return $objProduct->lists($objQuery, $arrProduct_id); 134 135 // 表示順序 136 $order = "update_date DESC, product_id DESC"; 137 $objQuery->setOrder($order); 138 139 return $objProduct->getListByProductIds($objQuery, $arrProductId); 143 140 } 144 141 -
branches/version-2_11-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend.php
r21215 r21256 101 101 // 商品一覧を取得 102 102 // where条件生成&セット 103 $arr BestProductIds= array();103 $arrProductId = array(); 104 104 $where = 'product_id IN ('; 105 105 foreach ($arrBestProducts as $key => $val) { 106 $arr BestProductIds[] = $val['product_id'];106 $arrProductId[] = $val['product_id']; 107 107 } 108 $where .= implode(', ', $arrBestProductIds);109 $where .= ')';110 $where .= ' AND del_flg = 0'; // 商品規格の削除フラグ111 $objQuery->setWhere($where);112 108 // 取得 113 $arrTmp = $objProduct-> lists($objQuery);109 $arrTmp = $objProduct->getListByProductIds($objQuery, $arrProductId); 114 110 foreach ($arrTmp as $key => $arrRow) { 115 111 $arrProductList[$arrRow['product_id']] = $arrRow; -
branches/version-2_11-dev/data/class/pages/mypage/LC_Page_Mypage_Favorite.php
r21255 r21256 121 121 122 122 $objQuery->setOrder('create_date DESC'); 123 $arrProduct _id = $objQuery->getCol('product_id', 'dtb_customer_favorite_products', 'customer_id = ?', array($customer_id));123 $arrProductId = $objQuery->getCol('product_id', 'dtb_customer_favorite_products', 'customer_id = ?', array($customer_id)); 124 124 125 125 $objQuery =& SC_Query_Ex::getSingletonInstance(); 126 $objQuery->setWhere($this->lfMakeWhere('alldtl.', $arrProduct _id));126 $objQuery->setWhere($this->lfMakeWhere('alldtl.', $arrProductId)); 127 127 $linemax = $objProduct->findProductCount($objQuery); 128 128 … … 137 137 //$objQuery->setLimitOffset(SEARCH_PMAX, $startno); 138 138 // 取得範囲の指定(開始行番号、行数のセット) 139 $arrProduct _id = array_slice($arrProduct_id, $startno, SEARCH_PMAX);139 $arrProductId = array_slice($arrProductId, $startno, SEARCH_PMAX); 140 140 141 $where = $this->lfMakeWhere('', $arrProduct _id);141 $where = $this->lfMakeWhere('', $arrProductId); 142 142 $where .= ' AND del_flg = 0'; 143 $objQuery->setWhere($where );144 $arrProducts = $objProduct->lists($objQuery , $arrProduct_id);143 $objQuery->setWhere($where, $arrProductId); 144 $arrProducts = $objProduct->lists($objQuery); 145 145 146 146 //取得している並び順で並び替え … … 150 150 } 151 151 $arrProductsList = array(); 152 foreach($arrProduct _id as $product_id) {152 foreach($arrProductId as $product_id) { 153 153 $arrProductsList[] = $arrProducts2[$product_id]; 154 154 } … … 158 158 159 159 /* 仕方がない処理。。 */ 160 function lfMakeWhere ($tablename, $arrProduct _id) {160 function lfMakeWhere ($tablename, $arrProductId) { 161 161 162 162 // 取得した表示すべきIDだけを指定して情報を取得。 163 163 $where = ""; 164 if (is_array($arrProduct _id) && !empty($arrProduct_id)) {165 $where = $tablename . 'product_id IN (' . implode(',', $arrProduct _id) . ')';164 if (is_array($arrProductId) && !empty($arrProductId)) { 165 $where = $tablename . 'product_id IN (' . implode(',', $arrProductId) . ')'; 166 166 } else { 167 167 // 一致させない -
branches/version-2_11-dev/data/class/pages/products/LC_Page_Products_Detail.php
r21230 r21256 409 409 /* 登録済み関連商品の読み込み */ 410 410 function lfPreGetRecommendProducts($product_id) { 411 $ arrRecommend = array();411 $objProduct = new SC_Product_Ex(); 412 412 $objQuery =& SC_Query_Ex::getSingletonInstance(); 413 413 414 $objQuery->setOrder("rank DESC"); 414 415 $arrRecommendData = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id)); … … 420 421 } 421 422 422 $objProduct = new SC_Product_Ex();423 424 $where = "";425 if (!empty($arrRecommendProductId)) {426 $where = 'product_id IN (' . implode(',', $arrRecommendProductId) . ')';427 } else {428 return $arrRecommend;429 }430 423 $objQuery =& SC_Query_Ex::getSingletonInstance(); 431 $objQuery->setWhere($where); 432 $arrProducts = $objProduct->lists($objQuery, $arrRecommendProductId); 424 $arrProducts = $objProduct->getListByProductIds($objQuery, $arrRecommendProductId); 433 425 434 426 //取得している並び順で並び替え … … 438 430 $arrProducts2[ $item['product_id'] ] = $item; 439 431 } 440 $arrProducts = array(); 432 433 $arrRecommend = array(); 441 434 foreach($arrRecommendProductId as $product_id) { 442 435 $arrProducts2[$product_id]['comment'] = $arrRecommendData[$product_id]; -
branches/version-2_11-dev/data/class/pages/products/LC_Page_Products_List.php
r21213 r21256 304 304 305 305 // 表示すべきIDとそのIDの並び順を一気に取得 306 $arrProduct_id = $objProduct->findProductIdsOrder($objQuery, array_merge($searchCondition['arrval'], $arrval_order)); 307 308 // 取得した表示すべきIDだけを指定して情報を取得。 309 $where = ""; 310 if (is_array($arrProduct_id) && !empty($arrProduct_id)) { 311 $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')'; 312 } else { 313 // 一致させない 314 $where = '0<>0'; 315 } 316 317 $where .= ' AND del_flg = 0'; // 商品規格の削除フラグ 306 $arrProductId = $objProduct->findProductIdsOrder($objQuery, array_merge($searchCondition['arrval'], $arrval_order)); 307 318 308 $objQuery =& SC_Query_Ex::getSingletonInstance(); 319 $objQuery->setWhere($where); 320 $arrProducts = $objProduct->lists($objQuery, $arrProduct_id); 309 $arrProducts = $objProduct->getListByProductIds($objQuery, $arrProductId); 321 310 322 311 //取得している並び順で並び替え … … 326 315 } 327 316 $arrProducts = array(); 328 foreach($arrProduct _id as $product_id) {317 foreach($arrProductId as $product_id) { 329 318 $arrProducts[] = $arrProducts2[$product_id]; 330 319 } 331 320 332 321 // 規格を設定 333 $objProduct->setProductsClassByProductIds($arrProduct _id);334 $arrProducts += array('productStatus' => $objProduct->getProductStatus($arrProduct _id));322 $objProduct->setProductsClassByProductIds($arrProductId); 323 $arrProducts += array('productStatus' => $objProduct->getProductStatus($arrProductId)); 335 324 return $arrProducts; 336 325 } -
branches/version-2_11-dev/data/class/pages/rss/LC_Page_Rss_Products.php
r20976 r21256 244 244 */ 245 245 function lfGetProductsDetail(&$objQuery, $product_id = 'all'){ 246 $objProduct = new SC_Product_Ex(); 247 246 248 // --- 商品詳細の取得 247 if ($product_id != 'all') {248 $ where = 'product_id = ' . $product_id;249 $ objQuery->setWhere($where);250 } 251 $objQuery->setOrder('product_id');252 $objProduct = new SC_Product_Ex();253 $arrProductLsit = $objProduct->lists($objQuery); 249 if ($product_id == 'all') { 250 $objQuery->setOrder('product_id'); 251 $arrProductLsit = $objProduct->lists($objQuery); 252 } else { 253 $arrProductLsit = $objProduct->getListByProductIds($objQuery, $product_id); 254 } 255 254 256 // 各商品のカテゴリIDとランクの取得 255 257 $arrProduct = array();
Note: See TracChangeset
for help on using the changeset viewer.