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

Revision 21867, 6.6 KB checked in by nakanishi, 12 years ago (diff)

#1831 Copyright Update

  • 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-2012 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_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ex.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_Ex {
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() {
54        $this->action();
55        $this->sendResponse();
56    }
57
58    /**
59     * Page のアクション.
60     *
61     * @return void
62     */
63    function action() {
64
65        // モバイル判定
66        switch (SC_Display_Ex::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     * デストラクタ.
84     *
85     * @return void
86     */
87    function destroy() {
88        parent::destroy();
89    }
90
91    /**
92     * 選択中のカテゴリIDを取得する.
93     *
94     * @param array $arrRequest リクエスト配列
95     * @return array $arrCategoryId 選択中のカテゴリID
96     */
97    function lfGetSelectedCategoryId($arrRequest) {
98            // 商品ID取得
99        $product_id = '';
100        if (isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id'])) {
101            $product_id = $arrRequest['product_id'];
102        }
103        // カテゴリID取得
104        $category_id = '';
105        if (isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id'])) {
106            $category_id = $arrRequest['category_id'];
107        }
108        // 選択中のカテゴリIDを判定する
109        $objDb = new SC_Helper_DB_Ex();
110        $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
111        if (empty($arrCategoryId)) {
112            $arrCategoryId = array(0);
113        }
114        return $arrCategoryId;
115    }
116
117    /**
118     * カテゴリツリーの取得.
119     *
120     * @param array $arrParentCategoryId 親カテゴリの配列
121     * @param boolean $count_check 登録商品数をチェックする場合はtrue
122     * @return array $arrRet カテゴリツリーの配列を返す
123     */
124    function lfGetCatTree($arrParentCategoryId, $count_check = false) {
125        $objQuery =& SC_Query_Ex::getSingletonInstance();
126        $objDb = new SC_Helper_DB_Ex();
127        $col = '*';
128        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
129        // 登録商品数のチェック
130        if ($count_check) {
131            $where = 'del_flg = 0 AND product_count > 0';
132        } else {
133            $where = 'del_flg = 0';
134        }
135        $objQuery->setOption('ORDER BY rank DESC');
136        $arrRet = $objQuery->select($col, $from, $where);
137        foreach ($arrParentCategoryId as $category_id) {
138            $arrParentID = $objDb->sfGetParents(
139                'dtb_category',
140                'parent_category_id',
141                'category_id',
142                $category_id
143            );
144            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray(
145                $arrRet,
146                'parent_category_id',
147                'category_id',
148                $arrParentID
149            );
150            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
151                $arrRet,
152                'parent_category_id',
153                'category_id',
154                $category_id
155            );
156            $this->root_parent_id[] = $arrParentID[0];
157            $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
158            foreach ($arrRet as $key => $array) {
159                foreach ($arrDispID as $val) {
160                    if ($array['category_id'] == $val) {
161                        $arrRet[$key]['display'] = 1;
162                        break;
163                    }
164                }
165            }
166        }
167        return $arrRet;
168    }
169
170    /**
171     * メインカテゴリの取得.
172     *
173     * @param boolean $count_check 登録商品数をチェックする場合はtrue
174     * @return array $arrMainCat メインカテゴリの配列を返す
175     */
176    function lfGetMainCat($count_check = false) {
177        $objQuery =& SC_Query_Ex::getSingletonInstance();
178        $col = '*';
179        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
180        // メインカテゴリとその直下のカテゴリを取得する。
181        $where = 'level <= 2 AND del_flg = 0';
182        // 登録商品数のチェック
183        if ($count_check) {
184            $where .= ' AND product_count > 0';
185        }
186        $objQuery->setOption('ORDER BY rank DESC');
187        $arrRet = $objQuery->select($col, $from, $where);
188        // メインカテゴリを抽出する。
189        $arrMainCat = array();
190        foreach ($arrRet as $cat) {
191            if ($cat['level'] != 1) {
192                continue;
193            }
194            // 子カテゴリを持つかどうかを調べる。
195            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
196                $arrRet,
197                'parent_category_id',
198                'category_id',
199                $cat['category_id']
200            );
201            $cat['has_children'] = count($arrChildrenID) > 0;
202            $arrMainCat[] = $cat;
203        }
204        return $arrMainCat;
205    }
206}
Note: See TracBrowser for help on using the repository browser.