source: trunk/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php @ 18758

Revision 18758, 5.3 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.4 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=223

  • 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_PATH . "pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php");
26
27/**
28 * カテゴリ のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id:LC_Page_FrontParts_Bloc_Category.php 15532 2007-08-31 14:39:46Z nanasess $
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        $bloc_file = 'category.tpl';
47        $this->setTplMainpage($bloc_file);
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    function process() {
56        $objSubView = new SC_SiteView();
57        $objDb = new SC_Helper_DB_Ex();
58
59        // 選択中のカテゴリIDを判定する
60        $arrCategory_id = $objDb->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
61
62        // 選択中のカテゴリID
63        $this->tpl_category_id = empty($arrCategory_id) ? array(0) : $arrCategory_id;;
64        $this->lfGetCatTree($this->tpl_category_id, true, $this);
65
66        $objSubView->assignobj($this);
67        $objSubView->display($this->tpl_mainpage);
68    }
69
70    /**
71     * モバイルページを初期化する.
72     *
73     * @return void
74     */
75    function mobileInit() {
76        $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "frontparts/"
77            . BLOC_DIR . 'category.tpl';
78    }
79
80    /**
81     * Page のプロセス(モバイル).
82     *
83     * @return void
84     */
85    function mobileProcess() {
86        $objSubView = new SC_MobileView();
87
88       $this->lfGetMainCat(true, $this);
89
90        $objSubView->assignobj($this);
91        $objSubView->display($this->tpl_mainpage);
92    }
93
94    /**
95     * デストラクタ.
96     *
97     * @return void
98     */
99    function destroy() {
100        parent::destroy();
101    }
102
103    // カテゴリツリーの取得
104    function lfGetCatTree($arrParent_category_id, $count_check = false) {
105        $objQuery = new SC_Query();
106        $objDb = new SC_Helper_DB_Ex();
107        $col = "*";
108        $from = "dtb_category left join dtb_category_total_count using (category_id)";
109        // 登録商品数のチェック
110        if($count_check) {
111            $where = "del_flg = 0 AND product_count > 0";
112        } else {
113            $where = "del_flg = 0";
114        }
115        $objQuery->setOption("ORDER BY rank DESC");
116        $arrRet = $objQuery->select($col, $from, $where);
117
118        foreach ($arrParent_category_id as $category_id) {
119            $arrParentID = $objDb->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
120            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray($arrRet, 'parent_category_id', 'category_id', $arrParentID);
121            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $category_id);
122
123            $this->root_parent_id[] = $arrParentID[0];
124
125            $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
126
127            foreach($arrRet as $key => $array) {
128                foreach($arrDispID as $val) {
129                    if($array['category_id'] == $val) {
130                        $arrRet[$key]['display'] = 1;
131                        break;
132                    }
133                }
134            }
135        }
136
137        $this->arrTree = $arrRet;
138    }
139
140    // メインカテゴリーの取得
141    function lfGetMainCat($count_check = false, &$objSubPage) {
142        $objQuery = new SC_Query();
143        $col = "*";
144        $from = "dtb_category left join dtb_category_total_count using (category_id)";
145        // メインカテゴリーとその直下のカテゴリーを取得する。
146        $where = 'level <= 2 AND del_flg = 0';
147        // 登録商品数のチェック
148        if($count_check) {
149            $where .= " AND product_count > 0";
150        }
151        $objQuery->setOption("ORDER BY rank DESC");
152        $arrRet = $objQuery->select($col, $from, $where);
153
154        // メインカテゴリーを抽出する。
155        $arrMainCat = array();
156        foreach ($arrRet as $cat) {
157            if ($cat['level'] != 1) {
158                continue;
159            }
160
161            // 子カテゴリーを持つかどうかを調べる。
162            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']);
163            $cat['has_children'] = count($arrChildrenID) > 0;
164            $arrMainCat[] = $cat;
165        }
166
167        $objSubPage->arrCat = $arrMainCat;
168        return $objSubPage;
169    }
170}
171?>
Note: See TracBrowser for help on using the repository browser.