[22588] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * カテゴリーを管理するヘルパークラス. |
---|
| 26 | * |
---|
| 27 | * @package Helper |
---|
| 28 | * @author pineray |
---|
| 29 | * @version $Id:$ |
---|
| 30 | */ |
---|
| 31 | class SC_Helper_Category |
---|
| 32 | { |
---|
[22589] | 33 | private $count_check; |
---|
| 34 | |
---|
[22588] | 35 | /** |
---|
[22589] | 36 | * コンストラクター |
---|
| 37 | * |
---|
| 38 | * @param boolean $count_check 登録商品数をチェックする場合はtrue |
---|
| 39 | */ |
---|
| 40 | function __construct($count_check = FALSE) |
---|
| 41 | { |
---|
| 42 | $this->count_check = $count_check; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | /** |
---|
[22595] | 46 | * カテゴリーの情報を取得. |
---|
| 47 | * |
---|
| 48 | * @param integer $category_id カテゴリーID |
---|
| 49 | * @return array |
---|
| 50 | */ |
---|
| 51 | public function get($category_id) |
---|
| 52 | { |
---|
| 53 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[22777] | 54 | $col = 'dtb_category.*, dtb_category_total_count.product_count'; |
---|
[22595] | 55 | $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id'; |
---|
| 56 | $where = 'dtb_category.category_id = ? AND del_flg = 0'; |
---|
| 57 | // 登録商品数のチェック |
---|
| 58 | if ($this->count_check) { |
---|
| 59 | $where .= ' AND product_count > 0'; |
---|
| 60 | } |
---|
| 61 | $arrRet = $objQuery->getRow($col, $from, $where, array($category_id)); |
---|
| 62 | return $arrRet; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
[22588] | 66 | * カテゴリー一覧の取得. |
---|
| 67 | * |
---|
| 68 | * @param boolean $cid_to_key 配列のキーをカテゴリーIDにする場合はtrue |
---|
| 69 | * @return array カテゴリー一覧の配列 |
---|
| 70 | */ |
---|
[22589] | 71 | public function getList($cid_to_key = FALSE) |
---|
[22588] | 72 | { |
---|
[22603] | 73 | static $arrCategory = array(), $cidIsKey = array(); |
---|
[22594] | 74 | |
---|
| 75 | if (!isset($arrCategory[$this->count_check])) { |
---|
| 76 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[22777] | 77 | $col = 'dtb_category.*, dtb_category_total_count.product_count'; |
---|
[22594] | 78 | $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id'; |
---|
| 79 | // 登録商品数のチェック |
---|
| 80 | if ($this->count_check) { |
---|
| 81 | $where = 'del_flg = 0 AND product_count > 0'; |
---|
| 82 | } else { |
---|
| 83 | $where = 'del_flg = 0'; |
---|
| 84 | } |
---|
| 85 | $objQuery->setOption('ORDER BY rank DESC'); |
---|
| 86 | $arrTmp = $objQuery->select($col, $from, $where); |
---|
| 87 | |
---|
| 88 | $arrCategory[$this->count_check] = $arrTmp; |
---|
[22588] | 89 | } |
---|
| 90 | |
---|
| 91 | if ($cid_to_key) { |
---|
[22603] | 92 | if (!isset($cidIsKey[$this->count_check])) { |
---|
| 93 | // 配列のキーをカテゴリーIDに |
---|
| 94 | $cidIsKey[$this->count_check] = SC_Utils_Ex::makeArrayIDToKey('category_id', $arrCategory[$this->count_check]); |
---|
| 95 | } |
---|
| 96 | return $cidIsKey[$this->count_check]; |
---|
[22588] | 97 | } |
---|
[22594] | 98 | |
---|
| 99 | return $arrCategory[$this->count_check]; |
---|
[22588] | 100 | } |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * カテゴリーツリーの取得. |
---|
| 104 | * |
---|
| 105 | * @return type |
---|
| 106 | */ |
---|
[22589] | 107 | public function getTree() |
---|
[22588] | 108 | { |
---|
[22603] | 109 | static $arrTree = array(); |
---|
| 110 | if (!isset($arrTree[$this->count_check])) { |
---|
| 111 | $arrList = $this->getList(); |
---|
| 112 | $arrTree[$this->count_check] = SC_Utils_Ex::buildTree('category_id', 'parent_category_id', LEVEL_MAX, $arrList); |
---|
| 113 | } |
---|
| 114 | return $arrTree[$this->count_check]; |
---|
[22588] | 115 | } |
---|
[22595] | 116 | |
---|
| 117 | /** |
---|
| 118 | * 親カテゴリーIDの配列を取得. |
---|
| 119 | * |
---|
| 120 | * @param integer $category_id 起点のカテゴリーID |
---|
[22597] | 121 | * @param boolean $id_only IDだけの配列を返す場合はtrue |
---|
[22595] | 122 | * @return array |
---|
| 123 | */ |
---|
[22597] | 124 | public function getTreeTrail($category_id, $id_only = TRUE) |
---|
[22595] | 125 | { |
---|
[22603] | 126 | $arrCategory = $this->getList(TRUE); |
---|
| 127 | $arrTrailID = SC_Utils_Ex::getTreeTrail($category_id, 'category_id', 'parent_category_id', $arrCategory, TRUE, 0, $id_only); |
---|
[22595] | 128 | return $arrTrailID; |
---|
| 129 | } |
---|
[22588] | 130 | } |
---|