1 | <?php |
---|
2 | /* |
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
4 | * |
---|
5 | * http://www.lockon.co.jp/ |
---|
6 | */ |
---|
7 | |
---|
8 | // {{{ requires |
---|
9 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
10 | |
---|
11 | /** |
---|
12 | * カテゴリ のページクラス. |
---|
13 | * |
---|
14 | * @package Page |
---|
15 | * @author LOCKON CO.,LTD. |
---|
16 | * @version $Id:LC_Page_FrontParts_Bloc_Category.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
17 | */ |
---|
18 | class LC_Page_FrontParts_Bloc_Category extends LC_Page { |
---|
19 | |
---|
20 | // }}} |
---|
21 | // {{{ functions |
---|
22 | |
---|
23 | /** |
---|
24 | * Page を初期化する. |
---|
25 | * |
---|
26 | * @return void |
---|
27 | */ |
---|
28 | function init() { |
---|
29 | parent::init(); |
---|
30 | $this->tpl_mainpage = BLOC_PATH . 'category.tpl'; |
---|
31 | } |
---|
32 | |
---|
33 | /** |
---|
34 | * Page のプロセス. |
---|
35 | * |
---|
36 | * @return void |
---|
37 | */ |
---|
38 | function process() { |
---|
39 | $objSubView = new SC_SiteView(); |
---|
40 | $objDb = new SC_Helper_DB_Ex(); |
---|
41 | |
---|
42 | // 選択中のカテゴリIDを判定する |
---|
43 | $category_id = $objDb->sfGetCategoryId($_GET['product_id'], $_GET['category_id']); |
---|
44 | |
---|
45 | // 選択中のカテゴリID |
---|
46 | $this->tpl_category_id = $category_id; |
---|
47 | $objPage = $this->lfGetCatTree($category_id, true, $this); |
---|
48 | |
---|
49 | $objSubView->assignobj($objPage); |
---|
50 | $objSubView->display($this->tpl_mainpage); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * モバイルページを初期化する. |
---|
55 | * |
---|
56 | * @return void |
---|
57 | */ |
---|
58 | function mobileInit() { |
---|
59 | $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "frontparts/" |
---|
60 | . BLOC_DIR . 'category.tpl'; |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * Page のプロセス(モバイル). |
---|
65 | * |
---|
66 | * @return void |
---|
67 | */ |
---|
68 | function mobileProcess() { |
---|
69 | $objSubView = new SC_MobileView(); |
---|
70 | |
---|
71 | $this->lfGetMainCat(true, $this); |
---|
72 | |
---|
73 | $objSubView->assignobj($this); |
---|
74 | $objSubView->display($this->tpl_mainpage); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * デストラクタ. |
---|
79 | * |
---|
80 | * @return void |
---|
81 | */ |
---|
82 | function destroy() { |
---|
83 | parent::destroy(); |
---|
84 | } |
---|
85 | |
---|
86 | // カテゴリツリーの取得 |
---|
87 | function lfGetCatTree($parent_category_id, $count_check = false, $objSubPage) { |
---|
88 | $objQuery = new SC_Query(); |
---|
89 | $objDb = new SC_Helper_DB_Ex(); |
---|
90 | $col = "*"; |
---|
91 | $from = "dtb_category left join dtb_category_total_count using (category_id)"; |
---|
92 | // 登録商品数のチェック |
---|
93 | if($count_check) { |
---|
94 | $where = "del_flg = 0 AND product_count > 0"; |
---|
95 | } else { |
---|
96 | $where = "del_flg = 0"; |
---|
97 | } |
---|
98 | $objQuery->setoption("ORDER BY rank DESC"); |
---|
99 | $arrRet = $objQuery->select($col, $from, $where); |
---|
100 | |
---|
101 | $arrParentID = $objDb->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id); |
---|
102 | $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray($arrRet, 'parent_category_id', 'category_id', $arrParentID); |
---|
103 | $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $parent_category_id); |
---|
104 | |
---|
105 | $objSubPage->root_parent_id = $arrParentID[0]; |
---|
106 | |
---|
107 | $arrDispID = array_merge($arrBrothersID, $arrChildrenID); |
---|
108 | |
---|
109 | foreach($arrRet as $key => $array) { |
---|
110 | foreach($arrDispID as $val) { |
---|
111 | if($array['category_id'] == $val) { |
---|
112 | $arrRet[$key]['display'] = 1; |
---|
113 | break; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | $objSubPage->arrTree = $arrRet; |
---|
119 | return $objSubPage; |
---|
120 | } |
---|
121 | |
---|
122 | // メインカテゴリーの取得 |
---|
123 | function lfGetMainCat($count_check = false, &$objSubPage) { |
---|
124 | $objQuery = new SC_Query(); |
---|
125 | $col = "*"; |
---|
126 | $from = "dtb_category left join dtb_category_total_count using (category_id)"; |
---|
127 | // メインカテゴリーとその直下のカテゴリーを取得する。 |
---|
128 | $where = 'level <= 2 AND del_flg = 0'; |
---|
129 | // 登録商品数のチェック |
---|
130 | if($count_check) { |
---|
131 | $where .= " AND product_count > 0"; |
---|
132 | } |
---|
133 | $objQuery->setoption("ORDER BY rank DESC"); |
---|
134 | $arrRet = $objQuery->select($col, $from, $where); |
---|
135 | |
---|
136 | // メインカテゴリーを抽出する。 |
---|
137 | $arrMainCat = array(); |
---|
138 | foreach ($arrRet as $cat) { |
---|
139 | if ($cat['level'] != 1) { |
---|
140 | continue; |
---|
141 | } |
---|
142 | |
---|
143 | // 子カテゴリーを持つかどうかを調べる。 |
---|
144 | $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']); |
---|
145 | $cat['has_children'] = count($arrChildrenID) > 0; |
---|
146 | $arrMainCat[] = $cat; |
---|
147 | } |
---|
148 | |
---|
149 | $objSubPage->arrCat = $arrMainCat; |
---|
150 | return $objSubPage; |
---|
151 | } |
---|
152 | } |
---|
153 | ?> |
---|