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

Revision 22856, 5.5 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • 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
24require_once CLASS_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ex.php';
25
26/**
27 * カテゴリ のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_FrontParts_Bloc_Category extends LC_Page_FrontParts_Bloc_Ex
34{
35    public $arrParentID;
36
37    /**
38     * Page を初期化する.
39     *
40     * @return void
41     */
42    function init()
43    {
44        parent::init();
45    }
46
47    /**
48     * Page のプロセス.
49     *
50     * @return void
51     */
52    function process()
53    {
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     * @return void
85     */
86    function destroy()
87    {
88        parent::destroy();
89    }
90
91    /**
92     * 選択中のカテゴリIDを取得する.
93     *
94     * @param array $arrRequest リクエスト配列
95     * @return array $arrCategoryId 選択中のカテゴリID
96     */
97    function lfGetSelectedCategoryId($arrRequest)
98    {
99            // 商品ID取得
100        $product_id = '';
101        if (isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id'])) {
102            $product_id = $arrRequest['product_id'];
103        }
104        // カテゴリID取得
105        $category_id = '';
106        if (isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id'])) {
107            $category_id = $arrRequest['category_id'];
108        }
109        // 選択中のカテゴリIDを判定する
110        $objDb = new SC_Helper_DB_Ex();
111        $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
112        if (empty($arrCategoryId)) {
113            $arrCategoryId = array(0);
114        }
115
116        return $arrCategoryId;
117    }
118
119    /**
120     * カテゴリツリーの取得.
121     *
122     * @param array $arrParentCategoryId 親カテゴリの配列
123     * @param boolean $count_check 登録商品数をチェックする場合はtrue
124     * @return array $arrRet カテゴリツリーの配列を返す
125     */
126    function lfGetCatTree($arrParentCategoryId, $count_check = false)
127    {
128        $objCategory = new SC_Helper_Category_Ex($count_check);
129        $arrTree = $objCategory->getTree();
130
131        $this->arrParentID = array();
132        foreach ($arrParentCategoryId as $category_id) {
133            $arrParentID = $objCategory->getTreeTrail($category_id);
134            $this->arrParentID = array_merge($this->arrParentID, $arrParentID);
135            $this->root_parent_id[] = $arrParentID[0];
136        }
137
138        return $arrTree;
139    }
140
141    /**
142     * メインカテゴリの取得.
143     *
144     * @param boolean $count_check 登録商品数をチェックする場合はtrue
145     * @return array $arrMainCat メインカテゴリの配列を返す
146     */
147    function lfGetMainCat($count_check = false)
148    {
149        $objQuery =& SC_Query_Ex::getSingletonInstance();
150        $col = '*';
151        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
152        // メインカテゴリとその直下のカテゴリを取得する。
153        $where = 'level <= 2 AND del_flg = 0';
154        // 登録商品数のチェック
155        if ($count_check) {
156            $where .= ' AND product_count > 0';
157        }
158        $objQuery->setOption('ORDER BY rank DESC');
159        $arrRet = $objQuery->select($col, $from, $where);
160        // メインカテゴリを抽出する。
161        $arrMainCat = array();
162        foreach ($arrRet as $cat) {
163            if ($cat['level'] != 1) {
164                continue;
165            }
166            // 子カテゴリを持つかどうかを調べる。
167            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
168                $arrRet,
169                'parent_category_id',
170                'category_id',
171                $cat['category_id']
172            );
173            $cat['has_children'] = count($arrChildrenID) > 0;
174            $arrMainCat[] = $cat;
175        }
176
177        return $arrMainCat;
178    }
179}
Note: See TracBrowser for help on using the repository browser.