[15367] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[20764] | 5 | * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15367] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 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. |
---|
[15367] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_REALDIR . 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php'; |
---|
[15367] | 26 | |
---|
| 27 | /** |
---|
| 28 | * カテゴリ のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
[19903] | 32 | * @version $Id$ |
---|
[15367] | 33 | */ |
---|
[16530] | 34 | class LC_Page_FrontParts_Bloc_Category extends LC_Page_FrontParts_Bloc { |
---|
[15367] | 35 | |
---|
| 36 | // }}} |
---|
| 37 | // {{{ functions |
---|
| 38 | |
---|
| 39 | /** |
---|
| 40 | * Page を初期化する. |
---|
| 41 | * |
---|
| 42 | * @return void |
---|
| 43 | */ |
---|
| 44 | function init() { |
---|
| 45 | parent::init(); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Page のプロセス. |
---|
| 50 | * |
---|
| 51 | * @return void |
---|
| 52 | */ |
---|
| 53 | function process() { |
---|
[19726] | 54 | $this->action(); |
---|
| 55 | $this->sendResponse(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | /** |
---|
| 59 | * Page のアクション. |
---|
| 60 | * |
---|
| 61 | * @return void |
---|
| 62 | */ |
---|
| 63 | function action() { |
---|
[20076] | 64 | // モバイル判定 |
---|
[20484] | 65 | switch ( SC_Display_Ex::detectDevice() ) { |
---|
[20108] | 66 | case DEVICE_TYPE_MOBILE: |
---|
| 67 | // メインカテゴリーの取得 |
---|
| 68 | $this->arrCat = $this->lfGetMainCat(true); |
---|
| 69 | break; |
---|
| 70 | default: |
---|
| 71 | // 選択中のカテゴリID |
---|
| 72 | $this->tpl_category_id = $this->lfGetSelectedCategoryId($_GET); |
---|
| 73 | // カテゴリツリーの取得 |
---|
| 74 | $this->arrTree = $this->lfGetCatTree($this->tpl_category_id, true); |
---|
| 75 | break; |
---|
[19903] | 76 | } |
---|
[15367] | 77 | } |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * デストラクタ. |
---|
| 81 | * |
---|
| 82 | * @return void |
---|
| 83 | */ |
---|
| 84 | function destroy() { |
---|
| 85 | parent::destroy(); |
---|
| 86 | } |
---|
| 87 | |
---|
[20076] | 88 | /** |
---|
| 89 | * 選択中のカテゴリIDを取得する. |
---|
| 90 | * |
---|
[20108] | 91 | * @param array $arrRequest リクエスト配列 |
---|
[20076] | 92 | * @return array $arrCategoryId 選択中のカテゴリID |
---|
| 93 | */ |
---|
[20108] | 94 | function lfGetSelectedCategoryId($arrRequest) { |
---|
[20086] | 95 | // 商品ID取得 |
---|
| 96 | $product_id = ''; |
---|
[20108] | 97 | if ( isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id']) ) { |
---|
| 98 | $product_id = $arrRequest['product_id']; |
---|
[20076] | 99 | } |
---|
| 100 | // カテゴリID取得 |
---|
[20086] | 101 | $category_id = ''; |
---|
[20108] | 102 | if ( isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id']) ) { |
---|
| 103 | $category_id = $arrRequest['category_id']; |
---|
[20076] | 104 | } |
---|
| 105 | // 選択中のカテゴリIDを判定する |
---|
| 106 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 107 | $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id); |
---|
| 108 | if (empty($arrCategoryId)) { |
---|
| 109 | $arrCategoryId = array(0); |
---|
| 110 | } |
---|
| 111 | return $arrCategoryId; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | /** |
---|
| 115 | * カテゴリツリーの取得. |
---|
| 116 | * |
---|
| 117 | * @param array $arrParentCategoryId 親カテゴリの配列 |
---|
| 118 | * @param boolean $count_check 登録商品数をチェックする場合はtrue |
---|
| 119 | * @return array $arrRet カテゴリーツリーの配列を返す |
---|
| 120 | */ |
---|
| 121 | function lfGetCatTree($arrParentCategoryId, $count_check = false) { |
---|
[20507] | 122 | $objQuery = new SC_Query_Ex(); |
---|
[15367] | 123 | $objDb = new SC_Helper_DB_Ex(); |
---|
[20076] | 124 | $col = '*'; |
---|
| 125 | $from = 'dtb_category left join dtb_category_total_count using (category_id)'; |
---|
[15367] | 126 | // 登録商品数のチェック |
---|
| 127 | if($count_check) { |
---|
[20076] | 128 | $where = 'del_flg = 0 AND product_count > 0'; |
---|
[15367] | 129 | } else { |
---|
[20076] | 130 | $where = 'del_flg = 0'; |
---|
[15367] | 131 | } |
---|
[20076] | 132 | $objQuery->setOption('ORDER BY rank DESC'); |
---|
[15367] | 133 | $arrRet = $objQuery->select($col, $from, $where); |
---|
[20076] | 134 | foreach ($arrParentCategoryId as $category_id) { |
---|
| 135 | $arrParentID = $objDb->sfGetParents( |
---|
| 136 | 'dtb_category', |
---|
| 137 | 'parent_category_id', |
---|
| 138 | 'category_id', |
---|
| 139 | $category_id |
---|
| 140 | ); |
---|
| 141 | $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray( |
---|
| 142 | $arrRet, |
---|
| 143 | 'parent_category_id', |
---|
| 144 | 'category_id', |
---|
| 145 | $arrParentID |
---|
| 146 | ); |
---|
| 147 | $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray( |
---|
| 148 | $arrRet, |
---|
| 149 | 'parent_category_id', |
---|
| 150 | 'category_id', |
---|
| 151 | $category_id |
---|
| 152 | ); |
---|
[16546] | 153 | $this->root_parent_id[] = $arrParentID[0]; |
---|
| 154 | $arrDispID = array_merge($arrBrothersID, $arrChildrenID); |
---|
| 155 | foreach($arrRet as $key => $array) { |
---|
| 156 | foreach($arrDispID as $val) { |
---|
| 157 | if($array['category_id'] == $val) { |
---|
| 158 | $arrRet[$key]['display'] = 1; |
---|
| 159 | break; |
---|
| 160 | } |
---|
[15367] | 161 | } |
---|
| 162 | } |
---|
| 163 | } |
---|
[20076] | 164 | return $arrRet; |
---|
[15367] | 165 | } |
---|
[16147] | 166 | |
---|
[20076] | 167 | /** |
---|
| 168 | * メインカテゴリーの取得. |
---|
| 169 | * |
---|
| 170 | * @param boolean $count_check 登録商品数をチェックする場合はtrue |
---|
| 171 | * @return array $arrMainCat メインカテゴリーの配列を返す |
---|
| 172 | */ |
---|
| 173 | function lfGetMainCat($count_check = false) { |
---|
[20507] | 174 | $objQuery = new SC_Query_Ex(); |
---|
[20076] | 175 | $col = '*'; |
---|
| 176 | $from = 'dtb_category left join dtb_category_total_count using (category_id)'; |
---|
[16147] | 177 | // メインカテゴリーとその直下のカテゴリーを取得する。 |
---|
| 178 | $where = 'level <= 2 AND del_flg = 0'; |
---|
| 179 | // 登録商品数のチェック |
---|
| 180 | if($count_check) { |
---|
[20076] | 181 | $where .= ' AND product_count > 0'; |
---|
[16147] | 182 | } |
---|
[20076] | 183 | $objQuery->setOption('ORDER BY rank DESC'); |
---|
[16147] | 184 | $arrRet = $objQuery->select($col, $from, $where); |
---|
| 185 | // メインカテゴリーを抽出する。 |
---|
| 186 | $arrMainCat = array(); |
---|
| 187 | foreach ($arrRet as $cat) { |
---|
| 188 | if ($cat['level'] != 1) { |
---|
| 189 | continue; |
---|
| 190 | } |
---|
| 191 | // 子カテゴリーを持つかどうかを調べる。 |
---|
[20076] | 192 | $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray( |
---|
| 193 | $arrRet, |
---|
| 194 | 'parent_category_id', |
---|
| 195 | 'category_id', |
---|
| 196 | $cat['category_id'] |
---|
| 197 | ); |
---|
[16147] | 198 | $cat['has_children'] = count($arrChildrenID) > 0; |
---|
| 199 | $arrMainCat[] = $cat; |
---|
| 200 | } |
---|
[20076] | 201 | return $arrMainCat; |
---|
[16147] | 202 | } |
---|
[15367] | 203 | } |
---|
| 204 | ?> |
---|