1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2011 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 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | $this->tpl_mainpage = 'contents/recommend.tpl'; |
---|
47 | $this->tpl_mainno = 'contents'; |
---|
48 | $this->tpl_subno = 'recommend'; |
---|
49 | $this->tpl_maintitle = 'コンテンツ管理'; |
---|
50 | $this->tpl_subtitle = 'おすすめ商品管理'; |
---|
51 | //最大登録数の表示 |
---|
52 | $this->tpl_disp_max = RECOMMEND_NUM; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Page のプロセス. |
---|
57 | * |
---|
58 | * @return void |
---|
59 | */ |
---|
60 | function process() { |
---|
61 | $this->action(); |
---|
62 | $this->sendResponse(); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Page のアクション. |
---|
67 | * |
---|
68 | * @return void |
---|
69 | */ |
---|
70 | function action() { |
---|
71 | // フックポイント. |
---|
72 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg); |
---|
73 | $objPlugin->doAction('lc_page_admin_contents_recommend_action_start', array($this)); |
---|
74 | |
---|
75 | $objFormParam = new SC_FormParam_Ex(); |
---|
76 | $this->lfInitParam($objFormParam); |
---|
77 | $objFormParam->setParam($_POST); |
---|
78 | $objFormParam->convParam(); |
---|
79 | |
---|
80 | switch ($this->getMode()) { |
---|
81 | case 'regist': // 商品を登録する。 |
---|
82 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
83 | $arrPost = $objFormParam->getHashArray(); |
---|
84 | // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。 |
---|
85 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
86 | $member_id = $_SESSION['member_id']; |
---|
87 | $this->insertRecommendProduct($arrPost,$member_id); |
---|
88 | $arrItems = $this->getRecommendProducts(); |
---|
89 | } else { |
---|
90 | $arrItems = $this->setProducts($arrPost, $arrItems); |
---|
91 | $this->checkRank = $arrPost['rank']; |
---|
92 | } |
---|
93 | $this->tpl_onload = "window.alert('編集が完了しました');"; |
---|
94 | break; |
---|
95 | case 'delete': // 商品を削除する。 |
---|
96 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
97 | $arrPost = $objFormParam->getHashArray(); |
---|
98 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
99 | $this->deleteProduct($arrPost); |
---|
100 | $arrItems = $this->getRecommendProducts(); |
---|
101 | } |
---|
102 | $this->tpl_onload = "window.alert('削除しました');"; |
---|
103 | break; |
---|
104 | case 'set_item': // 商品を選択する。 |
---|
105 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
106 | $arrPost = $objFormParam->getHashArray(); |
---|
107 | if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) { |
---|
108 | $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts()); |
---|
109 | $this->checkRank = $arrPost['rank']; |
---|
110 | } |
---|
111 | break; |
---|
112 | default: |
---|
113 | $arrItems = $this->getRecommendProducts(); |
---|
114 | break; |
---|
115 | } |
---|
116 | |
---|
117 | $this->category_id = intval($arrPost['category_id']); |
---|
118 | $this->arrItems = $arrItems; |
---|
119 | |
---|
120 | // カテゴリ取得 |
---|
121 | $objDb = new SC_Helper_DB_Ex(); |
---|
122 | $this->arrCatList = $objDb->sfGetCategoryList('level = 1'); |
---|
123 | |
---|
124 | // フックポイント. |
---|
125 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg); |
---|
126 | $objPlugin->doAction('lc_page_admin_contents_recommend_action_end', array($this)); |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * デストラクタ. |
---|
131 | * |
---|
132 | * @return void |
---|
133 | */ |
---|
134 | function destroy() { |
---|
135 | parent::destroy(); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * パラメーターの初期化を行う |
---|
140 | * @param Object $objFormParam |
---|
141 | */ |
---|
142 | function lfInitParam(&$objFormParam) { |
---|
143 | $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
144 | $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
145 | $objFormParam->addParam('ランク', 'rank', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
146 | $objFormParam->addParam('コメント', 'comment', LTEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * 入力されたパラメーターのエラーチェックを行う。 |
---|
151 | * @param Object $objFormParam |
---|
152 | * @return Array エラー内容 |
---|
153 | */ |
---|
154 | function lfCheckError(&$objFormParam) { |
---|
155 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
156 | $objErr->arrErr = $objFormParam->checkError(); |
---|
157 | return $objErr->arrErr; |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * 既に登録されている内容を取得する |
---|
162 | * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列 |
---|
163 | */ |
---|
164 | function getRecommendProducts() { |
---|
165 | $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
166 | $col = 'dtb_products.name,dtb_products.main_list_image,dtb_best_products.*'; |
---|
167 | $table = 'dtb_best_products INNER JOIN dtb_products USING (product_id)'; |
---|
168 | $where = 'dtb_best_products.del_flg = 0'; |
---|
169 | $order = 'rank'; |
---|
170 | $objQuery->setOrder($order); |
---|
171 | $arrProducts = $objQuery->select($col, $table, $where); |
---|
172 | |
---|
173 | $arrReturnProducts = array(); |
---|
174 | foreach ($arrProducts as $data) { |
---|
175 | $arrReturnProducts[$data['rank']] = $data; |
---|
176 | } |
---|
177 | return $arrReturnProducts; |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * おすすめ商品の新規登録を行う。 |
---|
182 | * @param Array $arrPost POSTの値を格納した配列 |
---|
183 | * @param Integer $member_id 登録した管理者を示すID |
---|
184 | */ |
---|
185 | function insertRecommendProduct($arrPost,$member_id) { |
---|
186 | $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
187 | // 古いおすすめ商品のデータを削除する。 |
---|
188 | $this->deleteProduct($arrPost); |
---|
189 | |
---|
190 | $sqlval = array(); |
---|
191 | $sqlval['product_id'] = $arrPost['product_id']; |
---|
192 | $sqlval['category_id'] = $arrPost['category_id']; |
---|
193 | $sqlval['rank'] = $arrPost['rank']; |
---|
194 | $sqlval['comment'] = $arrPost['comment']; |
---|
195 | $sqlval['creator_id'] = $member_id; |
---|
196 | $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; |
---|
197 | $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
198 | $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id'); |
---|
199 | $objQuery->insert('dtb_best_products', $sqlval); |
---|
200 | } |
---|
201 | |
---|
202 | /** |
---|
203 | * データを削除する |
---|
204 | * @param Array $arrPost POSTの値を格納した配列 |
---|
205 | */ |
---|
206 | function deleteProduct($arrPost) { |
---|
207 | $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
208 | $table = 'dtb_best_products'; |
---|
209 | $where = 'category_id = ? AND rank = ?'; |
---|
210 | $arrWhereVal = array($arrPost['category_id'],$arrPost['rank']); |
---|
211 | $objQuery->delete($table, $where, $arrWhereVal); |
---|
212 | } |
---|
213 | |
---|
214 | /** |
---|
215 | * 商品情報を取得する |
---|
216 | * @param Integer $product_id 商品ID |
---|
217 | * @return Array $arrProduct 商品のデータを格納した配列 |
---|
218 | */ |
---|
219 | function getProduct($product_id) { |
---|
220 | $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
221 | $col = 'product_id,main_list_image,name'; |
---|
222 | $table = 'dtb_products'; |
---|
223 | $where = 'product_id = ? AND del_flg = 0'; |
---|
224 | $arrWhereVal = array($product_id); |
---|
225 | $arrProduct = $objQuery->select($col, $table, $where, $arrWhereVal); |
---|
226 | return $arrProduct[0]; |
---|
227 | } |
---|
228 | |
---|
229 | /** |
---|
230 | * 商品のデータを表示用に処理する |
---|
231 | * @param Array $arrPost POSTのデータを格納した配列 |
---|
232 | * @param Array $arrItems フロントに表示される商品の情報を格納した配列 |
---|
233 | */ |
---|
234 | function setProducts($arrPost,$arrItems) { |
---|
235 | $arrProduct = $this->getProduct($arrPost['product_id']); |
---|
236 | if (count($arrProduct) > 0) { |
---|
237 | $rank = $arrPost['rank']; |
---|
238 | foreach ($arrProduct as $key => $val) { |
---|
239 | $arrItems[$rank][$key] = $val; |
---|
240 | } |
---|
241 | $arrItems[$rank]['rank'] = $rank; |
---|
242 | } |
---|
243 | return $arrItems; |
---|
244 | } |
---|
245 | |
---|
246 | } |
---|