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

Revision 20116, 6.6 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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        switch ( SC_Display::detectDevice() ) {
67            case DEVICE_TYPE_MOBILE:
68                // メインカテゴリーの取得
69                $this->arrCat = $this->lfGetMainCat(true);
70                break;
71            default:
72                // 選択中のカテゴリID
73                $this->tpl_category_id = $this->lfGetSelectedCategoryId($_GET);
74                // カテゴリツリーの取得
75                $this->arrTree = $this->lfGetCatTree($this->tpl_category_id, true);
76                break;
77        }
78    }
79
80    /**
81     * デストラクタ.
82     *
83     * @return void
84     */
85    function destroy() {
86        parent::destroy();
87    }
88
89    /**
90     * 選択中のカテゴリIDを取得する.
91     *
92     * @param array $arrRequest リクエスト配列
93     * @return array $arrCategoryId 選択中のカテゴリID
94     */
95    function lfGetSelectedCategoryId($arrRequest) {
96            // 商品ID取得
97        $product_id = '';
98        if ( isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id']) ) {
99            $product_id = $arrRequest['product_id'];
100        }
101        // カテゴリID取得
102        $category_id = '';
103        if ( isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id']) ) {
104            $category_id = $arrRequest['category_id'];
105        }
106        // 選択中のカテゴリIDを判定する
107        $objDb = new SC_Helper_DB_Ex();
108        $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
109        if (empty($arrCategoryId)) {
110            $arrCategoryId = array(0);
111        }
112        return $arrCategoryId;
113    }
114
115    /**
116     * カテゴリツリーの取得.
117     *
118     * @param array $arrParentCategoryId 親カテゴリの配列
119     * @param boolean $count_check 登録商品数をチェックする場合はtrue
120     * @return array $arrRet カテゴリーツリーの配列を返す
121     */
122    function lfGetCatTree($arrParentCategoryId, $count_check = false) {
123        $objQuery = new SC_Query();
124        $objDb = new SC_Helper_DB_Ex();
125        $col = '*';
126        $from = 'dtb_category left join dtb_category_total_count using (category_id)';
127        // 登録商品数のチェック
128        if($count_check) {
129            $where = 'del_flg = 0 AND product_count > 0';
130        } else {
131            $where = 'del_flg = 0';
132        }
133        $objQuery->setOption('ORDER BY rank DESC');
134        $arrRet = $objQuery->select($col, $from, $where);
135        foreach ($arrParentCategoryId as $category_id) {
136            $arrParentID = $objDb->sfGetParents(
137                'dtb_category',
138                'parent_category_id',
139                'category_id',
140                $category_id
141            );
142            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray(
143                $arrRet,
144                'parent_category_id',
145                'category_id',
146                $arrParentID
147            );
148            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
149                $arrRet,
150                'parent_category_id',
151                'category_id',
152                $category_id
153            );
154            $this->root_parent_id[] = $arrParentID[0];
155            $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
156            foreach($arrRet as $key => $array) {
157                foreach($arrDispID as $val) {
158                    if($array['category_id'] == $val) {
159                        $arrRet[$key]['display'] = 1;
160                        break;
161                    }
162                }
163            }
164        }
165        return $arrRet;
166    }
167
168    /**
169     * メインカテゴリーの取得.
170     *
171     * @param boolean $count_check 登録商品数をチェックする場合はtrue
172     * @return array $arrMainCat メインカテゴリーの配列を返す
173     */
174    function lfGetMainCat($count_check = false) {
175        $objQuery = new SC_Query();
176        $col = '*';
177        $from = 'dtb_category left join dtb_category_total_count using (category_id)';
178        // メインカテゴリーとその直下のカテゴリーを取得する。
179        $where = 'level <= 2 AND del_flg = 0';
180        // 登録商品数のチェック
181        if($count_check) {
182            $where .= ' AND product_count > 0';
183        }
184        $objQuery->setOption('ORDER BY rank DESC');
185        $arrRet = $objQuery->select($col, $from, $where);
186        // メインカテゴリーを抽出する。
187        $arrMainCat = array();
188        foreach ($arrRet as $cat) {
189            if ($cat['level'] != 1) {
190                continue;
191            }
192            // 子カテゴリーを持つかどうかを調べる。
193            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
194                $arrRet,
195                'parent_category_id',
196                'category_id',
197                $cat['category_id']
198            );
199            $cat['has_children'] = count($arrChildrenID) > 0;
200            $arrMainCat[] = $cat;
201        }
202        return $arrMainCat;
203    }
204}
205?>
Note: See TracBrowser for help on using the repository browser.