source: branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_CategoryList.php @ 23605

Revision 23605, 5.1 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • 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-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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * カテゴリ一覧 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Products_CategoryList extends LC_Page_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43    }
44
45    /**
46     * Page のプロセス.
47     *
48     * @return void
49     */
50    public function process()
51    {
52        parent::process();
53        $this->action();
54        $this->sendResponse();
55    }
56
57    /**
58     * Page のAction
59     * @return void
60     */
61    public function action()
62    {
63        $objFormParam = $this->lfInitParam($_REQUEST);
64
65        // カテゴリIDの正当性チェック
66        $category_id = $this->lfCheckCategoryId($objFormParam->getValue('category_id'));
67        if ($category_id == 0) {
68            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
69        }
70
71        // カテゴリ情報を取得する。
72        $arrCategoryData = $this->lfGetCategories($category_id, true);
73        $this->arrCategory = $arrCategoryData['arrCategory'];
74        $this->arrChildren = $arrCategoryData['arrChildren'];
75        $this->tpl_subtitle = $this->arrCategory['category_name'];
76    }
77
78    /* カテゴリIDの正当性チェック */
79
80    /**
81     * @return string
82     */
83    public function lfCheckCategoryId($category_id)
84    {
85        if ($category_id && !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array) $category_id, 'del_flg = 0')) {
86            return 0;
87        }
88
89        return $category_id;
90    }
91
92    /**
93     * 選択されたカテゴリとその子カテゴリの情報を取得し、
94     * ページオブジェクトに格納する。
95     *
96     * @param  string  $category_id カテゴリID
97     * @param  boolean $count_check 有効な商品がないカテゴリを除くかどうか
98     * @return void
99     */
100    public function lfGetCategories($category_id, $count_check = false)
101    {
102        $arrCategory = null;    // 選択されたカテゴリ
103        $arrChildren = array(); // 子カテゴリ
104
105        $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, $count_check);
106        foreach ($arrAll as $category) {
107            // 選択されたカテゴリの場合
108            if ($category['category_id'] == $category_id) {
109                $arrCategory = $category;
110                continue;
111            }
112
113            // 関係のないカテゴリはスキップする。
114            if ($category['parent_category_id'] != $category_id) {
115                continue;
116            }
117
118            // 子カテゴリの場合は、孫カテゴリが存在するかどうかを調べる。
119            $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
120            $category['has_children'] = count($arrGrandchildrenID) > 0;
121            $arrChildren[] = $category;
122        }
123
124        if (!isset($arrCategory)) {
125            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
126        }
127
128        // 子カテゴリの商品数を合計する。
129        $children_product_count = 0;
130        foreach ($arrChildren as $category) {
131            $children_product_count += $category['product_count'];
132        }
133
134        // 選択されたカテゴリに直属の商品がある場合は、子カテゴリの先頭に追加する。
135        if ($arrCategory['product_count'] > $children_product_count) {
136            $arrCategory['product_count'] -= $children_product_count; // 子カテゴリの商品数を除く。
137            $arrCategory['has_children'] = false; // 商品一覧ページに遷移させるため。
138            array_unshift($arrChildren, $arrCategory);
139        }
140
141        return array('arrChildren'=>$arrChildren, 'arrCategory'=>$arrCategory);
142    }
143
144    /**
145     * ユーザ入力値の処理
146     *
147     * @return SC_FormParam_Ex
148     */
149    public function lfInitParam($arrRequest)
150    {
151        $objFormParam = new SC_FormParam_Ex();
152        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
153        // 値の取得
154        $objFormParam->setParam($arrRequest);
155        // 入力値の変換
156        $objFormParam->convParam();
157
158        return $objFormParam;
159    }
160}
Note: See TracBrowser for help on using the repository browser.