source: branches/version-2_12-dev/data/class/helper/SC_Helper_Category.php @ 22588

Revision 22588, 2.6 KB checked in by pineray, 11 years ago (diff)

#2166 カテゴリーツリーの生成処理を別ファイルへ分離

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
24/**
25 * カテゴリーを管理するヘルパークラス.
26 *
27 * @package Helper
28 * @author pineray
29 * @version $Id:$
30 */
31class SC_Helper_Category
32{
33    /**
34     * カテゴリー一覧の取得.
35     *
36     * @param boolean $count_check 登録商品数をチェックする場合はtrue
37     * @param boolean $cid_to_key 配列のキーをカテゴリーIDにする場合はtrue
38     * @return array カテゴリー一覧の配列
39     */
40    public function getList($count_check = FALSE, $cid_to_key = FALSE)
41    {
42        $objQuery =& SC_Query_Ex::getSingletonInstance();
43        $col = '*';
44        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
45        // 登録商品数のチェック
46        if ($count_check) {
47            $where = 'del_flg = 0 AND product_count > 0';
48        } else {
49            $where = 'del_flg = 0';
50        }
51        $objQuery->setOption('ORDER BY rank DESC');
52        $arrCategory = $objQuery->select($col, $from, $where);
53
54        if ($cid_to_key) {
55            // 配列のキーをカテゴリーIDに
56            $arrTmp = array();
57            foreach ($arrCategory as $category) {
58                $arrTmp[$category['category_id']] = $category;
59            }
60            $arrCategory =& $arrTmp;
61            unset($arrTmp);
62        }
63       
64        return $arrCategory;
65    }
66
67    /**
68     * カテゴリーツリーの取得.
69     *
70     * @param boolean $count_check 登録商品数をチェックする場合はtrue
71     * @return type
72     */
73    public function getTree($count_check = FALSE)
74    {
75        $arrList = $this->getList($count_check);
76        $arrTree = SC_Utils_Ex::buildTree('category_id', 'parent_category_id', LEVEL_MAX, $arrList);
77        return $arrTree;
78    }
79}
Note: See TracBrowser for help on using the repository browser.