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

Revision 22588, 6.1 KB checked in by pineray, 11 years ago (diff)

#2166 カテゴリーツリーの生成処理を別ファイルへ分離

  • 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-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// {{{ 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    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init()
46    {
47        parent::init();
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    function action()
67    {
68
69        // モバイル判定
70        switch (SC_Display_Ex::detectDevice()) {
71            case DEVICE_TYPE_MOBILE:
72                // メインカテゴリの取得
73                $this->arrCat = $this->lfGetMainCat(true);
74                break;
75            default:
76                // 選択中のカテゴリID
77                $this->tpl_category_id = $this->lfGetSelectedCategoryId($_GET);
78                // カテゴリツリーの取得
79                $this->arrTree = $this->lfGetCatTree($this->tpl_category_id, true);
80                break;
81        }
82
83
84    }
85
86    /**
87     * デストラクタ.
88     *
89     * @return void
90     */
91    function destroy()
92    {
93        parent::destroy();
94    }
95
96    /**
97     * 選択中のカテゴリIDを取得する.
98     *
99     * @param array $arrRequest リクエスト配列
100     * @return array $arrCategoryId 選択中のカテゴリID
101     */
102    function lfGetSelectedCategoryId($arrRequest)
103    {
104            // 商品ID取得
105        $product_id = '';
106        if (isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id'])) {
107            $product_id = $arrRequest['product_id'];
108        }
109        // カテゴリID取得
110        $category_id = '';
111        if (isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id'])) {
112            $category_id = $arrRequest['category_id'];
113        }
114        // 選択中のカテゴリIDを判定する
115        $objDb = new SC_Helper_DB_Ex();
116        $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
117        if (empty($arrCategoryId)) {
118            $arrCategoryId = array(0);
119        }
120        return $arrCategoryId;
121    }
122
123    /**
124     * カテゴリツリーの取得.
125     *
126     * @param array $arrParentCategoryId 親カテゴリの配列
127     * @param boolean $count_check 登録商品数をチェックする場合はtrue
128     * @return array $arrRet カテゴリツリーの配列を返す
129     */
130    function lfGetCatTree($arrParentCategoryId, $count_check = false)
131    {
132        $objDb = new SC_Helper_DB_Ex();
133        $objCategory = new SC_Helper_Category_Ex();
134        $arrTree = $objCategory->getTree($count_check);
135
136        $arrCategory = $objCategory->getList($count_check);
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                $arrCategory,
146                'parent_category_id',
147                'category_id',
148                $arrParentID
149            );
150            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
151                $arrCategory,
152                'parent_category_id',
153                'category_id',
154                $category_id
155            );
156            $this->root_parent_id[] = $arrParentID[0];
157            $this->arrDispID = array_merge($arrBrothersID, $arrChildrenID);
158        }
159
160        return $arrTree;
161    }
162
163    /**
164     * メインカテゴリの取得.
165     *
166     * @param boolean $count_check 登録商品数をチェックする場合はtrue
167     * @return array $arrMainCat メインカテゴリの配列を返す
168     */
169    function lfGetMainCat($count_check = false)
170    {
171        $objQuery =& SC_Query_Ex::getSingletonInstance();
172        $col = '*';
173        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
174        // メインカテゴリとその直下のカテゴリを取得する。
175        $where = 'level <= 2 AND del_flg = 0';
176        // 登録商品数のチェック
177        if ($count_check) {
178            $where .= ' AND product_count > 0';
179        }
180        $objQuery->setOption('ORDER BY rank DESC');
181        $arrRet = $objQuery->select($col, $from, $where);
182        // メインカテゴリを抽出する。
183        $arrMainCat = array();
184        foreach ($arrRet as $cat) {
185            if ($cat['level'] != 1) {
186                continue;
187            }
188            // 子カテゴリを持つかどうかを調べる。
189            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
190                $arrRet,
191                'parent_category_id',
192                'category_id',
193                $cat['category_id']
194            );
195            $cat['has_children'] = count($arrChildrenID) > 0;
196            $arrMainCat[] = $cat;
197        }
198        return $arrMainCat;
199    }
200}
Note: See TracBrowser for help on using the repository browser.