source: branches/version-2_5-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php @ 20076

Revision 20076, 6.4 KB checked in by yomoro, 13 years ago (diff)

#986 リファクタリング

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