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

Revision 20116, 6.5 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • 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_REALDIR . "pages/admin/LC_Page_Admin.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 {
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 = new SC_Query();
70        $objSess = new SC_Session();
71        $objDb = new SC_Helper_DB_Ex();
72
73        // 認証可否の判定
74        SC_Utils_Ex::sfIsSuccess($objSess);
75
76        $this->tpl_pageno = isset($_POST['pageno']) ? $_POST['pageno'] : "";
77
78        // 通常時は親カテゴリを0に設定する。
79        $this->arrForm['parent_category_id'] =
80            isset($_POST['parent_category_id']) ? $_POST['parent_category_id'] : 0;
81
82        switch($this->getMode()) {
83        case 'up':
84            $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($_POST['parent_category_id']);
85            $objDb->sfRankUp("dtb_product_categories", "product_id", $_POST['product_id'], $where);
86            break;
87        case 'down':
88            $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($_POST['parent_category_id']);
89            $objDb->sfRankDown("dtb_product_categories", "product_id", $_POST['product_id'], $where);
90            break;
91        case 'move':
92            $key = "pos-".$_POST['product_id'];
93            $input_pos = mb_convert_kana($_POST[$key], "n");
94            if(SC_Utils_Ex::sfIsInt($input_pos)) {
95                $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($_POST['parent_category_id']);
96                $objDb->sfMoveRank("dtb_product_categories", "product_id", $_POST['product_id'], $input_pos, $where);
97            }
98            break;
99        case 'tree':
100            // カテゴリの切替は、ページ番号をクリアする。
101            $this->tpl_pageno = "";
102            break;
103
104        case 'renumber':
105            $sql = <<< __EOS__
106                UPDATE dtb_product_categories
107                SET
108                    rank =
109                        (
110                            SELECT COUNT(*)
111                            FROM dtb_product_categories t_in
112                            WHERE t_in.category_id = dtb_product_categories.category_id
113                                AND (
114                                    t_in.rank < dtb_product_categories.rank
115                                    OR (
116                                        t_in.rank = dtb_product_categories.rank
117                                        AND t_in.product_id < dtb_product_categories.product_id
118                                    )
119                                )
120                        ) + 1
121                WHERE dtb_product_categories.category_id = ?
122__EOS__;
123            $objQuery->query($sql, array($_POST['parent_category_id']));
124            break;
125
126        default:
127            break;
128        }
129
130        $this->arrTree = $objDb->sfGetCatTree($this->arrForm['parent_category_id']);
131        $this->arrProductsList =
132            $this->lfGetProduct($this->arrForm['parent_category_id']);
133        $arrBread = array();
134        $objDb->findTree($this->arrTree, $this->arrForm['parent_category_id'], $arrBread);
135        $this->breadcrumbs = "ホーム";
136        // TODO JSON で投げて, フロント側で処理した方が良い?
137        for ($i = count($arrBread) - 1; $i >= 0; $i--) {
138            // フロント側で &gt; へエスケープするため, ここでは > を使用
139            if ($i === count($arrBread) - 1) {
140                $this->breadcrumbs .= ' > ';
141            }
142            $this->breadcrumbs .= $arrBread[$i]['category_name'];
143            if ($i > 0) {
144                $this->breadcrumbs .= ' > ';
145            }
146        }
147    }
148
149    /**
150     * デストラクタ.
151     *
152     * @return void
153     */
154    function destroy() {
155        parent::destroy();
156    }
157
158    /* 商品読み込み */
159    function lfGetProduct($category_id) {
160        // FIXME SC_Product クラスを使用した実装
161        $objQuery = new SC_Query();
162        $col = "product_id, name, main_list_image, product_code_min, product_code_max, status";
163        $table = "vw_products_allclass AS allcls";
164        $where = "del_flg = 0 AND category_id = ?";
165
166        // 行数の取得
167        $linemax = $objQuery->count($table, $where, array($category_id));
168        // 該当件数表示用
169        $this->tpl_linemax = $linemax;
170
171        $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, SEARCH_PMAX, "fnNaviPage", NAVI_PMAX);
172        $startno = $objNavi->start_row;
173        $this->tpl_start_row = $objNavi->start_row;
174        $this->tpl_strnavi = $objNavi->strnavi;     // Navi表示文字列
175        $this->tpl_pagemax = $objNavi->max_page;    // ページ最大数(「上へ下へ」表示判定用)
176        $this->tpl_disppage = $objNavi->now_page;   // 表示ページ番号(「上へ下へ」表示判定用)
177
178        // 取得範囲の指定(開始行番号、行数のセット)
179        $objQuery->setLimitOffset(SEARCH_PMAX, $startno);
180
181        $objQuery->setOrder("product_rank DESC, product_id DESC");
182
183        $arrRet = $objQuery->select($col, $table, $where, array($category_id));
184        return $arrRet;
185    }
186}
187?>
Note: See TracBrowser for help on using the repository browser.