- Timestamp:
- 2012/02/06 11:05:15 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php
r21425 r21441 74 74 75 75 // 正常に接続されている場合 76 if (!$objQuery->isError()) {76 if (!$objQuery->isError()) { 77 77 list($db_type) = explode(":", $dsn); 78 78 … … 80 80 $columns = $objQuery->listTableFields($table_name); 81 81 82 if (in_array($col_name, $columns)){82 if (in_array($col_name, $columns)) { 83 83 return true; 84 84 } … … 86 86 87 87 // カラムを追加する 88 if ($add){88 if ($add) { 89 89 $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type "); 90 90 return true; … … 112 112 113 113 // データを追加する 114 if (!$exists && $add) {114 if (!$exists && $add) { 115 115 $objQuery->exec($sql); 116 116 } … … 175 175 function sfGetRootId() { 176 176 177 if (!$this->g_root_on){177 if (!$this->g_root_on) { 178 178 $this->g_root_on = true; 179 179 $objQuery =& SC_Query_Ex::getSingletonInstance(); … … 182 182 if (!isset($_GET['category_id'])) $_GET['category_id'] = ""; 183 183 184 if (!empty($_GET['product_id']) || !empty($_GET['category_id'])) {184 if (!empty($_GET['product_id']) || !empty($_GET['category_id'])) { 185 185 // 選択中のカテゴリIDを判定する 186 186 $category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']); 187 187 // ROOTカテゴリIDの取得 188 if (count($category_id) > 0) {188 if (count($category_id) > 0) { 189 189 $arrRet = $this->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $category_id); 190 190 $root_id = isset($arrRet[0]) ? $arrRet[0] : ""; … … 214 214 $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id)); 215 215 $customer_id = $arrRet[0]['customer_id']; 216 if ($customer_id != "" && $customer_id >= 1) {216 if ($customer_id != "" && $customer_id >= 1) { 217 217 $arrRet = $objQuery->select('point', "dtb_customer", "customer_id = ?", array($customer_id)); 218 218 $point = $arrRet[0]['point']; … … 257 257 $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; 258 258 // 登録商品数のチェック 259 if ($count_check) {259 if ($count_check) { 260 260 $where = "del_flg = 0 AND product_count > 0"; 261 261 } else { … … 267 267 $arrParentID = SC_Helper_DB_Ex::sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 268 268 269 foreach ($arrRet as $key => $array) {270 foreach ($arrParentID as $val) {271 if ($array['category_id'] == $val) {269 foreach ($arrRet as $key => $array) { 270 foreach ($arrParentID as $val) { 271 if ($array['category_id'] == $val) { 272 272 $arrRet[$key]['display'] = 1; 273 273 break; … … 325 325 $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; 326 326 // 登録商品数のチェック 327 if ($count_check) {327 if ($count_check) { 328 328 $where = "del_flg = 0 AND product_count > 0"; 329 329 } else { … … 339 339 $arrParentID = SC_Helper_DB_Ex::sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 340 340 341 foreach ($arrParentID as $pid) {342 foreach ($arrRet as $key => $array) {343 if ($array['category_id'] == $pid) {341 foreach ($arrParentID as $pid) { 342 foreach ($arrRet as $key => $array) { 343 if ($array['category_id'] == $pid) { 344 344 $arrCatTree[$pkey][] = $arrRet[$key]; 345 345 break; … … 365 365 366 366 // カテゴリ名称を取得する 367 foreach ($arrCatID as $key => $val){367 foreach ($arrCatID as $key => $val) { 368 368 $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; 369 369 $arrVal = array($val); … … 428 428 $where = "del_flg = 0"; 429 429 430 if ($addwhere != "") {430 if ($addwhere != "") { 431 431 $where.= " AND $addwhere"; 432 432 } … … 434 434 $objQuery->setOption("ORDER BY rank DESC"); 435 435 436 if ($products_check) {436 if ($products_check) { 437 437 $col = "T1.category_id, category_name, level"; 438 438 $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id"; … … 446 446 447 447 $max = count($arrRet); 448 for ($cnt = 0; $cnt < $max; $cnt++) {448 for ($cnt = 0; $cnt < $max; $cnt++) { 449 449 $id = $arrRet[$cnt]['category_id']; 450 450 $name = $arrRet[$cnt]['category_name']; … … 484 484 $max = count($arrRet); 485 485 486 for ($cnt = 0; $cnt < $max; $cnt++) {487 if ($parent_zero) {488 if ($arrRet[$cnt]['level'] == LEVEL_MAX) {486 for ($cnt = 0; $cnt < $max; $cnt++) { 487 if ($parent_zero) { 488 if ($arrRet[$cnt]['level'] == LEVEL_MAX) { 489 489 $arrValue[$cnt] = $arrRet[$cnt]['category_id']; 490 490 } else { … … 651 651 $objProduct = new SC_Product_Ex(); 652 652 653 if ($objQuery == NULL) {653 if ($objQuery == NULL) { 654 654 $objQuery =& SC_Query_Ex::getSingletonInstance(); 655 655 } 656 656 657 657 $is_out_trans = false; 658 if (!$objQuery->inTransaction()){658 if (!$objQuery->inTransaction()) { 659 659 $objQuery->begin(); 660 660 $is_out_trans = true; … … 667 667 $where_products_class = '(stock >= 1 OR stock_unlimited = 1)'; 668 668 $from = $objProduct->alldtlSQL($where_products_class); 669 } else{669 } else { 670 670 $from = 'dtb_products as alldtl'; 671 671 } … … 675 675 676 676 //まずテーブル内容の元を取得 677 if (!$is_force_all_count) {677 if (!$is_force_all_count) { 678 678 $arrCategoryCountOld = $objQuery->select('category_id,product_count','dtb_category_count'); 679 } else{679 } else { 680 680 $arrCategoryCountOld = array(); 681 681 } … … 700 700 //古いデータの構造入れ替え 701 701 $arrOld = array(); 702 foreach ($arrCategoryCountOld as $item){702 foreach ($arrCategoryCountOld as $item) { 703 703 $arrOld[$item['category_id']] = $item['product_count']; 704 704 } 705 705 //新しいデータの構造入れ替え 706 706 $arrNew = array(); 707 foreach ($arrCategoryCountNew as $item){707 foreach ($arrCategoryCountNew as $item) { 708 708 $arrNew[$item['category_id']] = $item['product_count']; 709 709 } … … 711 711 $arrDiffCategory_id = array(); 712 712 //新しいカテゴリ一覧から見て商品数が異なるデータが無いか確認 713 foreach ($arrNew as $cid => $count){714 if ($arrOld[$cid] != $count){713 foreach ($arrNew as $cid => $count) { 714 if ($arrOld[$cid] != $count) { 715 715 $arrDiffCategory_id[] = $cid; 716 716 } 717 717 } 718 718 //削除カテゴリを想定して、古いカテゴリ一覧から見て商品数が異なるデータが無いか確認。 719 foreach ($arrOld as $cid => $count){720 if ($arrNew[$cid] != $count && $count > 0){719 foreach ($arrOld as $cid => $count) { 720 if ($arrNew[$cid] != $count && $count > 0) { 721 721 $arrDiffCategory_id[] = $cid; 722 722 } … … 724 724 725 725 //対象IDが無ければ終了 726 if (count($arrDiffCategory_id) == 0){727 if ($is_out_trans) {726 if (count($arrDiffCategory_id) == 0) { 727 if ($is_out_trans) { 728 728 $objQuery->commit(); 729 729 } … … 735 735 736 736 //dtb_category_countの更新 差分のあったカテゴリだけ更新する。 737 foreach ($arrDiffCategory_id as $cid) {737 foreach ($arrDiffCategory_id as $cid) { 738 738 $sqlval = array(); 739 739 $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; 740 740 $sqlval['product_count'] = (string)$arrNew[$cid]; 741 if ($sqlval['product_count'] =="") {741 if ($sqlval['product_count'] =="") { 742 742 $sqlval['product_count'] = (string)'0'; 743 743 } 744 if (isset($arrOld[$cid])) {744 if (isset($arrOld[$cid])) { 745 745 $objQuery->update('dtb_category_count', $sqlval, 'category_id = ?', array($cid)); 746 } else{746 } else { 747 747 if ($is_force_all_count) { 748 748 $ret = $objQuery->update('dtb_category_count', $sqlval, 'category_id = ?', array($cid)); … … 791 791 } 792 792 // 更新対象だけを更新。 793 foreach ($arrUpdateData as $cid => $count) {793 foreach ($arrUpdateData as $cid => $count) { 794 794 $sqlval = array(); 795 795 $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; 796 796 $sqlval['product_count'] = $count; 797 if ($sqlval['product_count'] =="") {797 if ($sqlval['product_count'] =="") { 798 798 $sqlval['product_count'] = (string)'0'; 799 799 } 800 800 $ret = $objQuery->update('dtb_category_total_count', $sqlval, 'category_id = ?', array($cid)); 801 if (!$ret) {801 if (!$ret) { 802 802 $sqlval['category_id'] = $cid; 803 803 $ret = $objQuery->insert('dtb_category_total_count', $sqlval); … … 805 805 } 806 806 // トランザクション終了処理 807 if ($is_out_trans) {807 if ($is_out_trans) { 808 808 $objQuery->commit(); 809 809 } … … 837 837 $arrRet = array($id); 838 838 839 while (count($arrRet) > 0) {839 while (count($arrRet) > 0) { 840 840 $arrChildren = array_merge($arrChildren, $arrRet); 841 841 $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($table, $pid_name, $id_name, $arrRet); … … 897 897 $ret = $id; 898 898 899 while ($ret != "0" && !SC_Utils_Ex::isBlank($ret)) {899 while ($ret != "0" && !SC_Utils_Ex::isBlank($ret)) { 900 900 $arrParents[] = $ret; 901 901 $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($table, $pid_name, $id_name, $ret); … … 909 909 /* 子ID所属する親IDを取得する */ 910 910 function sfGetParentsArraySub($table, $pid_name, $id_name, $child) { 911 if (SC_Utils_Ex::isBlank($child)) {911 if (SC_Utils_Ex::isBlank($child)) { 912 912 return false; 913 913 } 914 914 $objQuery =& SC_Query_Ex::getSingletonInstance(); 915 if (!is_array($child)) {915 if (!is_array($child)) { 916 916 $child = array($child); 917 917 } … … 952 952 $arrList = $objQuery->select($col, $table, $where, $arrVal); 953 953 $count = count($arrList); 954 for ($cnt = 0; $cnt < $count; $cnt++) {954 for ($cnt = 0; $cnt < $count; $cnt++) { 955 955 $key = $arrList[$cnt][$keyname]; 956 956 $val = $arrList[$cnt][$valname]; … … 973 973 $objQuery->begin(); 974 974 $where = "$colname = ?"; 975 if ($andwhere != "") {975 if ($andwhere != "") { 976 976 $where.= " AND $andwhere"; 977 977 } … … 981 981 $maxrank = $objQuery->max('rank', $table, $andwhere); 982 982 // ランクが最大値よりも小さい場合に実行する。 983 if ($rank < $maxrank) {983 if ($rank < $maxrank) { 984 984 // ランクが一つ上のIDを取得する。 985 985 $where = "rank = ?"; 986 if ($andwhere != "") {986 if ($andwhere != "") { 987 987 $where.= " AND $andwhere"; 988 988 } … … 991 991 // ランク入れ替えの実行 992 992 $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; 993 if ($andwhere != "") {993 if ($andwhere != "") { 994 994 $sqlup.= " AND $andwhere"; 995 995 } … … 1013 1013 $objQuery->begin(); 1014 1014 $where = "$colname = ?"; 1015 if ($andwhere != "") {1015 if ($andwhere != "") { 1016 1016 $where.= " AND $andwhere"; 1017 1017 } … … 1020 1020 1021 1021 // ランクが1(最小値)よりも大きい場合に実行する。 1022 if ($rank > 1) {1022 if ($rank > 1) { 1023 1023 // ランクが一つ下のIDを取得する。 1024 1024 $where = "rank = ?"; 1025 if ($andwhere != "") {1025 if ($andwhere != "") { 1026 1026 $where.= " AND $andwhere"; 1027 1027 } … … 1030 1030 // ランク入れ替えの実行 1031 1031 $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; 1032 if ($andwhere != "") {1032 if ($andwhere != "") { 1033 1033 $sqlup.= " AND $andwhere"; 1034 1034 } … … 1054 1054 1055 1055 // 自身のランクを取得する 1056 if ($where != "") {1056 if ($where != "") { 1057 1057 $getWhere = "$keyIdColumn = ? AND " . $where; 1058 1058 } else { … … 1064 1064 1065 1065 // 値の調整(逆順) 1066 if ($pos > $max) {1066 if ($pos > $max) { 1067 1067 $position = 1; 1068 } else if ($pos < 1) {1068 } else if ($pos < 1) { 1069 1069 $position = $max; 1070 1070 } else { … … 1083 1083 // 指定した順位の商品から移動させる商品までのrankを1つずらす 1084 1084 $sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?"; 1085 if ($where != "") {1085 if ($where != "") { 1086 1086 $sql.= " AND $where"; 1087 1087 } … … 1092 1092 // 指定した順位へrankを書き換える。 1093 1093 $sql = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? "; 1094 if ($where != "") {1094 if ($where != "") { 1095 1095 $sql.= " AND $where"; 1096 1096 } … … 1119 1119 // 削除レコードのランクを取得する。 1120 1120 $where = "$colname = ?"; 1121 if ($andwhere != "") {1121 if ($andwhere != "") { 1122 1122 $where.= " AND $andwhere"; 1123 1123 } 1124 1124 $rank = $objQuery->get('rank', $table, $where, array($id)); 1125 1125 1126 if (!$delete) {1126 if (!$delete) { 1127 1127 // ランクを最下位にする、DELフラグON 1128 1128 $sqlup = "UPDATE $table SET rank = 0, del_flg = 1 "; … … 1136 1136 // 追加レコードのランクより上のレコードを一つずらす。 1137 1137 $where = "rank > ?"; 1138 if ($andwhere != "") {1138 if ($andwhere != "") { 1139 1139 $where.= " AND $andwhere"; 1140 1140 } … … 1159 1159 $where = ""; 1160 1160 1161 for ($cnt = 0; $cnt < $len; $cnt++) {1162 if ($where == "") {1161 for ($cnt = 0; $cnt < $len; $cnt++) { 1162 if ($where == "") { 1163 1163 $where = "$id_name = ?"; 1164 1164 } else { … … 1249 1249 $where = "del_flg = 0"; 1250 1250 1251 if ($addwhere != "") {1251 if ($addwhere != "") { 1252 1252 $where.= " AND $addwhere"; 1253 1253 } 1254 1254 1255 foreach ($arrCol as $val) {1256 if ($val != "") {1257 if ($where == "") {1255 foreach ($arrCol as $val) { 1256 if ($val != "") { 1257 if ($where == "") { 1258 1258 $where = "$val = ?"; 1259 1259 } else { … … 1264 1264 $ret = $objQuery->get($col, $table, $where, $arrval); 1265 1265 1266 if ($ret != "") {1266 if ($ret != "") { 1267 1267 return true; 1268 1268 } … … 1339 1339 $where = "del_flg = 0"; 1340 1340 1341 if ($addwhere != "") {1341 if ($addwhere != "") { 1342 1342 $where.= " AND $addwhere"; 1343 1343 } … … 1345 1345 $objQuery->setOption("ORDER BY rank DESC"); 1346 1346 1347 if ($products_check) {1347 if ($products_check) { 1348 1348 $col = "T1.maker_id, name"; 1349 1349 $from = "dtb_maker AS T1 LEFT JOIN dtb_maker_count AS T2 ON T1.maker_id = T2.maker_id"; … … 1357 1357 1358 1358 $max = count($arrRet); 1359 for ($cnt = 0; $cnt < $max; $cnt++) {1359 for ($cnt = 0; $cnt < $max; $cnt++) { 1360 1360 $id = $arrRet[$cnt]['maker_id']; 1361 1361 $name = $arrRet[$cnt]['name'];
Note: See TracChangeset
for help on using the changeset viewer.
