Changeset 23568
- Timestamp:
- 2014/07/10 23:50:09 (10 years ago)
- Location:
- branches/version-2_13-dev
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_13-dev/data/class/helper/SC_Helper_BestProducts.php
r23546 r23568 171 171 public function rankUp($best_id) 172 172 { 173 $objDb = new SC_Helper_DB_Ex(); 174 //おすすめはデータベースの登録が昇順なので、Modeを逆にする。 175 $objDb->sfRankDown('dtb_best_products', 'best_id', $best_id); 173 $arrBestProducts = $this->getBestProducts($best_id); 174 $rank = $arrBestProducts['rank']; 175 176 if ($rank > 1) { 177 // 表示順が一つ上のIDを取得する 178 $arrAboveBestProducts = $this->getByRank($rank - 1); 179 $above_best_id = $arrAboveBestProducts['best_id']; 180 181 if ($above_best_id) { 182 // 一つ上のものを一つ下に下げる 183 $this->changeRank($above_best_id, $rank); 184 } else { 185 // 無ければ何もしない。(歯抜けの場合) 186 } 187 188 // 一つ上に上げる 189 $this->changeRank($best_id, $rank - 1); 190 } 176 191 } 177 192 … … 184 199 public function rankDown($best_id) 185 200 { 186 $objDb = new SC_Helper_DB_Ex(); 187 //おすすめはデータベースの登録が昇順なので、Modeを逆にする。 188 $objDb->sfRankUp('dtb_best_products', 'best_id', $best_id); 201 $arrBestProducts = $this->getBestProducts($best_id); 202 $rank = $arrBestProducts['rank']; 203 204 if ($rank < RECOMMEND_NUM) { 205 // 表示順が一つ下のIDを取得する 206 $arrBelowBestProducts = $this->getByRank($rank + 1); 207 $below_best_id = $arrBelowBestProducts['best_id']; 208 209 if ($below_best_id) { 210 // 一つ下のものを一つ上に上げる 211 $this->changeRank($below_best_id, $rank); 212 } else { 213 // 無ければ何もしない。(歯抜けの場合) 214 } 215 216 // 一つ下に下げる 217 $this->changeRank($best_id, $rank + 1); 218 } 219 } 220 221 /** 222 * 対象IDのrankを指定値に変更する 223 * 224 * @param integer $best_id 対象ID 225 * @param integer $rank 変更したいrank値 226 * @return void 227 */ 228 public function changeRank($best_id, $rank) 229 { 230 $objQuery =& SC_Query_Ex::getSingletonInstance(); 231 232 $table = 'dtb_best_products'; 233 $sqlval = array('rank' => $rank); 234 $where = 'best_id = ?'; 235 $arrWhereVal = array($best_id); 236 $objQuery->update($table, $sqlval, $where, $arrWhereVal); 189 237 } 190 238 } -
branches/version-2_13-dev/tests/class/helper/SC_Helper_BestProducts/SC_Helper_BestProducts_rankDownTest.php
r23546 r23568 42 42 } 43 43 44 public function testRankDown_指定されたデータがランクダウンされる(){ 45 46 SC_Helper_BestProducts_Ex::rankDown("1001"); 44 public function testRankDown_指定されたデータがランクダウンされる() 45 { 46 $objRecommend = new SC_Helper_BestProducts_Ex(); 47 $objRecommend->rankDown("1001"); 47 48 48 49 $this->expected = "2"; 49 50 50 $arrRet = SC_Helper_BestProducts_Ex::getBestProducts('1001');51 $arrRet = $objRecommend->getBestProducts('1001'); 51 52 52 53 $this->actual = $arrRet['rank']; -
branches/version-2_13-dev/tests/class/helper/SC_Helper_BestProducts/SC_Helper_BestProducts_rankUpTest.php
r23546 r23568 42 42 } 43 43 44 public function testRankUp_指定されたデータがランクアップされる(){ 44 public function testRankUp_指定されたデータがランクアップされる() 45 { 46 $objRecommend = new SC_Helper_BestProducts_Ex(); 45 47 46 SC_Helper_BestProducts_Ex::rankUp("1003");48 $objRecommend->rankUp("1003"); 47 49 48 50 $this->expected = "2"; 49 51 50 $arrRet = SC_Helper_BestProducts_Ex::getBestProducts('1003');52 $arrRet = $objRecommend->getBestProducts('1003'); 51 53 52 54 $this->actual = $arrRet['rank'];
Note: See TracChangeset
for help on using the changeset viewer.