- Timestamp:
- 2012/08/30 14:15:56 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php
r21927 r22012 985 985 $uprank = $rank + 1; 986 986 $up_id = $objQuery->get($colname, $table, $where, array($uprank)); 987 987 988 // ランク入れ替えの実行 988 $ sqlup = "UPDATE $table SET rank = ? WHERE$colname = ?";989 $where = "$colname = ?"; 989 990 if ($andwhere != '') { 990 $sqlup.= " AND $andwhere"; 991 } 992 $objQuery->exec($sqlup, array($rank + 1, $id)); 993 $objQuery->exec($sqlup, array($rank, $up_id)); 991 $where .= " AND $andwhere"; 992 } 993 994 $sqlval = array( 995 'rank' => $rank + 1, 996 ); 997 $arrWhereVal = array($id); 998 $objQuery->update($table, $sqlval, $where, $arrWhereVal); 999 1000 $sqlval = array( 1001 'rank' => $rank, 1002 ); 1003 $arrWhereVal = array($up_id); 1004 $objQuery->update($table, $sqlval, $where, $arrWhereVal); 994 1005 } 995 1006 $objQuery->commit(); … … 1024 1035 $downrank = $rank - 1; 1025 1036 $down_id = $objQuery->get($colname, $table, $where, array($downrank)); 1037 1026 1038 // ランク入れ替えの実行 1027 $ sqlup = "UPDATE $table SET rank = ? WHERE$colname = ?";1039 $where = "$colname = ?"; 1028 1040 if ($andwhere != '') { 1029 $sqlup.= " AND $andwhere"; 1030 } 1031 $objQuery->exec($sqlup, array($rank - 1, $id)); 1032 $objQuery->exec($sqlup, array($rank, $down_id)); 1041 $where .= " AND $andwhere"; 1042 } 1043 1044 $sqlval = array( 1045 'rank' => $rank - 1, 1046 ); 1047 $arrWhereVal = array($id); 1048 $objQuery->update($table, $sqlval, $where, $arrWhereVal); 1049 1050 $sqlval = array( 1051 'rank' => $rank, 1052 ); 1053 $arrWhereVal = array($down_id); 1054 $objQuery->update($table, $sqlval, $where, $arrWhereVal); 1033 1055 } 1034 1056 $objQuery->commit(); … … 1078 1100 1079 1101 // 指定した順位の商品から移動させる商品までのrankを1つずらす 1080 $sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?"; 1102 $sqlval = array(); 1103 $arrRawSql = array( 1104 'rank' => $term, 1105 ); 1106 $str_where = 'rank BETWEEN ? AND ?'; 1081 1107 if ($where != '') { 1082 $sql.= " AND $where"; 1083 } 1084 1085 if ($position > $rank) $objQuery->exec($sql, array($rank + 1, $position)); 1086 if ($position < $rank) $objQuery->exec($sql, array($position, $rank - 1)); 1108 $str_where .= " AND $where"; 1109 } 1110 1111 if ($position > $rank) { 1112 $arrWhereVal = array($rank + 1, $position); 1113 $objQuery->update($tableName, $sqlval, $str_where, $arrWhereVal, $arrRawSql); 1114 } 1115 if ($position < $rank) { 1116 $arrWhereVal = array($position, $rank - 1); 1117 $objQuery->update($tableName, $sqlval, $str_where, $arrWhereVal, $arrRawSql); 1118 } 1087 1119 1088 1120 // 指定した順位へrankを書き換える。 1089 $sql = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? "; 1121 $sqlval = array( 1122 'rank' => $position, 1123 ); 1124 $str_where = "$keyIdColumn = ?"; 1090 1125 if ($where != '') { 1091 $sql.= " AND $where"; 1092 } 1093 1094 $objQuery->exec($sql, array($position, $keyId)); 1126 $str_where .= " AND $where"; 1127 } 1128 $arrWhereVal = array($keyId); 1129 $objQuery->update($tableName, $sqlval, $str_where, $arrWhereVal); 1130 1095 1131 $objQuery->commit(); 1096 1132 } … … 1122 1158 if (!$delete) { 1123 1159 // ランクを最下位にする、DELフラグON 1124 $sqlup = "UPDATE $table SET rank = 0, del_flg = 1 "; 1125 $sqlup.= "WHERE $colname = ?"; 1126 // UPDATEの実行 1127 $objQuery->exec($sqlup, array($id)); 1160 $sqlval = array( 1161 'rank' => 0, 1162 'del_flg' => 1, 1163 ); 1164 $where = "$colname = ?"; 1165 $arrWhereVal = array($id); 1166 $objQuery->update($table, $sqlval, $where, $arrWhereVal); 1128 1167 } else { 1129 1168 $objQuery->delete($table, "$colname = ?", array($id)); … … 1131 1170 1132 1171 // 追加レコードのランクより上のレコードを一つずらす。 1172 $sqlval = array(); 1133 1173 $where = 'rank > ?'; 1134 1174 if ($andwhere != '') { 1135 $where.= " AND $andwhere"; 1136 } 1137 $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; 1138 $objQuery->exec($sqlup, array($rank)); 1175 $where .= " AND $andwhere"; 1176 } 1177 $arrWhereVal = array($rank); 1178 $arrRawSql = array( 1179 'rank' => '(rank - 1)', 1180 ); 1181 $objQuery->update($table, $sqlval, $where, $arrWhereVal, $arrRawSql); 1182 1139 1183 $objQuery->commit(); 1140 1184 } … … 1170 1214 /** 1171 1215 * カテゴリ変更時の移動処理を行う. 1216 * 1217 * ※この関数って、どこからも呼ばれていないのでは?? 1172 1218 * 1173 1219 * @param SC_Query $objQuery SC_Query インスタンス … … 1186 1232 // 旧カテゴリでのランク削除処理 1187 1233 // 移動レコードのランクを取得する。 1234 $sqlval = array(); 1188 1235 $where = "$id_name = ?"; 1189 1236 $rank = $objQuery->get('rank', $table, $where, array($id)); 1190 1237 // 削除レコードのランクより上のレコードを一つ下にずらす。 1191 1238 $where = "rank > ? AND $cat_name = ?"; 1192 $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; 1193 $objQuery->exec($sqlup, array($rank, $old_catid)); 1239 $arrWhereVal = array($rank, $old_catid); 1240 $arrRawSql = array( 1241 'rank' => '(rank - 1)', 1242 ); 1243 $objQuery->update($table, $sqlval, $where, $arrWhereVal, $arrRawSql); 1244 1194 1245 // 新カテゴリでの登録処理 1195 1246 // 新カテゴリの最大ランクを取得する。 1196 1247 $max_rank = $objQuery->max('rank', $table, "$cat_name = ?", array($new_catid)) + 1; 1248 $sqlval = array( 1249 'rank' => $max_rank, 1250 ); 1197 1251 $where = "$id_name = ?"; 1198 $ sqlup = "UPDATE $table SET rank = ? WHERE $where";1199 $objQuery-> exec($sqlup, array($max_rank, $id));1252 $arrWhereVal = array($id); 1253 $objQuery->update($table, $sqlval, $where, $arrWhereVal); 1200 1254 } 1201 1255
Note: See TracChangeset
for help on using the changeset viewer.