Changeset 23436
- Timestamp:
- 2014/05/21 12:33:38 (9 years ago)
- Location:
- branches/version-2_13-dev/data/class
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/class/helper/SC_Helper_Category.php
r23435 r23436 105 105 * カテゴリーツリーの取得. 106 106 * 107 * @return type107 * @return array 108 108 */ 109 109 public function getTree() … … 139 139 * @return array 140 140 */ 141 public function getTreeBranch($category_id) { 141 public function getTreeBranch($category_id) 142 { 142 143 $arrTree = $this->getTree(); 143 144 $arrTrail = $this->getTreeTrail($category_id, true); … … 163 164 * @return void 164 165 */ 165 public function delete($category_id) { 166 public function delete($category_id) 167 { 166 168 $objDb = new SC_Helper_DB_Ex(); 167 169 // ランク付きレコードの削除(※処理負荷を考慮してレコードごと削除する。) 168 170 $objDb->sfDeleteRankRecord('dtb_category', 'category_id', $category_id, '', true); 169 171 } 172 173 /** 174 * カテゴリーの表示順をひとつ上げる. 175 * 176 * @param int $category_id カテゴリーID 177 * @return void 178 */ 179 public function rankUp($category_id) 180 { 181 $objQuery =& SC_Query_Ex::getSingletonInstance(); 182 $objQuery->begin(); 183 $up_id = $this->getNeighborRankId('upper', $category_id); 184 if ($up_id != '') { 185 // 上のグループのrankから減算する数 186 $my_count = $this->countAllBranches($category_id); 187 // 自分のグループのrankに加算する数 188 $up_count = $this->countAllBranches($up_id); 189 if ($my_count > 0 && $up_count > 0) { 190 // 自分のグループに加算 191 $this->raiseBranchRank($objQuery, $category_id, $up_count); 192 // 上のグループから減算 193 $this->reduceBranchRank($objQuery, $up_id, $my_count); 194 } 195 } 196 $objQuery->commit(); 197 } 198 199 /** 200 * カテゴリーの表示順をひとつ下げる. 201 * 202 * @param int $category_id カテゴリーID 203 * @return void 204 */ 205 public function rankDown($category_id) 206 { 207 $objQuery =& SC_Query_Ex::getSingletonInstance(); 208 $objQuery->begin(); 209 $down_id = $this->getNeighborRankId('lower', $category_id); 210 if ($down_id != '') { 211 // 下のグループのrankに加算する数 212 $my_count = $this->countAllBranches($category_id); 213 // 自分のグループのrankから減算する数 214 $down_count = $this->countAllBranches($down_id); 215 if ($my_count > 0 && $down_count > 0) { 216 // 自分のグループから減算 217 $this->raiseBranchRank($objQuery, $down_id, $my_count); 218 // 下のグループに加算 219 $this->reduceBranchRank($objQuery, $category_id, $down_count); 220 } 221 } 222 $objQuery->commit(); 223 } 224 225 /** 226 * 並びがとなりのIDを取得する。 227 * 228 * @param string $side 上 upper か下 down か 229 * @param int $category_id カテゴリーID 230 * @return int 231 */ 232 private function getNeighborRankId($side, $category_id) 233 { 234 $arrCategory = $this->get($category_id); 235 $parent_id = $arrCategory['parent_category_id']; 236 237 if ($parent_id == 0) { 238 $arrBrother = $this->getTree(); 239 } else { 240 $arrBrother = $this->getTreeBranch($parent_id); 241 } 242 243 // 全ての子を取得する。 244 $max = count($arrBrother); 245 $upper_id = ''; 246 for ($cnt = 0; $cnt < $max; $cnt++) { 247 if ($arrBrother[$cnt]['category_id'] == $category_id) { 248 if ($side == 'upper') { 249 $index = $cnt - 1; 250 } else { 251 $index = $cnt + 1; 252 } 253 $upper_id = $arrBrother[$index]['category_id']; 254 break; 255 } 256 } 257 258 return $upper_id; 259 } 260 261 /** 262 * 指定カテゴリーを含めた子孫カテゴリーの数を取得する. 263 * 264 * @param int $category_id カテゴリーID 265 * @return int 266 */ 267 private function countAllBranches($category_id) 268 { 269 $objDb = new SC_Helper_DB_Ex(); 270 // 子ID一覧を取得 271 $arrRet = $objDb->sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $category_id); 272 273 return count($arrRet); 274 } 275 276 /** 277 * 子孫カテゴリーの表示順を一括して上げる. 278 * 279 * @param SC_Query $objQuery 280 * @param int $category_id 281 * @param int $count 282 * @return array|bool 283 */ 284 private function raiseBranchRank(SC_Query $objQuery, $category_id, $count) 285 { 286 $table = 'dtb_category'; 287 $objDb = new SC_Helper_DB_Ex(); 288 // 子ID一覧を取得 289 $arrRet = $objDb->sfGetChildrenArray($table, 'parent_category_id', 'category_id', $category_id); 290 $line = SC_Utils_Ex::sfGetCommaList($arrRet); 291 $where = "category_id IN ($line) AND del_flg = 0"; 292 $arrRawVal = array( 293 'rank' => "(rank + $count)", 294 ); 295 296 return $objQuery->update($table, array(), $where, array(), $arrRawVal); 297 } 298 299 /** 300 * 子孫カテゴリーの表示順を一括して下げる. 301 * 302 * @param SC_Query $objQuery 303 * @param int $category_id 304 * @param int $count 305 * @return array|bool 306 */ 307 private function reduceBranchRank(SC_Query $objQuery, $category_id, $count) 308 { 309 $table = 'dtb_category'; 310 $objDb = new SC_Helper_DB_Ex(); 311 // 子ID一覧を取得 312 $arrRet = $objDb->sfGetChildrenArray($table, 'parent_category_id', 'category_id', $category_id); 313 $line = SC_Utils_Ex::sfGetCommaList($arrRet); 314 $where = "category_id IN ($line) AND del_flg = 0"; 315 $arrRawVal = array( 316 'rank' => "(rank - $count)", 317 ); 318 319 return $objQuery->update($table, array(), $where, array(), $arrRawVal); 320 } 170 321 } -
branches/version-2_13-dev/data/class/pages/admin/products/LC_Page_Admin_Products_Category.php
r23435 r23436 345 345 public function doUp(&$objFormParam) 346 346 { 347 $objCategory = new SC_Helper_Category_Ex(false); 347 348 $category_id = $objFormParam->getValue('category_id'); 348 349 $objQuery =& SC_Query_Ex::getSingletonInstance(); 350 $objQuery->begin(); 351 $up_id = $this->lfGetUpRankID($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 352 if ($up_id != '') { 353 // 上のグループのrankから減算する数 354 $my_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 355 // 自分のグループのrankに加算する数 356 $up_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $up_id); 357 if ($my_count > 0 && $up_count > 0) { 358 // 自分のグループに加算 359 $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id, $up_count); 360 // 上のグループから減算 361 $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $up_id, $my_count); 362 } 363 } 364 $objQuery->commit(); 349 $objCategory->rankUp($category_id); 365 350 } 366 351 … … 373 358 public function doDown(&$objFormParam) 374 359 { 360 $objCategory = new SC_Helper_Category_Ex(false); 375 361 $category_id = $objFormParam->getValue('category_id'); 376 377 $objQuery =& SC_Query_Ex::getSingletonInstance(); 378 $objQuery->begin(); 379 $down_id = $this->lfGetDownRankID($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 380 if ($down_id != '') { 381 // 下のグループのrankに加算する数 382 $my_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 383 // 自分のグループのrankから減算する数 384 $down_count = $this->lfCountChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $down_id); 385 if ($my_count > 0 && $down_count > 0) { 386 // 自分のグループから減算 387 $this->lfUpRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $down_id, $my_count); 388 // 下のグループに加算 389 $this->lfDownRankChilds($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id, $down_count); 390 } 391 } 392 $objQuery->commit(); 362 $objCategory->rankDown($category_id); 393 363 } 394 364 … … 497 467 * カテゴリの階層が上限を超えているかを判定する 498 468 * 499 * @param int eger親カテゴリID500 * @ param超えている場合 true469 * @param int $parent_category_id 親カテゴリID 470 * @return bool 超えている場合 true 501 471 */ 502 472 public function isOverLevel($parent_category_id) 503 473 { 504 $objQuery =& SC_Query_Ex::getSingletonInstance(); 505 $level = $objQuery->get('level', 'dtb_category', 'category_id = ?', array($parent_category_id)); 506 507 return $level >= LEVEL_MAX; 508 } 509 510 // 並びが1つ下のIDを取得する。 511 public function lfGetDownRankID($objQuery, $table, $pid_name, $id_name, $id) 512 { 513 // 親IDを取得する。 514 $col = "$pid_name"; 515 $where = "$id_name = ?"; 516 $pid = $objQuery->get($col, $table, $where, $id); 517 // 全ての子を取得する。 518 $col = "$id_name"; 519 $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 520 $arrRet = $objQuery->select($col, $table, $where, array($pid)); 521 $max = count($arrRet); 522 $down_id = ''; 523 for ($cnt = 0; $cnt < $max; $cnt++) { 524 if ($arrRet[$cnt][$id_name] == $id) { 525 $down_id = $arrRet[($cnt + 1)][$id_name]; 526 break; 527 } 528 } 529 530 return $down_id; 531 } 532 533 // 並びが1つ上のIDを取得する。 534 public function lfGetUpRankID($objQuery, $table, $pid_name, $id_name, $id) 535 { 536 // 親IDを取得する。 537 $col = "$pid_name"; 538 $where = "$id_name = ?"; 539 $pid = $objQuery->get($col, $table, $where, $id); 540 // 全ての子を取得する。 541 $col = "$id_name"; 542 $where = "del_flg = 0 AND $pid_name = ? ORDER BY rank DESC"; 543 $arrRet = $objQuery->select($col, $table, $where, array($pid)); 544 $max = count($arrRet); 545 $up_id = ''; 546 for ($cnt = 0; $cnt < $max; $cnt++) { 547 if ($arrRet[$cnt][$id_name] == $id) { 548 $up_id = $arrRet[($cnt - 1)][$id_name]; 549 break; 550 } 551 } 552 553 return $up_id; 474 $objCategory = new SC_Helper_Category_Ex(); 475 $arrCategory = $objCategory->get($parent_category_id); 476 477 return $arrCategory['level'] >= LEVEL_MAX; 554 478 } 555 479 -
branches/version-2_13-dev/data/class/util/SC_Utils.php
r23415 r23436 549 549 550 550 // 配列の値をカンマ区切りで返す。 551 public function sfGetCommaList($array, $space=true, $arrPop = array())551 public static function sfGetCommaList($array, $space=true, $arrPop = array()) 552 552 { 553 553 if (count($array) > 0) {
Note: See TracChangeset
for help on using the changeset viewer.