1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
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. |
---|
22 | */ |
---|
23 | |
---|
24 | // {{{ requires |
---|
25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * おすすめ商品管理 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Contents_Recommend extends LC_Page_Admin_Ex |
---|
35 | { |
---|
36 | |
---|
37 | // }}} |
---|
38 | // {{{ functions |
---|
39 | |
---|
40 | /** |
---|
41 | * Page を初期化する. |
---|
42 | * |
---|
43 | * @return void |
---|
44 | */ |
---|
45 | function init() |
---|
46 | { |
---|
47 | parent::init(); |
---|
48 | $this->tpl_mainpage = 'contents/recommend.tpl'; |
---|
49 | $this->tpl_mainno = 'contents'; |
---|
50 | $this->tpl_subno = 'recommend'; |
---|
51 | $this->tpl_maintitle = 'コンテンツ管理'; |
---|
52 | $this->tpl_subtitle = 'おすすめ商品管理'; |
---|
53 | //最大登録数の表示 |
---|
54 | $this->tpl_disp_max = RECOMMEND_NUM; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Page のプロセス. |
---|
59 | * |
---|
60 | * @return void |
---|
61 | */ |
---|
62 | function process() |
---|
63 | { |
---|
64 | $this->action(); |
---|
65 | $this->sendResponse(); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * Page のアクション. |
---|
70 | * |
---|
71 | * @return void |
---|
72 | */ |
---|
73 | function action() |
---|
74 | { |
---|
75 | $objFormParam = new SC_FormParam_Ex(); |
---|
76 | $this->lfInitParam($objFormParam); |
---|
77 | $objFormParam->setParam($_POST); |
---|
78 | $objFormParam->convParam(); |
---|
79 | $arrPost = $objFormParam->getHashArray(); |
---|
80 | |
---|
81 | $objRecommend = new SC_Helper_BestProducts_Ex(); |
---|
82 | |
---|
83 | 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); |
---|
92 | break; |
---|
93 | |
---|
94 | case 'regist': // 商品を登録する。 |
---|
95 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
96 | // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。 |
---|
97 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
98 | $member_id = $_SESSION['member_id']; |
---|
99 | $this->insertRecommendProduct($arrPost,$member_id,$objRecommend); |
---|
100 | $arrItems = $this->getRecommendProducts($objRecommend); |
---|
101 | } else { |
---|
102 | $arrItems = $this->setProducts($arrPost, $arrItems); |
---|
103 | $this->checkRank = $arrPost['rank']; |
---|
104 | } |
---|
105 | $this->tpl_onload = "window.alert('編集が完了しました');"; |
---|
106 | break; |
---|
107 | case 'delete': // 商品を削除する。 |
---|
108 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
109 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
110 | $this->deleteProduct($arrPost, $objRecommend); |
---|
111 | $arrItems = $this->getRecommendProducts($objRecommend); |
---|
112 | } |
---|
113 | $this->tpl_onload = "window.alert('削除しました');"; |
---|
114 | break; |
---|
115 | case 'set_item': // 商品を選択する。 |
---|
116 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
117 | $arrPost = $objFormParam->getHashArray(); |
---|
118 | if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) { |
---|
119 | $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts($objRecommend)); |
---|
120 | $this->checkRank = $arrPost['rank']; |
---|
121 | } |
---|
122 | break; |
---|
123 | default: |
---|
124 | $arrItems = $this->getRecommendProducts($objRecommend); |
---|
125 | break; |
---|
126 | } |
---|
127 | |
---|
128 | $this->category_id = intval($arrPost['category_id']); |
---|
129 | $this->arrItems = $arrItems; |
---|
130 | |
---|
131 | // カテゴリ取得 |
---|
132 | $objDb = new SC_Helper_DB_Ex(); |
---|
133 | $this->arrCatList = $objDb->sfGetCategoryList('level = 1'); |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * デストラクタ. |
---|
139 | * |
---|
140 | * @return void |
---|
141 | */ |
---|
142 | function destroy() |
---|
143 | { |
---|
144 | parent::destroy(); |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | * パラメーターの初期化を行う |
---|
149 | * @param Object $objFormParam |
---|
150 | */ |
---|
151 | function lfInitParam(&$objFormParam) |
---|
152 | { |
---|
153 | $objFormParam->addParam('おすすめ商品ID', 'best_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
154 | $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
155 | $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
156 | $objFormParam->addParam('ランク', 'rank', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
157 | $objFormParam->addParam('コメント', 'comment', LTEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * 入力されたパラメーターのエラーチェックを行う。 |
---|
162 | * @param Object $objFormParam |
---|
163 | * @return Array エラー内容 |
---|
164 | */ |
---|
165 | function lfCheckError(&$objFormParam) |
---|
166 | { |
---|
167 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
168 | $objErr->arrErr = $objFormParam->checkError(); |
---|
169 | return $objErr->arrErr; |
---|
170 | } |
---|
171 | |
---|
172 | /** |
---|
173 | * 既に登録されている内容を取得する |
---|
174 | * @param Object $objRecommend |
---|
175 | * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列 |
---|
176 | */ |
---|
177 | function getRecommendProducts(SC_Helper_BestProducts_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); |
---|
189 | |
---|
190 | $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']; |
---|
194 | $arrReturnProducts[$data['rank']] = $data; |
---|
195 | } |
---|
196 | return $arrReturnProducts; |
---|
197 | } |
---|
198 | |
---|
199 | /** |
---|
200 | * おすすめ商品の新規登録を行う。 |
---|
201 | * @param Array $arrPost POSTの値を格納した配列 |
---|
202 | * @param Integer $member_id 登録した管理者を示すID |
---|
203 | * @param Object $objRecommend |
---|
204 | */ |
---|
205 | function insertRecommendProduct($arrPost,$member_id, SC_Helper_BestProducts_Ex &$objRecommend) |
---|
206 | { |
---|
207 | // 古いおすすめ商品のデータを削除する。 |
---|
208 | $this->deleteProduct($arrPost, $objRecommend); |
---|
209 | |
---|
210 | $sqlval = array(); |
---|
211 | $sqlval['product_id'] = $arrPost['product_id']; |
---|
212 | $sqlval['category_id'] = $arrPost['category_id']; |
---|
213 | $sqlval['rank'] = $arrPost['rank']; |
---|
214 | $sqlval['comment'] = $arrPost['comment']; |
---|
215 | $sqlval['creator_id'] = $member_id; |
---|
216 | $objRecommend->saveBestProducts($sqlval); |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * データを削除する |
---|
221 | * @param Array $arrPost POSTの値を格納した配列 |
---|
222 | * @param Object $objRecommend |
---|
223 | * @return void |
---|
224 | */ |
---|
225 | function deleteProduct($arrPost, SC_Helper_BestProducts_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->deleteBestProducts($target); |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | * 商品情報を取得する |
---|
238 | * @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; |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * 商品のデータを表示用に処理する |
---|
255 | * @param Array $arrPost POSTのデータを格納した配列 |
---|
256 | * @param Array $arrItems フロントに表示される商品の情報を格納した配列 |
---|
257 | */ |
---|
258 | function setProducts($arrPost,$arrItems) |
---|
259 | { |
---|
260 | $arrProduct = $this->getProduct($arrPost['product_id']); |
---|
261 | if (count($arrProduct) > 0) { |
---|
262 | $rank = $arrPost['rank']; |
---|
263 | foreach ($arrProduct as $key => $val) { |
---|
264 | $arrItems[$rank][$key] = $val; |
---|
265 | } |
---|
266 | $arrItems[$rank]['rank'] = $rank; |
---|
267 | } |
---|
268 | return $arrItems; |
---|
269 | } |
---|
270 | |
---|
271 | } |
---|