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

Revision 19903, 4.9 KB checked in by kotani, 11 years ago (diff)

#880(mobile/sphoneディレクトリを削除)に対応。まずmobileのみ意図通りの動作になるように一部コミット(frontpartsディレクトリ)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-2010 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_REALDIR . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc.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 {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->setTplMainpage('category.tpl');
47    }
48
49    /**
50     * Page のプロセス.
51     *
52     * @return void
53     */
54    function process() {
55        $this->action();
56        $this->sendResponse();
57    }
58
59    /**
60     * Page のアクション.
61     *
62     * @return void
63     */
64    function action() {
65        if(Net_UserAgent_Mobile::isMobile() === true) {
66            $this->lfGetMainCat(true, $this);
67        } else {
68            $objDb = new SC_Helper_DB_Ex();
69
70            // 選択中のカテゴリIDを判定する
71            $arrCategory_id = $objDb->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
72
73            // 選択中のカテゴリID
74            $this->tpl_category_id = empty($arrCategory_id) ? array(0) : $arrCategory_id;;
75            $this->lfGetCatTree($this->tpl_category_id, true, $this);
76        }
77    }
78
79    /**
80     * デストラクタ.
81     *
82     * @return void
83     */
84    function destroy() {
85        parent::destroy();
86    }
87
88    // カテゴリツリーの取得
89    function lfGetCatTree($arrParent_category_id, $count_check = false) {
90        $objQuery = new SC_Query();
91        $objDb = new SC_Helper_DB_Ex();
92        $col = "*";
93        $from = "dtb_category left join dtb_category_total_count using (category_id)";
94        // 登録商品数のチェック
95        if($count_check) {
96            $where = "del_flg = 0 AND product_count > 0";
97        } else {
98            $where = "del_flg = 0";
99        }
100        $objQuery->setOption("ORDER BY rank DESC");
101        $arrRet = $objQuery->select($col, $from, $where);
102
103        foreach ($arrParent_category_id as $category_id) {
104            $arrParentID = $objDb->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
105            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray($arrRet, 'parent_category_id', 'category_id', $arrParentID);
106            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $category_id);
107
108            $this->root_parent_id[] = $arrParentID[0];
109
110            $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
111
112            foreach($arrRet as $key => $array) {
113                foreach($arrDispID as $val) {
114                    if($array['category_id'] == $val) {
115                        $arrRet[$key]['display'] = 1;
116                        break;
117                    }
118                }
119            }
120        }
121
122        $this->arrTree = $arrRet;
123    }
124
125    // メインカテゴリーの取得
126    function lfGetMainCat($count_check = false, &$objSubPage) {
127        $objQuery = new SC_Query();
128        $col = "*";
129        $from = "dtb_category left join dtb_category_total_count using (category_id)";
130        // メインカテゴリーとその直下のカテゴリーを取得する。
131        $where = 'level <= 2 AND del_flg = 0';
132        // 登録商品数のチェック
133        if($count_check) {
134            $where .= " AND product_count > 0";
135        }
136        $objQuery->setOption("ORDER BY rank DESC");
137        $arrRet = $objQuery->select($col, $from, $where);
138
139        // メインカテゴリーを抽出する。
140        $arrMainCat = array();
141        foreach ($arrRet as $cat) {
142            if ($cat['level'] != 1) {
143                continue;
144            }
145
146            // 子カテゴリーを持つかどうかを調べる。
147            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']);
148            $cat['has_children'] = count($arrChildrenID) > 0;
149            $arrMainCat[] = $cat;
150        }
151
152        $objSubPage->arrCat = $arrMainCat;
153        return $objSubPage;
154    }
155}
156?>
Note: See TracBrowser for help on using the repository browser.