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

Revision 22589, 6.1 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
RevLine 
[15367]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[22206]5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
[15367]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15367]22 */
23
24// {{{ requires
[21771]25require_once CLASS_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ex.php';
[15367]26
27/**
28 * カテゴリ のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
[19903]32 * @version $Id$
[15367]33 */
[22567]34class LC_Page_FrontParts_Bloc_Category extends LC_Page_FrontParts_Bloc_Ex
35{
[15367]36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
[22567]45    function init()
46    {
[15367]47        parent::init();
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
[22567]55    function process()
56    {
[19726]57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
[22567]66    function action()
67    {
[21596]68
[20076]69        // モバイル判定
[21442]70        switch (SC_Display_Ex::detectDevice()) {
[20108]71            case DEVICE_TYPE_MOBILE:
[21317]72                // メインカテゴリの取得
[20108]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;
[19903]81        }
[21596]82
[21743]83
[15367]84    }
85
86    /**
87     * デストラクタ.
88     *
89     * @return void
90     */
[22567]91    function destroy()
92    {
[15367]93        parent::destroy();
94    }
95
[20076]96    /**
97     * 選択中のカテゴリIDを取得する.
98     *
[20108]99     * @param array $arrRequest リクエスト配列
[20076]100     * @return array $arrCategoryId 選択中のカテゴリID
101     */
[22567]102    function lfGetSelectedCategoryId($arrRequest)
103    {
[20086]104            // 商品ID取得
105        $product_id = '';
[21442]106        if (isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id'])) {
[20108]107            $product_id = $arrRequest['product_id'];
[20076]108        }
109        // カテゴリID取得
[20086]110        $category_id = '';
[21442]111        if (isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id'])) {
[20108]112            $category_id = $arrRequest['category_id'];
[20076]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
[21317]128     * @return array $arrRet カテゴリツリーの配列を返す
[20076]129     */
[22567]130    function lfGetCatTree($arrParentCategoryId, $count_check = false)
131    {
[15367]132        $objDb = new SC_Helper_DB_Ex();
[22589]133        $objCategory = new SC_Helper_Category_Ex($count_check);
134        $arrTree = $objCategory->getTree();
[22586]135
[22589]136        $arrCategory = $objCategory->getList();
[20076]137        foreach ($arrParentCategoryId as $category_id) {
138            $arrParentID = $objDb->sfGetParents(
139                'dtb_category',
140                'parent_category_id',
141                'category_id',
142                $category_id
143            );
144            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray(
[22588]145                $arrCategory,
[20076]146                'parent_category_id',
147                'category_id',
148                $arrParentID
149            );
150            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
[22588]151                $arrCategory,
[20076]152                'parent_category_id',
153                'category_id',
154                $category_id
155            );
[16546]156            $this->root_parent_id[] = $arrParentID[0];
[22586]157            $this->arrDispID = array_merge($arrBrothersID, $arrChildrenID);
[15367]158        }
[22586]159
160        return $arrTree;
[15367]161    }
[16147]162
[20076]163    /**
[21317]164     * メインカテゴリの取得.
[20076]165     *
166     * @param boolean $count_check 登録商品数をチェックする場合はtrue
[21317]167     * @return array $arrMainCat メインカテゴリの配列を返す
[20076]168     */
[22567]169    function lfGetMainCat($count_check = false)
170    {
[21750]171        $objQuery =& SC_Query_Ex::getSingletonInstance();
[20076]172        $col = '*';
[21809]173        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
[21317]174        // メインカテゴリとその直下のカテゴリを取得する。
[16147]175        $where = 'level <= 2 AND del_flg = 0';
176        // 登録商品数のチェック
[21441]177        if ($count_check) {
[20076]178            $where .= ' AND product_count > 0';
[16147]179        }
[20076]180        $objQuery->setOption('ORDER BY rank DESC');
[16147]181        $arrRet = $objQuery->select($col, $from, $where);
[21317]182        // メインカテゴリを抽出する。
[16147]183        $arrMainCat = array();
184        foreach ($arrRet as $cat) {
185            if ($cat['level'] != 1) {
186                continue;
187            }
[21317]188            // 子カテゴリを持つかどうかを調べる。
[20076]189            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
190                $arrRet,
191                'parent_category_id',
192                'category_id',
193                $cat['category_id']
194            );
[16147]195            $cat['has_children'] = count($arrChildrenID) > 0;
196            $arrMainCat[] = $cat;
197        }
[20076]198        return $arrMainCat;
[16147]199    }
[15367]200}
Note: See TracBrowser for help on using the repository browser.