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

Revision 22595, 5.9 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        $objCategory = new SC_Helper_Category_Ex($count_check);
133        $arrTree = $objCategory->getTree();
134
135        $arrCategory = $objCategory->getList();
136        foreach ($arrParentCategoryId as $category_id) {
137            $arrParentID = $objCategory->getTreeTrail($category_id);
138            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray(
139                $arrCategory,
140                'parent_category_id',
141                'category_id',
142                $arrParentID
143            );
144            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
145                $arrCategory,
146                'parent_category_id',
147                'category_id',
148                $category_id
149            );
150            $this->root_parent_id[] = $arrParentID[0];
151            $this->arrDispID = array_merge($arrBrothersID, $arrChildrenID);
152        }
153
154        return $arrTree;
155    }
156
157    /**
158     * メインカテゴリの取得.
159     *
160     * @param boolean $count_check 登録商品数をチェックする場合はtrue
161     * @return array $arrMainCat メインカテゴリの配列を返す
162     */
163    function lfGetMainCat($count_check = false)
164    {
165        $objQuery =& SC_Query_Ex::getSingletonInstance();
166        $col = '*';
167        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
168        // メインカテゴリとその直下のカテゴリを取得する。
169        $where = 'level <= 2 AND del_flg = 0';
170        // 登録商品数のチェック
171        if ($count_check) {
172            $where .= ' AND product_count > 0';
173        }
174        $objQuery->setOption('ORDER BY rank DESC');
175        $arrRet = $objQuery->select($col, $from, $where);
176        // メインカテゴリを抽出する。
177        $arrMainCat = array();
178        foreach ($arrRet as $cat) {
179            if ($cat['level'] != 1) {
180                continue;
181            }
182            // 子カテゴリを持つかどうかを調べる。
183            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
184                $arrRet,
185                'parent_category_id',
186                'category_id',
187                $cat['category_id']
188            );
189            $cat['has_children'] = count($arrChildrenID) > 0;
190            $arrMainCat[] = $cat;
191        }
192        return $arrMainCat;
193    }
194}
Note: See TracBrowser for help on using the repository browser.