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