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

Revision 22926, 5.3 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 不明確な仕様にコメントを残した。
  • 親デストラクタを呼ぶだけの記述は可読性が悪くなると考え削除した。(上述のチケットで OS の仕様に依存したデストラクタとなるため、敢えてアプリケーション側で記述しておく意義は薄れたという認識のもと。)
  • 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     * 選択中のカテゴリIDを取得する.
83     *
84     * @param array $arrRequest リクエスト配列
85     * @return array $arrCategoryId 選択中のカテゴリID
86     */
87    function lfGetSelectedCategoryId($arrRequest)
88    {
89            // 商品ID取得
90        $product_id = '';
91        if (isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id'])) {
92            $product_id = $arrRequest['product_id'];
93        }
94        // カテゴリID取得
95        $category_id = '';
96        if (isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id'])) {
97            $category_id = $arrRequest['category_id'];
98        }
99        // 選択中のカテゴリIDを判定する
100        $objDb = new SC_Helper_DB_Ex();
101        $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
102        if (empty($arrCategoryId)) {
103            $arrCategoryId = array(0);
104        }
105
106        return $arrCategoryId;
107    }
108
109    /**
110     * カテゴリツリーの取得.
111     *
112     * @param array $arrParentCategoryId 親カテゴリの配列
113     * @param boolean $count_check 登録商品数をチェックする場合はtrue
114     * @return array $arrRet カテゴリツリーの配列を返す
115     */
116    function lfGetCatTree($arrParentCategoryId, $count_check = false)
117    {
118        $objCategory = new SC_Helper_Category_Ex($count_check);
119        $arrTree = $objCategory->getTree();
120
121        $this->arrParentID = array();
122        foreach ($arrParentCategoryId as $category_id) {
123            $arrParentID = $objCategory->getTreeTrail($category_id);
124            $this->arrParentID = array_merge($this->arrParentID, $arrParentID);
125            $this->root_parent_id[] = $arrParentID[0];
126        }
127
128        return $arrTree;
129    }
130
131    /**
132     * メインカテゴリの取得.
133     *
134     * @param boolean $count_check 登録商品数をチェックする場合はtrue
135     * @return array $arrMainCat メインカテゴリの配列を返す
136     */
137    function lfGetMainCat($count_check = false)
138    {
139        $objQuery =& SC_Query_Ex::getSingletonInstance();
140        $col = '*';
141        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
142        // メインカテゴリとその直下のカテゴリを取得する。
143        $where = 'level <= 2 AND del_flg = 0';
144        // 登録商品数のチェック
145        if ($count_check) {
146            $where .= ' AND product_count > 0';
147        }
148        $objQuery->setOption('ORDER BY rank DESC');
149        $arrRet = $objQuery->select($col, $from, $where);
150        // メインカテゴリを抽出する。
151        $arrMainCat = array();
152        foreach ($arrRet as $cat) {
153            if ($cat['level'] != 1) {
154                continue;
155            }
156            // 子カテゴリを持つかどうかを調べる。
157            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
158                $arrRet,
159                'parent_category_id',
160                'category_id',
161                $cat['category_id']
162            );
163            $cat['has_children'] = count($arrChildrenID) > 0;
164            $arrMainCat[] = $cat;
165        }
166
167        return $arrMainCat;
168    }
169}
Note: See TracBrowser for help on using the repository browser.