source: branches/version-2_5-dev/data/class/pages/admin/products/LC_Page_Admin_Products_ProductRank.php @ 20538

Revision 20538, 7.3 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)
#628(未使用処理・定義などの削除)

  • 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-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_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * 商品並べ替え のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Products_ProductRank extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'products/product_rank.tpl';
47        $this->tpl_subnavi = 'products/subnavi.tpl';
48        $this->tpl_mainno = 'products';
49        $this->tpl_subno = 'product_rank';
50        $this->tpl_subtitle = '商品並び替え';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のアクション.
65     *
66     * @return void
67     */
68    function action() {
69        $objQuery =& SC_Query_Ex::getSingletonInstance();
70        $objDb = new SC_Helper_DB_Ex();
71
72        $this->tpl_pageno = isset($_POST['pageno']) ? $_POST['pageno'] : "";
73
74        // 通常時は親カテゴリを0に設定する。
75        $this->arrForm['parent_category_id'] =
76            isset($_POST['parent_category_id']) ? $_POST['parent_category_id'] : 0;
77        $this->arrForm['product_id'] =
78            isset($_POST['product_id']) ? $_POST['product_id'] : '';
79
80        switch($this->getMode()) {
81        case 'up':
82            $this->lfRankUp($objDb, $this->arrForm['parent_category_id'], $this->arrForm['product_id']);
83            break;
84        case 'down':
85            $this->lfRankDown($objDb, $this->arrForm['parent_category_id'], $this->arrForm['product_id']);
86            break;
87        case 'move':
88            $this->lfRankMove($objDb, $this->arrForm['parent_category_id'], $this->arrForm['product_id']);
89            break;
90        case 'tree':
91            // カテゴリの切替は、ページ番号をクリアする。
92            $this->tpl_pageno = "";
93            break;
94        case 'renumber':
95            $this->lfRenumber($this->arrForm['parent_category_id']);
96            break;
97        default:
98            break;
99        }
100
101        $this->arrTree = $objDb->sfGetCatTree($this->arrForm['parent_category_id']);
102        $this->arrProductsList = $this->lfGetProduct($this->arrForm['parent_category_id']);
103        $arrBread = array();
104        $objDb->findTree($this->arrTree, $this->arrForm['parent_category_id'], $arrBread);
105        $this->breadcrumbs = $this->lfGetBreadcrumbs($arrBread);
106    }
107
108    /**
109     * デストラクタ.
110     *
111     * @return void
112     */
113    function destroy() {
114        parent::destroy();
115    }
116
117    /* 商品読み込み */
118    function lfGetProduct($category_id) {
119        // FIXME SC_Product クラスを使用した実装
120        $objQuery =& SC_Query_Ex::getSingletonInstance();
121        $col = "product_id, name, main_list_image, product_code_min, product_code_max, status";
122        $table = "vw_products_allclass AS allcls";
123        $where = "del_flg = 0 AND category_id = ?";
124
125        // 行数の取得
126        $linemax = $objQuery->count($table, $where, array($category_id));
127        // 該当件数表示用
128        $this->tpl_linemax = $linemax;
129
130        $objNavi = new SC_PageNavi_Ex($this->tpl_pageno, $linemax, SEARCH_PMAX, 'fnNaviPage', NAVI_PMAX);
131        $startno = $objNavi->start_row;
132        $this->tpl_start_row = $objNavi->start_row;
133        $this->tpl_strnavi = $objNavi->strnavi;     // Navi表示文字列
134        $this->tpl_pagemax = $objNavi->max_page;    // ページ最大数(「上へ下へ」表示判定用)
135        $this->tpl_disppage = $objNavi->now_page;   // 表示ページ番号(「上へ下へ」表示判定用)
136
137        // 取得範囲の指定(開始行番号、行数のセット)
138        $objQuery->setLimitOffset(SEARCH_PMAX, $startno);
139
140        $objQuery->setOrder("product_rank DESC, product_id DESC");
141
142        $arrRet = $objQuery->select($col, $table, $where, array($category_id));
143        return $arrRet;
144    }
145
146    /*
147     * 商品の数値指定での並び替え実行
148     */
149    function lfRenumber($parent_category_id) {
150        $objQuery =& SC_Query_Ex::getSingletonInstance();
151
152        $sql = <<< __EOS__
153            UPDATE dtb_product_categories
154            SET
155                rank =
156                    (
157                        SELECT COUNT(*)
158                        FROM dtb_product_categories t_in
159                        WHERE t_in.category_id = dtb_product_categories.category_id
160                            AND (
161                                t_in.rank < dtb_product_categories.rank
162                                OR (
163                                    t_in.rank = dtb_product_categories.rank
164                                    AND t_in.product_id < dtb_product_categories.product_id
165                                )
166                            )
167                    ) + 1
168            WHERE dtb_product_categories.category_id = ?
169__EOS__;
170        $arrRet = $objQuery->query($sql, array($parent_category_id));
171        return $arrRet;
172    }
173
174    function lfRankUp(&$objDb, $parent_category_id, $product_id) {
175        $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id);
176        $objDb->sfRankUp("dtb_product_categories", "product_id", $product_id, $where);
177    }
178
179    function lfRankDown(&$objDb, $parent_category_id, $product_id) {
180        $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id);
181        $objDb->sfRankDown("dtb_product_categories", "product_id", $product_id, $where);
182    }
183
184    function lfRankMove(&$objDb, $parent_category_id, $product_id) {
185        $key = "pos-".$product_id;
186        $input_pos = mb_convert_kana($_POST[$key], 'n');
187        if(SC_Utils_Ex::sfIsInt($input_pos)) {
188            $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id);
189            $objDb->sfMoveRank("dtb_product_categories", "product_id", $product_id, $input_pos, $where);
190        }
191    }
192
193
194    function lfGetBreadcrumbs($arrBread) {
195        $breadcrumbs = "ホーム";
196        // TODO JSON で投げて, フロント側で処理した方が良い?
197        for ($i = count($arrBread) - 1; $i >= 0; $i--) {
198            // フロント側で &gt; へエスケープするため, ここでは > を使用
199            if ($i === count($arrBread) - 1) {
200                $breadcrumbs .= ' > ';
201            }
202            $breadcrumbs .= $arrBread[$i]['category_name'];
203            if ($i > 0) {
204                $breadcrumbs .= ' > ';
205            }
206        }
207
208        return $breadcrumbs;
209    }
210
211
212
213}
214?>
Note: See TracBrowser for help on using the repository browser.