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 | require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php'; |
---|
25 | |
---|
26 | /** |
---|
27 | * カテゴリ一覧 のページクラス. |
---|
28 | * |
---|
29 | * @package Page |
---|
30 | * @author LOCKON CO.,LTD. |
---|
31 | * @version $Id$ |
---|
32 | */ |
---|
33 | class LC_Page_Products_CategoryList extends LC_Page_Ex |
---|
34 | { |
---|
35 | /** |
---|
36 | * Page を初期化する. |
---|
37 | * |
---|
38 | * @return void |
---|
39 | */ |
---|
40 | function init() |
---|
41 | { |
---|
42 | parent::init(); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * Page のプロセス. |
---|
47 | * |
---|
48 | * @return void |
---|
49 | */ |
---|
50 | function process() |
---|
51 | { |
---|
52 | parent::process(); |
---|
53 | $this->action(); |
---|
54 | $this->sendResponse(); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Page のAction |
---|
59 | * @return void |
---|
60 | */ |
---|
61 | function action() |
---|
62 | { |
---|
63 | // カテゴリIDの正当性チェック |
---|
64 | $this->lfCheckCategoryId(); |
---|
65 | |
---|
66 | // カテゴリ情報を取得する。 |
---|
67 | $objFormParam = $this->lfInitParam($_REQUEST); |
---|
68 | $arrCategoryData = $this->lfGetCategories($objFormParam->getValue('category_id'), true, $this); |
---|
69 | $this->arrCategory = $arrCategoryData['arrCategory']; |
---|
70 | $this->arrChildren = $arrCategoryData['arrChildren']; |
---|
71 | $this->tpl_subtitle = $this->arrCategory['category_name']; |
---|
72 | } |
---|
73 | |
---|
74 | /* カテゴリIDの正当性チェック */ |
---|
75 | function lfCheckCategoryId($category_id) |
---|
76 | { |
---|
77 | if ($category_id && !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')) { |
---|
78 | return 0; |
---|
79 | } |
---|
80 | |
---|
81 | return $category_id; |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * 選択されたカテゴリとその子カテゴリの情報を取得し、 |
---|
86 | * ページオブジェクトに格納する。 |
---|
87 | * |
---|
88 | * @param string $category_id カテゴリID |
---|
89 | * @param boolean $count_check 有効な商品がないカテゴリを除くかどうか |
---|
90 | * @param object &$objPage ページオブジェクト |
---|
91 | * @return void |
---|
92 | */ |
---|
93 | function lfGetCategories($category_id, $count_check = false, &$objPage) |
---|
94 | { |
---|
95 | // カテゴリの正しいIDを取得する。 |
---|
96 | $category_id = $this->lfCheckCategoryId($category_id); |
---|
97 | if ($category_id == 0) { |
---|
98 | SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND); |
---|
99 | } |
---|
100 | |
---|
101 | $arrCategory = null; // 選択されたカテゴリ |
---|
102 | $arrChildren = array(); // 子カテゴリ |
---|
103 | |
---|
104 | $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, $count_check); |
---|
105 | foreach ($arrAll as $category) { |
---|
106 | // 選択されたカテゴリの場合 |
---|
107 | if ($category['category_id'] == $category_id) { |
---|
108 | $arrCategory = $category; |
---|
109 | continue; |
---|
110 | } |
---|
111 | |
---|
112 | // 関係のないカテゴリはスキップする。 |
---|
113 | if ($category['parent_category_id'] != $category_id) { |
---|
114 | continue; |
---|
115 | } |
---|
116 | |
---|
117 | // 子カテゴリの場合は、孫カテゴリが存在するかどうかを調べる。 |
---|
118 | $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']); |
---|
119 | $category['has_children'] = count($arrGrandchildrenID) > 0; |
---|
120 | $arrChildren[] = $category; |
---|
121 | } |
---|
122 | |
---|
123 | if (!isset($arrCategory)) { |
---|
124 | SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND); |
---|
125 | } |
---|
126 | |
---|
127 | // 子カテゴリの商品数を合計する。 |
---|
128 | $children_product_count = 0; |
---|
129 | foreach ($arrChildren as $category) { |
---|
130 | $children_product_count += $category['product_count']; |
---|
131 | } |
---|
132 | |
---|
133 | // 選択されたカテゴリに直属の商品がある場合は、子カテゴリの先頭に追加する。 |
---|
134 | if ($arrCategory['product_count'] > $children_product_count) { |
---|
135 | $arrCategory['product_count'] -= $children_product_count; // 子カテゴリの商品数を除く。 |
---|
136 | $arrCategory['has_children'] = false; // 商品一覧ページに遷移させるため。 |
---|
137 | array_unshift($arrChildren, $arrCategory); |
---|
138 | } |
---|
139 | |
---|
140 | return array('arrChildren'=>$arrChildren, 'arrCategory'=>$arrCategory); |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * ユーザ入力値の処理 |
---|
145 | * |
---|
146 | * @return object |
---|
147 | */ |
---|
148 | function lfInitParam($arrRequest) |
---|
149 | { |
---|
150 | $objFormParam = new SC_FormParam_Ex(); |
---|
151 | $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK')); |
---|
152 | // 値の取得 |
---|
153 | $objFormParam->setParam($arrRequest); |
---|
154 | // 入力値の変換 |
---|
155 | $objFormParam->convParam(); |
---|
156 | |
---|
157 | return $objFormParam; |
---|
158 | } |
---|
159 | } |
---|