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

Revision 19713, 5.9 KB checked in by nanasess, 13 years ago (diff)
  • #748(モバイルのデザイン管理機能)
    • dtb_pagelayout, dtb_bloc, dtb_blocposition のデータを追加
    • dtb_blocposition.filename を削除
    • dtb_bloc.filename を device_type_id と filename のユニークキーへ変更
  • #787(スマートフォン対応)
    • data/install.php のモバイル関連の定数を data/class/SC_Initial.php へ移動
    • テンプレート, PHPファイル追加
  • #832 SC_Helper_PageLayout#sfGetPageLayout()) の呼び出しを1ヶ所に集約
  • #820 フラグ, マスタIDの値を定数にする
    • mtb_target の値を定数化
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-2010 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_PATH . "pages/LC_Page.php");
26
27/**
28 * カテゴリ一覧 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Products_CategoryList extends LC_Page {
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        parent::process();
55        $this->action();
56        $this->sendResponse();
57    }
58
59    /**
60     * Page のAction
61     * @return void
62     */
63    function action() {}
64
65    /**
66     * モバイルページを初期化する.
67     *
68     * @return void
69     */
70    function mobileInit() {
71        $this->init();
72        $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . 'products/category_list.tpl';
73        $this->tpl_title = 'カテゴリ一覧ページ';
74    }
75
76    /**
77     * Page のプロセス(モバイル).
78     *
79     * @return void
80     */
81    function mobileProcess(){
82        parent::mobileProcess();
83        $this->mobileAction();
84        $this->sendResponse();
85    }
86
87    /**
88     * Page のAction(モバイル).
89     *
90     * @return void
91     */
92    function mobileAction() {
93        // カテゴリIDの正当性チェック
94        $this->lfCheckCategoryId();
95       
96        //$objView = new SC_MobileView();
97
98        // カテゴリー情報を取得する。
99        $this->lfGetCategories(@$_GET['category_id'], true, $this);
100
101        //$objView->assignobj($this);
102        //$objView->display(SITE_FRAME);
103    }
104
105    /**
106     * デストラクタ.
107     *
108     * @return void
109     */
110    function destroy() {
111        parent::destroy();
112    }
113
114    /* カテゴリIDの正当性チェック */
115    function lfCheckCategoryId() {
116        $objDb = new SC_Helper_DB_Ex();
117        $category_id = $_POST['category_id'] ? $_POST['category_id'] : $_GET['category_id'];
118        if (!defined('MOBILE_SITE') && !isset($_REQUEST['category_id']))
119            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
120        if ($category_id
121                && (!SC_Utils_Ex::sfIsInt($category_id)
122                || SC_Utils_Ex::sfIsZeroFilling($category_id)
123                || !$objDb->sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')))
124            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
125    }
126
127    /**
128     * 選択されたカテゴリーとその子カテゴリーの情報を取得し、
129     * ページオブジェクトに格納する。
130     *
131     * @param string $category_id カテゴリーID
132     * @param boolean $count_check 有効な商品がないカテゴリーを除くかどうか
133     * @param object &$objPage ページオブジェクト
134     * @return void
135     */
136    function lfGetCategories($category_id, $count_check = false, &$objPage) {
137        $objDb = new SC_Helper_DB_Ex();
138        // カテゴリーの正しいIDを取得する。
139        $arrCategory_id = $objDb->sfGetCategoryId('', $category_id);
140        $category_id = $arrCategory_id[0];
141        if ($category_id == 0) {
142            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
143        }
144
145        $arrCategory = null;    // 選択されたカテゴリー
146        $arrChildren = array(); // 子カテゴリー
147
148        $arrAll = $objDb->sfGetCatTree($category_id, $count_check);
149        foreach ($arrAll as $category) {
150            // 選択されたカテゴリーの場合
151            if ($category['category_id'] == $category_id) {
152                $arrCategory = $category;
153                continue;
154            }
155
156            // 関係のないカテゴリーはスキップする。
157            if ($category['parent_category_id'] != $category_id) {
158                continue;
159            }
160
161            // 子カテゴリーの場合は、孫カテゴリーが存在するかどうかを調べる。
162            $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
163            $category['has_children'] = count($arrGrandchildrenID) > 0;
164            $arrChildren[] = $category;
165        }
166
167        if (!isset($arrCategory)) {
168            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
169        }
170
171        // 子カテゴリーの商品数を合計する。
172        $children_product_count = 0;
173        foreach ($arrChildren as $category) {
174            $children_product_count += $category['product_count'];
175        }
176
177        // 選択されたカテゴリーに直属の商品がある場合は、子カテゴリーの先頭に追加する。
178        if ($arrCategory['product_count'] > $children_product_count) {
179            $arrCategory['product_count'] -= $children_product_count;   // 子カテゴリーの商品数を除く。
180            $arrCategory['has_children'] = false;   // 商品一覧ページに遷移させるため。
181            array_unshift($arrChildren, $arrCategory);
182        }
183
184        // 結果を格納する。
185        $objPage->arrCategory = $arrCategory;
186        $objPage->arrChildren = $arrChildren;
187    }
188}
189?>
Note: See TracBrowser for help on using the repository browser.