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

Revision 21867, 5.3 KB checked in by nakanishi, 12 years ago (diff)

#1831 Copyright Update

  • 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 
[16166]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[21867]5 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
[16166]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.
[16166]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
[16166]26
27/**
28 * カテゴリ一覧 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20344]34class LC_Page_Products_CategoryList extends LC_Page_Ex {
[16166]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() {
[19661]54        parent::process();
55        $this->action();
56        $this->sendResponse();
[16166]57    }
58
59    /**
[19661]60     * Page のAction
61     * @return void
62     */
[19865]63    function action() {
[21596]64
[18142]65        // カテゴリIDの正当性チェック
66        $this->lfCheckCategoryId();
[16166]67
[21317]68        // カテゴリ情報を取得する。
[20284]69        $objFormParam = $this->lfInitParam($_REQUEST);
70        $arrCategoryData = $this->lfGetCategories($objFormParam->getValue('category_id'), true, $this);
[20538]71        $this->arrCategory = $arrCategoryData['arrCategory'];
72        $this->arrChildren = $arrCategoryData['arrChildren'];
[19961]73        $this->tpl_subtitle = $this->arrCategory['category_name'];
[21596]74
[21743]75
[16166]76    }
77
78    /**
79     * デストラクタ.
80     *
81     * @return void
82     */
83    function destroy() {
84        parent::destroy();
85    }
86
[18142]87    /* カテゴリIDの正当性チェック */
[20284]88    function lfCheckCategoryId($category_id) {
[21441]89        if ($category_id && !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')) {
[20284]90            return 0;
91        }
92        return $category_id;
[18142]93    }
94
[16166]95    /**
[21317]96     * 選択されたカテゴリとその子カテゴリの情報を取得し、
[16166]97     * ページオブジェクトに格納する。
98     *
[21317]99     * @param string $category_id カテゴリID
100     * @param boolean $count_check 有効な商品がないカテゴリを除くかどうか
[16166]101     * @param object &$objPage ページオブジェクト
102     * @return void
103     */
104    function lfGetCategories($category_id, $count_check = false, &$objPage) {
[21317]105        // カテゴリの正しいIDを取得する。
[20284]106        $category_id = $this->lfCheckCategoryId($category_id);
[16166]107        if ($category_id == 0) {
[18276]108            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
[16166]109        }
110
[21317]111        $arrCategory = null;    // 選択されたカテゴリ
112        $arrChildren = array(); // 子カテゴリ
[16166]113
[20284]114        $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, $count_check);
[16166]115        foreach ($arrAll as $category) {
[21317]116            // 選択されたカテゴリの場合
[16166]117            if ($category['category_id'] == $category_id) {
118                $arrCategory = $category;
119                continue;
120            }
121
[21317]122            // 関係のないカテゴリはスキップする。
[16166]123            if ($category['parent_category_id'] != $category_id) {
124                continue;
125            }
126
[21317]127            // 子カテゴリの場合は、孫カテゴリが存在するかどうかを調べる。
[16166]128            $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
129            $category['has_children'] = count($arrGrandchildrenID) > 0;
130            $arrChildren[] = $category;
131        }
132
133        if (!isset($arrCategory)) {
[18276]134            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
[16166]135        }
136
[21317]137        // 子カテゴリの商品数を合計する。
[16166]138        $children_product_count = 0;
139        foreach ($arrChildren as $category) {
140            $children_product_count += $category['product_count'];
141        }
142
[21317]143        // 選択されたカテゴリに直属の商品がある場合は、子カテゴリの先頭に追加する。
[16166]144        if ($arrCategory['product_count'] > $children_product_count) {
[21317]145            $arrCategory['product_count'] -= $children_product_count; // 子カテゴリの商品数を除く。
[20562]146            $arrCategory['has_children'] = false; // 商品一覧ページに遷移させるため。
[16166]147            array_unshift($arrChildren, $arrCategory);
148        }
149
[20538]150        return array('arrChildren'=>$arrChildren, 'arrCategory'=>$arrCategory);
[16166]151    }
[20284]152
153    /**
154     * ユーザ入力値の処理
155     *
156     * @return object
157     */
158    function lfInitParam($arrRequest) {
[20501]159        $objFormParam = new SC_FormParam_Ex();
[21514]160        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
[20284]161        // 値の取得
162        $objFormParam->setParam($arrRequest);
163        // 入力値の変換
164        $objFormParam->convParam();
[21743]165        return $objFormParam;
[20284]166    }
167
[16166]168}
Note: See TracBrowser for help on using the repository browser.