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 |
---|
25 | require_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 | */ |
---|
34 | class 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 | $objProduct = new SC_Product(); |
---|
123 | $table = $objProduct->alldtlSQL(); |
---|
124 | $table.= " LEFT JOIN dtb_product_categories AS T5 USING(product_id)"; |
---|
125 | $where = "del_flg = 0 AND category_id = ?"; |
---|
126 | |
---|
127 | // 行数の取得 |
---|
128 | $linemax = $objQuery->count($table, $where, array($category_id)); |
---|
129 | // 該当件数表示用 |
---|
130 | $this->tpl_linemax = $linemax; |
---|
131 | |
---|
132 | $objNavi = new SC_PageNavi_Ex($this->tpl_pageno, $linemax, SEARCH_PMAX, 'fnNaviPage', NAVI_PMAX); |
---|
133 | $startno = $objNavi->start_row; |
---|
134 | $this->tpl_start_row = $objNavi->start_row; |
---|
135 | $this->tpl_strnavi = $objNavi->strnavi; // Navi表示文字列 |
---|
136 | $this->tpl_pagemax = $objNavi->max_page; // ページ最大数(「上へ下へ」表示判定用) |
---|
137 | $this->tpl_disppage = $objNavi->now_page; // 表示ページ番号(「上へ下へ」表示判定用) |
---|
138 | |
---|
139 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
140 | $objQuery->setLimitOffset(SEARCH_PMAX, $startno); |
---|
141 | |
---|
142 | $objQuery->setOrder("rank DESC, product_id DESC"); |
---|
143 | |
---|
144 | $arrRet = $objQuery->select($col, $table, $where, array($category_id)); |
---|
145 | return $arrRet; |
---|
146 | } |
---|
147 | |
---|
148 | /* |
---|
149 | * 商品の数値指定での並び替え実行 |
---|
150 | */ |
---|
151 | function lfRenumber($parent_category_id) { |
---|
152 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
153 | |
---|
154 | $sql = <<< __EOS__ |
---|
155 | UPDATE dtb_product_categories |
---|
156 | SET |
---|
157 | rank = |
---|
158 | ( |
---|
159 | SELECT COUNT(*) |
---|
160 | FROM dtb_product_categories t_in |
---|
161 | WHERE t_in.category_id = dtb_product_categories.category_id |
---|
162 | AND ( |
---|
163 | t_in.rank < dtb_product_categories.rank |
---|
164 | OR ( |
---|
165 | t_in.rank = dtb_product_categories.rank |
---|
166 | AND t_in.product_id < dtb_product_categories.product_id |
---|
167 | ) |
---|
168 | ) |
---|
169 | ) + 1 |
---|
170 | WHERE dtb_product_categories.category_id = ? |
---|
171 | __EOS__; |
---|
172 | $arrRet = $objQuery->query($sql, array($parent_category_id)); |
---|
173 | return $arrRet; |
---|
174 | } |
---|
175 | |
---|
176 | function lfRankUp(&$objDb, $parent_category_id, $product_id) { |
---|
177 | $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id); |
---|
178 | $objDb->sfRankUp("dtb_product_categories", "product_id", $product_id, $where); |
---|
179 | } |
---|
180 | |
---|
181 | function lfRankDown(&$objDb, $parent_category_id, $product_id) { |
---|
182 | $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id); |
---|
183 | $objDb->sfRankDown("dtb_product_categories", "product_id", $product_id, $where); |
---|
184 | } |
---|
185 | |
---|
186 | function lfRankMove(&$objDb, $parent_category_id, $product_id) { |
---|
187 | $key = "pos-".$product_id; |
---|
188 | $input_pos = mb_convert_kana($_POST[$key], 'n'); |
---|
189 | if(SC_Utils_Ex::sfIsInt($input_pos)) { |
---|
190 | $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id); |
---|
191 | $objDb->sfMoveRank("dtb_product_categories", "product_id", $product_id, $input_pos, $where); |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | function lfGetBreadcrumbs($arrBread) { |
---|
196 | $breadcrumbs = "ホーム"; |
---|
197 | // TODO JSON で投げて, フロント側で処理した方が良い? |
---|
198 | for ($i = count($arrBread) - 1; $i >= 0; $i--) { |
---|
199 | // フロント側で > へエスケープするため, ここでは > を使用 |
---|
200 | if ($i === count($arrBread) - 1) { |
---|
201 | $breadcrumbs .= ' > '; |
---|
202 | } |
---|
203 | $breadcrumbs .= $arrBread[$i]['category_name']; |
---|
204 | if ($i > 0) { |
---|
205 | $breadcrumbs .= ' > '; |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | return $breadcrumbs; |
---|
210 | } |
---|
211 | |
---|
212 | } |
---|
213 | ?> |
---|