Changeset 22796 for branches/version-2_12-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_Recommend.php
- Timestamp:
- 2013/05/02 18:11:36 (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
r22582 r22796 32 32 * @version $Id$ 33 33 */ 34 class LC_Page_Admin_Contents_Recommend extends LC_Page_Admin_Ex 35 { 34 class LC_Page_Admin_Contents_Recommend extends LC_Page_Admin_Ex { 36 35 37 36 // }}} … … 43 42 * @return void 44 43 */ 45 function init() 46 { 44 function init() { 47 45 parent::init(); 48 46 $this->tpl_mainpage = 'contents/recommend.tpl'; … … 60 58 * @return void 61 59 */ 62 function process() 63 { 60 function process() { 64 61 $this->action(); 65 62 $this->sendResponse(); … … 71 68 * @return void 72 69 */ 73 function action() 74 { 70 function action() { 75 71 $objFormParam = new SC_FormParam_Ex(); 76 72 $this->lfInitParam($objFormParam); 77 73 $objFormParam->setParam($_POST); 78 74 $objFormParam->convParam(); 79 $arrPost = $objFormParam->getHashArray(); 80 81 $objRecommend = new SC_Helper_Recommend_Ex(); 75 $objQuery =& SC_Query_Ex::getSingletonInstance(); 76 $objDb = new SC_Helper_DB_Ex(); 82 77 83 78 switch ($this->getMode()) { 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); 79 case 'down': //商品の並び替えをする。おすすめはデータベースの登録が昇順なので、Modeを逆にする。 80 $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 81 $best_id = $arrRet[0]['best_id']; 82 $objDb->sfRankUp('dtb_best_products','best_id',$best_id); 83 $arrPost = $objFormParam->getHashArray(); 84 $arrItems = $this->getRecommendProducts(); 85 break; 86 87 case 'up': //商品の並び替えをする。おすすめのみデータベースの登録が昇順なので、Modeを逆にする。 88 $arrRet = $objQuery->select('best_id', 'dtb_best_products', 'rank = ?', array($_POST['rank'])); //おすすめidの取得 89 $best_id = $arrRet[0]['best_id']; 90 $objDb->sfRankDown('dtb_best_products','best_id',$best_id); 91 $arrPost = $objFormParam->getHashArray(); 92 $arrItems = $this->getRecommendProducts(); 92 93 break; 93 94 94 95 case 'regist': // 商品を登録する。 95 96 $this->arrErr = $this->lfCheckError($objFormParam); 97 $arrPost = $objFormParam->getHashArray(); 96 98 // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。 97 99 if (SC_Utils_Ex::isBlank($this->arrErr)) { 98 100 $member_id = $_SESSION['member_id']; 99 $this->insertRecommendProduct($arrPost,$member_id ,$objRecommend);100 $arrItems = $this->getRecommendProducts( $objRecommend);101 $this->insertRecommendProduct($arrPost,$member_id); 102 $arrItems = $this->getRecommendProducts(); 101 103 } else { 102 104 $arrItems = $this->setProducts($arrPost, $arrItems); … … 107 109 case 'delete': // 商品を削除する。 108 110 $this->arrErr = $this->lfCheckError($objFormParam); 111 $arrPost = $objFormParam->getHashArray(); 109 112 if (SC_Utils_Ex::isBlank($this->arrErr)) { 110 $this->deleteProduct($arrPost , $objRecommend);111 $arrItems = $this->getRecommendProducts( $objRecommend);113 $this->deleteProduct($arrPost); 114 $arrItems = $this->getRecommendProducts(); 112 115 } 113 116 $this->tpl_onload = "window.alert('削除しました');"; … … 117 120 $arrPost = $objFormParam->getHashArray(); 118 121 if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) { 119 $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts( $objRecommend));122 $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts()); 120 123 $this->checkRank = $arrPost['rank']; 121 124 } 122 125 break; 123 126 default: 124 $arrItems = $this->getRecommendProducts( $objRecommend);127 $arrItems = $this->getRecommendProducts(); 125 128 break; 126 129 } … … 140 143 * @return void 141 144 */ 142 function destroy() 143 { 145 function destroy() { 144 146 parent::destroy(); 145 147 } … … 149 151 * @param Object $objFormParam 150 152 */ 151 function lfInitParam(&$objFormParam) 152 { 153 $objFormParam->addParam('おすすめ商品ID', 'best_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); 153 function lfInitParam(&$objFormParam) { 154 154 $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); 155 155 $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); … … 163 163 * @return Array エラー内容 164 164 */ 165 function lfCheckError(&$objFormParam) 166 { 165 function lfCheckError(&$objFormParam) { 167 166 $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); 168 167 $objErr->arrErr = $objFormParam->checkError(); … … 172 171 /** 173 172 * 既に登録されている内容を取得する 174 * @param Object $objRecommend175 173 * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列 176 174 */ 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; 187 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 188 $arrProducts = $objProduct->getListByProductIds($objQuery, $product_ids); 175 function getRecommendProducts() { 176 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 177 $col = 'dtb_products.name,dtb_products.main_list_image,dtb_best_products.*'; 178 $table = 'dtb_best_products INNER JOIN dtb_products ON dtb_best_products.product_id = dtb_products.product_id'; 179 $where = 'dtb_best_products.del_flg = 0'; 180 $order = 'rank'; 181 $objQuery->setOrder($order); 182 $arrProducts = $objQuery->select($col, $table, $where); 189 183 190 184 $arrReturnProducts = array(); 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']; 185 foreach ($arrProducts as $data) { 194 186 $arrReturnProducts[$data['rank']] = $data; 195 187 } … … 201 193 * @param Array $arrPost POSTの値を格納した配列 202 194 * @param Integer $member_id 登録した管理者を示すID 203 * @param Object $objRecommend 204 */ 205 function insertRecommendProduct($arrPost,$member_id, SC_Helper_Recommend_Ex &$objRecommend) 206 { 195 */ 196 function insertRecommendProduct($arrPost,$member_id) { 197 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 207 198 // 古いおすすめ商品のデータを削除する。 208 $this->deleteProduct($arrPost , $objRecommend);199 $this->deleteProduct($arrPost); 209 200 210 201 $sqlval = array(); … … 214 205 $sqlval['comment'] = $arrPost['comment']; 215 206 $sqlval['creator_id'] = $member_id; 216 $objRecommend->save($sqlval); 207 $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; 208 $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; 209 $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id'); 210 $objQuery->insert('dtb_best_products', $sqlval); 217 211 } 218 212 … … 220 214 * データを削除する 221 215 * @param Array $arrPost POSTの値を格納した配列 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); 216 */ 217 function deleteProduct($arrPost) { 218 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 219 $table = 'dtb_best_products'; 220 $where = 'category_id = ? AND rank = ?'; 221 $arrWhereVal = array($arrPost['category_id'],$arrPost['rank']); 222 $objQuery->delete($table, $where, $arrWhereVal); 234 223 } 235 224 … … 237 226 * 商品情報を取得する 238 227 * @param Integer $product_id 商品ID 239 * @return Array $return 商品のデータを格納した配列 240 */ 241 function getProduct($product_id) 242 { 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; 228 * @return Array $arrProduct 商品のデータを格納した配列 229 */ 230 function getProduct($product_id) { 231 $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); 232 $col = 'product_id,main_list_image,name'; 233 $table = 'dtb_products'; 234 $where = 'product_id = ? AND del_flg = 0'; 235 $arrWhereVal = array($product_id); 236 $arrProduct = $objQuery->select($col, $table, $where, $arrWhereVal); 237 return $arrProduct[0]; 251 238 } 252 239 … … 256 243 * @param Array $arrItems フロントに表示される商品の情報を格納した配列 257 244 */ 258 function setProducts($arrPost,$arrItems) 259 { 245 function setProducts($arrPost,$arrItems) { 260 246 $arrProduct = $this->getProduct($arrPost['product_id']); 261 247 if (count($arrProduct) > 0) {
Note: See TracChangeset
for help on using the changeset viewer.