Changeset 22582 for branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_Recommend.php
- Timestamp:
- 2013/02/26 09:09:44 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_Recommend.php
r22567 r22582 77 77 $objFormParam->setParam($_POST); 78 78 $objFormParam->convParam(); 79 $objQuery =& SC_Query_Ex::getSingletonInstance(); 80 $objDb = new SC_Helper_DB_Ex(); 79 $arrPost = $objFormParam->getHashArray(); 80 81 $objRecommend = new SC_Helper_Recommend_Ex(); 81 82 82 83 switch ($this->getMode()) { 83 case 'down': //商品の並び替えをする。おすすめはデータベースの登録が昇順なので、Modeを逆にする。 84 $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 85 $best_id = $arrRet[0]['best_id']; 86 $objDb->sfRankUp('dtb_best_products','best_id',$best_id); 87 $arrPost = $objFormParam->getHashArray(); 88 $arrItems = $this->getRecommendProducts(); 89 break; 90 91 case 'up': //商品の並び替えをする。おすすめのみデータベースの登録が昇順なので、Modeを逆にする。 92 $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 93 $best_id = $arrRet[0]['best_id']; 94 $objDb->sfRankDown('dtb_best_products','best_id',$best_id); 95 $arrPost = $objFormParam->getHashArray(); 96 $arrItems = $this->getRecommendProducts(); 84 case 'down': //商品の並び替えをする。 85 $objRecommend->rankDown($arrPost['best_id']); 86 $arrItems = $this->getRecommendProducts($objRecommend); 87 break; 88 89 case 'up': //商品の並び替えをする。 90 $objRecommend->rankUp($arrPost['best_id']); 91 $arrItems = $this->getRecommendProducts($objRecommend); 97 92 break; 98 93 99 94 case 'regist': // 商品を登録する。 100 95 $this->arrErr = $this->lfCheckError($objFormParam); 101 $arrPost = $objFormParam->getHashArray();102 96 // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。 103 97 if (SC_Utils_Ex::isBlank($this->arrErr)) { 104 98 $member_id = $_SESSION['member_id']; 105 $this->insertRecommendProduct($arrPost,$member_id );106 $arrItems = $this->getRecommendProducts( );99 $this->insertRecommendProduct($arrPost,$member_id,$objRecommend); 100 $arrItems = $this->getRecommendProducts($objRecommend); 107 101 } else { 108 102 $arrItems = $this->setProducts($arrPost, $arrItems); … … 113 107 case 'delete': // 商品を削除する。 114 108 $this->arrErr = $this->lfCheckError($objFormParam); 115 $arrPost = $objFormParam->getHashArray();116 109 if (SC_Utils_Ex::isBlank($this->arrErr)) { 117 $this->deleteProduct($arrPost );118 $arrItems = $this->getRecommendProducts( );110 $this->deleteProduct($arrPost, $objRecommend); 111 $arrItems = $this->getRecommendProducts($objRecommend); 119 112 } 120 113 $this->tpl_onload = "window.alert('削除しました');"; … … 124 117 $arrPost = $objFormParam->getHashArray(); 125 118 if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) { 126 $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts( ));119 $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts($objRecommend)); 127 120 $this->checkRank = $arrPost['rank']; 128 121 } 129 122 break; 130 123 default: 131 $arrItems = $this->getRecommendProducts( );124 $arrItems = $this->getRecommendProducts($objRecommend); 132 125 break; 133 126 } … … 158 151 function lfInitParam(&$objFormParam) 159 152 { 153 $objFormParam->addParam('おすすめ商品ID', 'best_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 160 154 $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); 161 155 $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); … … 178 172 /** 179 173 * 既に登録されている内容を取得する 174 * @param Object $objRecommend 180 175 * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列 181 176 */ 182 function getRecommendProducts() 183 { 177 function getRecommendProducts(SC_Helper_Recommend_Ex &$objRecommend) 178 { 179 $arrList = $objRecommend->getList(); 180 // product_id の一覧を作成 181 $product_ids = array(); 182 foreach ($arrList as $value) { 183 $product_ids[] = $value['product_id']; 184 } 185 186 $objProduct = new SC_Product_Ex; 184 187 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 185 $col = 'dtb_products.name,dtb_products.main_list_image,dtb_best_products.*,dtb_products.status'; 186 $table = 'dtb_best_products INNER JOIN dtb_products ON dtb_best_products.product_id = dtb_products.product_id'; 187 $where = 'dtb_best_products.del_flg = 0'; 188 $order = 'rank'; 189 $objQuery->setOrder($order); 190 $arrProducts = $objQuery->select($col, $table, $where); 188 $arrProducts = $objProduct->getListByProductIds($objQuery, $product_ids); 191 189 192 190 $arrReturnProducts = array(); 193 foreach ($arrProducts as $data) { 191 foreach ($arrList as $data) { 192 $data['main_list_image'] = $arrProducts[$data['product_id']]['main_list_image']; 193 $data['name'] = $arrProducts[$data['product_id']]['name']; 194 194 $arrReturnProducts[$data['rank']] = $data; 195 195 } … … 201 201 * @param Array $arrPost POSTの値を格納した配列 202 202 * @param Integer $member_id 登録した管理者を示すID 203 * /204 function insertRecommendProduct($arrPost,$member_id)205 {206 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();203 * @param Object $objRecommend 204 */ 205 function insertRecommendProduct($arrPost,$member_id, SC_Helper_Recommend_Ex &$objRecommend) 206 { 207 207 // 古いおすすめ商品のデータを削除する。 208 $this->deleteProduct($arrPost );208 $this->deleteProduct($arrPost, $objRecommend); 209 209 210 210 $sqlval = array(); … … 214 214 $sqlval['comment'] = $arrPost['comment']; 215 215 $sqlval['creator_id'] = $member_id; 216 $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; 217 $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; 218 $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id'); 219 $objQuery->insert('dtb_best_products', $sqlval); 216 $objRecommend->save($sqlval); 220 217 } 221 218 … … 223 220 * データを削除する 224 221 * @param Array $arrPost POSTの値を格納した配列 225 */ 226 function deleteProduct($arrPost) 227 { 228 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 229 $table = 'dtb_best_products'; 230 $where = 'category_id = ? AND rank = ?'; 231 $arrWhereVal = array($arrPost['category_id'],$arrPost['rank']); 232 $objQuery->delete($table, $where, $arrWhereVal); 222 * @param Object $objRecommend 223 * @return void 224 */ 225 function deleteProduct($arrPost, SC_Helper_Recommend_Ex &$objRecommend) 226 { 227 if ($arrPost['best_id']) { 228 $target = $arrPost['best_id']; 229 } else { 230 $recommend = $objRecommend->getByRank($arrPost['rank']); 231 $target = $recommend['best_id']; 232 } 233 $objRecommend->delete($target); 233 234 } 234 235 … … 236 237 * 商品情報を取得する 237 238 * @param Integer $product_id 商品ID 238 * @return Array $ arrProduct商品のデータを格納した配列239 * @return Array $return 商品のデータを格納した配列 239 240 */ 240 241 function getProduct($product_id) 241 242 { 242 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 243 $col = 'product_id,main_list_image,name'; 244 $table = 'dtb_products'; 245 $where = 'product_id = ? AND del_flg = 0'; 246 $arrWhereVal = array($product_id); 247 $arrProduct = $objQuery->select($col, $table, $where, $arrWhereVal); 248 return $arrProduct[0]; 243 $objProduct = new SC_Product_Ex(); 244 $arrProduct = $objProduct->getDetail($product_id); 245 $return = array( 246 'product_id' => $arrProduct['product_id'], 247 'main_list_image' => $arrProduct['main_list_image'], 248 'name' => $arrProduct['name'] 249 ); 250 return $return; 249 251 } 250 252
Note: See TracChangeset
for help on using the changeset viewer.