- Timestamp:
- 2007/08/24 12:52:51 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/helper/SC_Helper_DB.php
r15295 r15343 408 408 409 409 /** 410 * カテゴリツリーの取得を行う. 411 * 412 * $products_check:true商品登録済みのものだけ取得する 413 * 414 * @param string $addwhere 追加する WHERE 句 415 * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true 416 * @param string $head カテゴリ名のプレフィックス文字列 417 * @return array カテゴリツリーの配列 418 */ 419 function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) { 420 $objQuery = new SC_Query(); 421 $where = "del_flg = 0"; 422 423 if($addwhere != "") { 424 $where.= " AND $addwhere"; 425 } 426 427 $objQuery->setoption("ORDER BY rank DESC"); 428 429 if($products_check) { 430 $col = "T1.category_id, category_name, level"; 431 $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id"; 432 $where .= " AND product_count > 0"; 433 } else { 434 $col = "category_id, category_name, level"; 435 $from = "dtb_category"; 436 } 437 438 $arrRet = $objQuery->select($col, $from, $where); 439 440 $max = count($arrRet); 441 for($cnt = 0; $cnt < $max; $cnt++) { 442 $id = $arrRet[$cnt]['category_id']; 443 $name = $arrRet[$cnt]['category_name']; 444 $arrList[$id] = ""; 445 /* 446 for($n = 1; $n < $arrRet[$cnt]['level']; $n++) { 447 $arrList[$id].= " "; 448 } 449 */ 450 for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) { 451 $arrList[$id].= $head; 452 } 453 $arrList[$id].= $name; 454 } 455 return $arrList; 456 } 457 458 /** 459 * カテゴリーツリーの取得を行う. 460 * 461 * 親カテゴリの Value=0 を対象とする 462 * 463 * @param bool $parent_zero 親カテゴリの Value=0 の場合 true 464 * @return array カテゴリツリーの配列 465 */ 466 function sfGetLevelCatList($parent_zero = true) { 467 $objQuery = new SC_Query(); 468 $col = "category_id, category_name, level"; 469 $where = "del_flg = 0"; 470 $objQuery->setoption("ORDER BY rank DESC"); 471 $arrRet = $objQuery->select($col, "dtb_category", $where); 472 $max = count($arrRet); 473 474 for($cnt = 0; $cnt < $max; $cnt++) { 475 if($parent_zero) { 476 if($arrRet[$cnt]['level'] == LEVEL_MAX) { 477 $arrValue[$cnt] = $arrRet[$cnt]['category_id']; 478 } else { 479 $arrValue[$cnt] = ""; 480 } 481 } else { 482 $arrValue[$cnt] = $arrRet[$cnt]['category_id']; 483 } 484 485 $arrOutput[$cnt] = ""; 486 /* 487 for($n = 1; $n < $arrRet[$cnt]['level']; $n++) { 488 $arrOutput[$cnt].= " "; 489 } 490 */ 491 for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) { 492 $arrOutput[$cnt].= CATEGORY_HEAD; 493 } 494 $arrOutput[$cnt].= $arrRet[$cnt]['category_name']; 495 } 496 return array($arrValue, $arrOutput); 497 } 498 499 /** 500 * カテゴリ数の登録を行う. 501 * 502 * @param SC_Query $objQuery SC_Query インスタンス 503 * @return void 504 */ 505 function sfCategory_Count($objQuery){ 506 $sql = ""; 507 508 //テーブル内容の削除 509 $objQuery->query("DELETE FROM dtb_category_count"); 510 $objQuery->query("DELETE FROM dtb_category_total_count"); 511 512 //各カテゴリ内の商品数を数えて格納 513 $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) "; 514 $sql .= " SELECT T1.category_id, count(T2.category_id), now() FROM dtb_category AS T1 LEFT JOIN dtb_products AS T2 "; 515 $sql .= " ON T1.category_id = T2.category_id "; 516 $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 "; 517 $sql .= " GROUP BY T1.category_id, T2.category_id "; 518 $objQuery->query($sql); 519 520 //子カテゴリ内の商品数を集計する 521 $arrCat = $objQuery->getAll("SELECT * FROM dtb_category"); 522 523 $sql = ""; 524 foreach($arrCat as $key => $val){ 525 526 // 子ID一覧を取得 527 $arrRet = $this->sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']); 528 $line = SC_Utils_Ex::sfGetCommaList($arrRet); 529 530 $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) "; 531 $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count "; 532 $sql .= " WHERE category_id IN (" . $line . ")"; 533 534 $objQuery->query($sql, array($val['category_id'])); 535 } 536 } 537 538 /** 539 * 階層構造のテーブルから子ID配列を取得する. 540 * 541 * @param string $table テーブル名 542 * @param string $pid_name 親ID名 543 * @param string $id_name ID名 544 * @param integer $id ID番号 545 * @return array 子IDの配列 546 */ 547 function sfGetChildrenArray($table, $pid_name, $id_name, $id) { 548 $objQuery = new SC_Query(); 549 $col = $pid_name . "," . $id_name; 550 $arrData = $objQuery->select($col, $table); 551 552 $arrPID = array(); 553 $arrPID[] = $id; 554 $arrChildren = array(); 555 $arrChildren[] = $id; 556 557 $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); 558 559 while(count($arrRet) > 0) { 560 $arrChildren = array_merge($arrChildren, $arrRet); 561 $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet); 562 } 563 564 return $arrChildren; 565 } 566 567 /** 568 * 親ID直下の子IDをすべて取得する. 569 * 570 * @param array $arrData 親カテゴリの配列 571 * @param string $pid_name 親ID名 572 * @param string $id_name ID名 573 * @param array $arrPID 親IDの配列 574 * @return array 子IDの配列 575 */ 576 function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) { 577 $arrChildren = array(); 578 $max = count($arrData); 579 580 for($i = 0; $i < $max; $i++) { 581 foreach($arrPID as $val) { 582 if($arrData[$i][$pid_name] == $val) { 583 $arrChildren[] = $arrData[$i][$id_name]; 584 } 585 } 586 } 587 return $arrChildren; 588 } 589 590 /** 591 * 階層構造のテーブルから親ID配列を取得する. 592 * 593 * @param string $table テーブル名 594 * @param string $pid_name 親ID名 595 * @param string $id_name ID名 596 * @param integer $id ID 597 * @return array 親IDの配列 598 */ 599 function sfGetParentsArray($table, $pid_name, $id_name, $id) { 600 $objQuery = new SC_Query(); 601 $col = $pid_name . "," . $id_name; 602 $arrData = $objQuery->select($col, $table); 603 604 $arrParents = array(); 605 $arrParents[] = $id; 606 $child = $id; 607 608 $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child); 609 610 while($ret != "") { 611 $arrParents[] = $ret; 612 $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret); 613 } 614 615 $arrParents = array_reverse($arrParents); 616 617 return $arrParents; 618 } 619 620 /** 410 621 * 受注一時テーブルから情報を取得する. 411 622 *
Note: See TracChangeset
for help on using the changeset viewer.