source: branches/version-2_13_3/data/class/helper/SC_Helper_Category.php @ 23656

Revision 23656, 6.1 KB checked in by kim, 9 years ago (diff)

#2590 SC_Helper_Category が持つプロパティのアクセス修飾子を変更

r23637 を2.13.3ブランチにマージ

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 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    protected $count_check;
34
35    /**
36     * コンストラクター
37     *
38     * @param boolean $count_check 登録商品数をチェックする場合はtrue
39     */
40    public function __construct($count_check = FALSE)
41    {
42        $this->count_check = $count_check;
43    }
44
45    /**
46     * カテゴリーの情報を取得.
47     *
48     * @param  integer $category_id カテゴリーID
49     * @return array
50     */
51    public function get($category_id)
52    {
53        $objQuery =& SC_Query_Ex::getSingletonInstance();
54        $col = 'dtb_category.*, dtb_category_total_count.product_count';
55        $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
56        $where = 'dtb_category.category_id = ? AND del_flg = 0';
57        // 登録商品数のチェック
58        if ($this->count_check) {
59            $where .= ' AND product_count > 0';
60        }
61        $arrRet = $objQuery->getRow($col, $from, $where, array($category_id));
62
63        return $arrRet;
64    }
65
66    /**
67     * カテゴリー一覧の取得.
68     *
69     * @param  boolean $cid_to_key 配列のキーをカテゴリーIDにする場合はtrue
70     * @return array   カテゴリー一覧の配列
71     */
72    public function getList($cid_to_key = FALSE)
73    {
74        static $arrCategory = array(), $cidIsKey = array();
75
76        if (!isset($arrCategory[$this->count_check])) {
77            $objQuery =& SC_Query_Ex::getSingletonInstance();
78            $col = 'dtb_category.*, dtb_category_total_count.product_count';
79            $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
80            // 登録商品数のチェック
81            if ($this->count_check) {
82                $where = 'del_flg = 0 AND product_count > 0';
83            } else {
84                $where = 'del_flg = 0';
85            }
86            $objQuery->setOption('ORDER BY rank DESC');
87            $arrTmp = $objQuery->select($col, $from, $where);
88
89            $arrCategory[$this->count_check] = $arrTmp;
90        }
91
92        if ($cid_to_key) {
93            if (!isset($cidIsKey[$this->count_check])) {
94                // 配列のキーをカテゴリーIDに
95                $cidIsKey[$this->count_check] = SC_Utils_Ex::makeArrayIDToKey('category_id', $arrCategory[$this->count_check]);
96            }
97
98            return $cidIsKey[$this->count_check];
99        }
100
101        return $arrCategory[$this->count_check];
102    }
103
104    /**
105     * カテゴリーツリーの取得.
106     *
107     * @return type
108     */
109    public function getTree()
110    {
111        static $arrTree = array();
112        if (!isset($arrTree[$this->count_check])) {
113            $arrList = $this->getList();
114            $arrTree[$this->count_check] = SC_Utils_Ex::buildTree('category_id', 'parent_category_id', LEVEL_MAX, $arrList);
115        }
116
117        return $arrTree[$this->count_check];
118    }
119
120    /**
121     * 親カテゴリーIDの配列を取得.
122     *
123     * @param  integer $category_id 起点のカテゴリーID
124     * @param  boolean $id_only     IDだけの配列を返す場合はtrue
125     * @return array
126     */
127    public function getTreeTrail($category_id, $id_only = TRUE)
128    {
129        $arrCategory = $this->getList(TRUE);
130        $arrTrailID = SC_Utils_Ex::getTreeTrail($category_id, 'category_id', 'parent_category_id', $arrCategory, TRUE, 0, $id_only);
131
132        return $arrTrailID;
133    }
134
135    /**
136     * 指定カテゴリーの子孫カテゴリーを取得
137     *
138     * @param int $category_id カテゴリーID
139     * @return array
140     */
141    public function getTreeBranch($category_id) {
142        $arrTree = $this->getTree();
143        $arrTrail = $this->getTreeTrail($category_id, true);
144
145        // ルートから指定カテゴリーまでたどる.
146        foreach ($arrTrail as $parent_id) {
147            $nextTree = array();
148            foreach ($arrTree as $branch) {
149                if ($branch['category_id'] == $parent_id && isset($branch['children'])) {
150                    $nextTree = $branch['children'];
151                }
152            }
153            $arrTree = $nextTree;
154        }
155
156        return $arrTree;
157    }
158
159    /**
160     * カテゴリーの削除
161     *
162     * @param int $category_id カテゴリーID
163     * @return void
164     */
165    public function delete($category_id) {
166        $objDb = new SC_Helper_DB_Ex();
167        // ランク付きレコードの削除(※処理負荷を考慮してレコードごと削除する。)
168        $objDb->sfDeleteRankRecord('dtb_category', 'category_id', $category_id, '', true);
169    }
170
171    /**
172     * 有効なカテゴリーIDかチェックする.
173     *
174     * @param int $category_id
175     * @param bool $include_deleted
176     * @return bool
177     */
178    public function isValidCategoryId($category_id, $include_deleted = false) {
179        if ($include_deleted) {
180            $where = '';
181        } else {
182            $where = 'del_flg = 0';
183        }
184        if (
185            SC_Utils_Ex::sfIsInt($category_id)
186            && !SC_Utils_Ex::sfIsZeroFilling($category_id)
187            && SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', array($category_id), $where)
188        ) {
189            return true;
190        }
191        return false;
192    }
193}
Note: See TracBrowser for help on using the repository browser.