Changeset 20192
- Timestamp:
- 2011/02/18 14:20:51 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/pages/admin/products/LC_Page_Admin_Products_ProductRank.php
r20116 r20192 79 79 $this->arrForm['parent_category_id'] = 80 80 isset($_POST['parent_category_id']) ? $_POST['parent_category_id'] : 0; 81 $this->arrForm['product_id'] = 82 isset($_POST['product_id']) ? $_POST['product_id'] : ''; 81 83 82 84 switch($this->getMode()) { 83 85 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 $this->lfRankUp($objDb, $this->arrForm['parent_category_id'], $this->arrForm['product_id']); 86 87 break; 87 88 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); 89 $this->lfRankDown($objDb, $this->arrForm['parent_category_id'], $this->arrForm['product_id']); 90 90 break; 91 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 } 92 $this->lfRankMove($objDb, $this->arrForm['parent_category_id'], $this->arrForm['product_id']); 98 93 break; 99 94 case 'tree': … … 101 96 $this->tpl_pageno = ""; 102 97 break; 103 104 98 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 99 $this->lfRenumber($this->arrForm['parent_category_id']); 100 break; 126 101 default: 127 102 break; … … 129 104 130 105 $this->arrTree = $objDb->sfGetCatTree($this->arrForm['parent_category_id']); 131 $this->arrProductsList = 132 $this->lfGetProduct($this->arrForm['parent_category_id']); 106 $this->arrProductsList = $this->lfGetProduct($this->arrForm['parent_category_id']); 133 107 $arrBread = array(); 134 108 $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 // フロント側で > へエスケープするため, ここでは > を使用 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 } 109 $this->breadcrumbs = $this->lfGetBreadcrumbs($arrBread); 147 110 } 148 111 … … 184 147 return $arrRet; 185 148 } 149 150 /* 151 * 商品の数値指定での並び替え実行 152 */ 153 function lfRenumber($parent_category_id) { 154 $objQuery = new SC_Query(); 155 156 $sql = <<< __EOS__ 157 UPDATE dtb_product_categories 158 SET 159 rank = 160 ( 161 SELECT COUNT(*) 162 FROM dtb_product_categories t_in 163 WHERE t_in.category_id = dtb_product_categories.category_id 164 AND ( 165 t_in.rank < dtb_product_categories.rank 166 OR ( 167 t_in.rank = dtb_product_categories.rank 168 AND t_in.product_id < dtb_product_categories.product_id 169 ) 170 ) 171 ) + 1 172 WHERE dtb_product_categories.category_id = ? 173 __EOS__; 174 $arrRet = $objQuery->query($sql, array($parent_category_id)); 175 return $arrRet; 176 } 177 178 function lfRankUp(&$objDb, $parent_category_id, $product_id) { 179 $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id); 180 $objDb->sfRankUp("dtb_product_categories", "product_id", $product_id, $where); 181 } 182 183 function lfRankDown(&$objDb, $parent_category_id, $product_id) { 184 $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id); 185 $objDb->sfRankDown("dtb_product_categories", "product_id", $product_id, $where); 186 } 187 188 function lfRankMove(&$objDb, $parent_category_id, $product_id) { 189 $key = "pos-".$product_id; 190 $input_pos = mb_convert_kana($_POST[$key], "n"); 191 if(SC_Utils_Ex::sfIsInt($input_pos)) { 192 $where = "category_id = " . SC_Utils_Ex::sfQuoteSmart($parent_category_id); 193 $objDb->sfMoveRank("dtb_product_categories", "product_id", $product_id, $input_pos, $where); 194 } 195 } 196 197 198 function lfGetBreadcrumbs($arrBread) { 199 $breadcrumbs = "ホーム"; 200 // TODO JSON で投げて, フロント側で処理した方が良い? 201 for ($i = count($arrBread) - 1; $i >= 0; $i--) { 202 // フロント側で > へエスケープするため, ここでは > を使用 203 if ($i === count($arrBread) - 1) { 204 $breadcrumbs .= ' > '; 205 } 206 $breadcrumbs .= $arrBread[$i]['category_name']; 207 if ($i > 0) { 208 $breadcrumbs .= ' > '; 209 } 210 } 211 212 return $breadcrumbs; 213 } 214 215 216 186 217 } 187 218 ?>
Note: See TracChangeset
for help on using the changeset viewer.