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

Revision 23064, 6.9 KB checked in by pineray, 9 years ago (diff)

#2342 JavaScript?のグローバルな宣言を減らす
フォーム関連残り.

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