- Timestamp:
- 2007/08/27 16:31:19 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/helper/SC_Helper_DB.php
r15359 r15364 22 22 /** ルートカテゴリID */ 23 23 var $g_root_id; 24 25 /** 選択中カテゴリ取得フラグ */ 26 var $g_category_on; 27 28 /** 選択中カテゴリID */ 29 var $g_category_id; 24 30 25 31 // }}} … … 205 211 if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) { 206 212 // 選択中のカテゴリIDを判定する 207 $category_id = SC_Utils_Ex::sfGetCategoryId($_GET['product_id'], $_GET['category_id']);213 $category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']); 208 214 // ROOTカテゴリIDの取得 209 $arrRet = SC_Utils_Ex::sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);215 $arrRet = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); 210 216 $root_id = $arrRet[0]; 211 217 } else { … … 420 426 * カテゴリツリーの取得を行う. 421 427 * 428 * @param integer $parent_category_id 親カテゴリID 429 * @param bool $count_check 登録商品数のチェックを行う場合 true 430 * @return array カテゴリツリーの配列 431 */ 432 function sfGetCatTree($parent_category_id, $count_check = false) { 433 $objQuery = new SC_Query(); 434 $col = ""; 435 $col .= " cat.category_id,"; 436 $col .= " cat.category_name,"; 437 $col .= " cat.parent_category_id,"; 438 $col .= " cat.level,"; 439 $col .= " cat.rank,"; 440 $col .= " cat.creator_id,"; 441 $col .= " cat.create_date,"; 442 $col .= " cat.update_date,"; 443 $col .= " cat.del_flg, "; 444 $col .= " ttl.product_count"; 445 $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; 446 // 登録商品数のチェック 447 if($count_check) { 448 $where = "del_flg = 0 AND product_count > 0"; 449 } else { 450 $where = "del_flg = 0"; 451 } 452 $objQuery->setoption("ORDER BY rank DESC"); 453 $arrRet = $objQuery->select($col, $from, $where); 454 455 $arrParentID = sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 456 457 foreach($arrRet as $key => $array) { 458 foreach($arrParentID as $val) { 459 if($array['category_id'] == $val) { 460 $arrRet[$key]['display'] = 1; 461 break; 462 } 463 } 464 } 465 466 return $arrRet; 467 } 468 469 /** 470 * 親カテゴリーを連結した文字列を取得する. 471 * 472 * @param integer $category_id カテゴリID 473 * @return string 親カテゴリーを連結した文字列 474 */ 475 function sfGetCatCombName($category_id){ 476 // 商品が属するカテゴリIDを縦に取得 477 $objQuery = new SC_Query(); 478 $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); 479 $ConbName = ""; 480 481 // カテゴリー名称を取得する 482 foreach($arrCatID as $key => $val){ 483 $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; 484 $arrVal = array($val); 485 $CatName = $objQuery->getOne($sql,$arrVal); 486 $ConbName .= $CatName . ' | '; 487 } 488 // 最後の | をカットする 489 $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2); 490 491 return $ConbName; 492 } 493 494 /** 495 * 指定したカテゴリーIDの大カテゴリーを取得する. 496 * 497 * @param integer $category_id カテゴリID 498 * @return array 指定したカテゴリーIDの大カテゴリー 499 */ 500 function sfGetFirstCat($category_id){ 501 // 商品が属するカテゴリIDを縦に取得 502 $objQuery = new SC_Query(); 503 $arrRet = array(); 504 $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); 505 $arrRet['id'] = $arrCatID[0]; 506 507 // カテゴリー名称を取得する 508 $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; 509 $arrVal = array($arrRet['id']); 510 $arrRet['name'] = $objQuery->getOne($sql,$arrVal); 511 512 return $arrRet; 513 } 514 515 /** 516 * カテゴリツリーの取得を行う. 517 * 422 518 * $products_check:true商品登録済みのものだけ取得する 423 519 * … … 508 604 509 605 /** 606 * 選択中のカテゴリを取得する. 607 * 608 * @param integer $product_id プロダクトID 609 * @param integer $category_id カテゴリID 610 * @return integer 選択中のカテゴリID 611 * 612 */ 613 function sfGetCategoryId($product_id, $category_id) { 614 615 if(!$this->g_category_on) { 616 $this->g_category_on = true; 617 $category_id = (int) $category_id; 618 $product_id = (int) $product_id; 619 if(SC_Utils_Ex::sfIsInt($category_id) && $this->sfIsRecord("dtb_category","category_id", $category_id)) { 620 $this->g_category_id = $category_id; 621 } else if (SC_Utils_Ex::sfIsInt($product_id) && $this->sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) { 622 $objQuery = new SC_Query(); 623 $where = "product_id = ?"; 624 $category_id = $objQuery->get("dtb_products", "category_id", $where, array($product_id)); 625 $this->g_category_id = $category_id; 626 } else { 627 // 不正な場合は、0を返す。 628 $this->g_category_id = 0; 629 } 630 } 631 return $this->g_category_id; 632 } 633 634 /** 510 635 * カテゴリ数の登録を行う. 511 636 * … … 623 748 */ 624 749 function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) { 625 $objDb = new SC_Helper_DB_Ex(); 626 $arrRet = $objDb->sfGetParentsArray($table, $pid_name, $id_name, $id); 750 $arrRet = $this->sfGetParentsArray($table, $pid_name, $id_name, $id); 627 751 // 配列の先頭1つを削除する。 628 752 array_shift($arrRet);
Note: See TracChangeset
for help on using the changeset viewer.