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

Revision 21420, 6.5 KB checked in by Seasoft, 12 years ago (diff)

#1613 (ソース整形・ソースコメントの改善)

  • Zend Framework PHP 標準コーディング規約への準拠を高めた
  • 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-2011 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    }
47
48    /**
49     * Page のプロセス.
50     *
51     * @return void
52     */
53    function process() {
54        $this->action();
55        $this->sendResponse();
56    }
57
58    /**
59     * Page のアクション.
60     *
61     * @return void
62     */
63    function action() {
64        // モバイル判定
65        switch ( SC_Display_Ex::detectDevice() ) {
66            case DEVICE_TYPE_MOBILE:
67                // メインカテゴリの取得
68                $this->arrCat = $this->lfGetMainCat(true);
69                break;
70            default:
71                // 選択中のカテゴリID
72                $this->tpl_category_id = $this->lfGetSelectedCategoryId($_GET);
73                // カテゴリツリーの取得
74                $this->arrTree = $this->lfGetCatTree($this->tpl_category_id, true);
75                break;
76        }
77    }
78
79    /**
80     * デストラクタ.
81     *
82     * @return void
83     */
84    function destroy() {
85        parent::destroy();
86    }
87
88    /**
89     * 選択中のカテゴリIDを取得する.
90     *
91     * @param array $arrRequest リクエスト配列
92     * @return array $arrCategoryId 選択中のカテゴリID
93     */
94    function lfGetSelectedCategoryId($arrRequest) {
95            // 商品ID取得
96        $product_id = '';
97        if ( isset($arrRequest['product_id']) && $arrRequest['product_id'] != '' && is_numeric($arrRequest['product_id']) ) {
98            $product_id = $arrRequest['product_id'];
99        }
100        // カテゴリID取得
101        $category_id = '';
102        if ( isset($arrRequest['category_id']) && $arrRequest['category_id'] != '' && is_numeric($arrRequest['category_id']) ) {
103            $category_id = $arrRequest['category_id'];
104        }
105        // 選択中のカテゴリIDを判定する
106        $objDb = new SC_Helper_DB_Ex();
107        $arrCategoryId = $objDb->sfGetCategoryId($product_id, $category_id);
108        if (empty($arrCategoryId)) {
109            $arrCategoryId = array(0);
110        }
111        return $arrCategoryId;
112    }
113
114    /**
115     * カテゴリツリーの取得.
116     *
117     * @param array $arrParentCategoryId 親カテゴリの配列
118     * @param boolean $count_check 登録商品数をチェックする場合はtrue
119     * @return array $arrRet カテゴリツリーの配列を返す
120     */
121    function lfGetCatTree($arrParentCategoryId, $count_check = false) {
122        $objQuery = new SC_Query_Ex();
123        $objDb = new SC_Helper_DB_Ex();
124        $col = '*';
125        $from = 'dtb_category left join dtb_category_total_count using (category_id)';
126        // 登録商品数のチェック
127        if($count_check) {
128            $where = 'del_flg = 0 AND product_count > 0';
129        } else {
130            $where = 'del_flg = 0';
131        }
132        $objQuery->setOption('ORDER BY rank DESC');
133        $arrRet = $objQuery->select($col, $from, $where);
134        foreach ($arrParentCategoryId as $category_id) {
135            $arrParentID = $objDb->sfGetParents(
136                'dtb_category',
137                'parent_category_id',
138                'category_id',
139                $category_id
140            );
141            $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray(
142                $arrRet,
143                'parent_category_id',
144                'category_id',
145                $arrParentID
146            );
147            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
148                $arrRet,
149                'parent_category_id',
150                'category_id',
151                $category_id
152            );
153            $this->root_parent_id[] = $arrParentID[0];
154            $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
155            foreach($arrRet as $key => $array) {
156                foreach($arrDispID as $val) {
157                    if($array['category_id'] == $val) {
158                        $arrRet[$key]['display'] = 1;
159                        break;
160                    }
161                }
162            }
163        }
164        return $arrRet;
165    }
166
167    /**
168     * メインカテゴリの取得.
169     *
170     * @param boolean $count_check 登録商品数をチェックする場合はtrue
171     * @return array $arrMainCat メインカテゴリの配列を返す
172     */
173    function lfGetMainCat($count_check = false) {
174        $objQuery = new SC_Query_Ex();
175        $col = '*';
176        $from = 'dtb_category left join dtb_category_total_count using (category_id)';
177        // メインカテゴリとその直下のカテゴリを取得する。
178        $where = 'level <= 2 AND del_flg = 0';
179        // 登録商品数のチェック
180        if($count_check) {
181            $where .= ' AND product_count > 0';
182        }
183        $objQuery->setOption('ORDER BY rank DESC');
184        $arrRet = $objQuery->select($col, $from, $where);
185        // メインカテゴリを抽出する。
186        $arrMainCat = array();
187        foreach ($arrRet as $cat) {
188            if ($cat['level'] != 1) {
189                continue;
190            }
191            // 子カテゴリを持つかどうかを調べる。
192            $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray(
193                $arrRet,
194                'parent_category_id',
195                'category_id',
196                $cat['category_id']
197            );
198            $cat['has_children'] = count($arrChildrenID) > 0;
199            $arrMainCat[] = $cat;
200        }
201        return $arrMainCat;
202    }
203}
Note: See TracBrowser for help on using the repository browser.