source: branches/version-2_12-multilang/data/class/pages/admin/contents/LC_Page_Admin_Contents_Recommend.php @ 22496

Revision 22496, 9.9 KB checked in by m_uehara, 11 years ago (diff)

#2084 メッセージIDの振り直し

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2012 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
25require_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 */
34class 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 = t('c_Edit contents_01');
50        $this->tpl_subtitle = t('LC_Page_Admin_Contents_Recommend_002');
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        $objFormParam = new SC_FormParam_Ex();
72        $this->lfInitParam($objFormParam);
73        $objFormParam->setParam($_POST);
74        $objFormParam->convParam();
75        $objQuery =& SC_Query_Ex::getSingletonInstance();
76        $objDb = new SC_Helper_DB_Ex();
77
78        switch ($this->getMode()) {
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();
93                break;
94
95            case 'regist': // 商品を登録する。
96                $this->arrErr = $this->lfCheckError($objFormParam);
97                $arrPost = $objFormParam->getHashArray();
98                // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。
99                if (SC_Utils_Ex::isBlank($this->arrErr)) {
100                    $member_id = $_SESSION['member_id'];
101                    $this->insertRecommendProduct($arrPost,$member_id);
102                    $arrItems = $this->getRecommendProducts();
103                } else {
104                    $arrItems = $this->setProducts($arrPost, $arrItems);
105                    $this->checkRank = $arrPost['rank'];
106                }
107                $this->tpl_onload = "window.alert('" . t('c_Editing is complete_01') . "');";
108                break;
109            case 'delete': // 商品を削除する。
110                $this->arrErr = $this->lfCheckError($objFormParam);
111                $arrPost = $objFormParam->getHashArray();
112                if (SC_Utils_Ex::isBlank($this->arrErr)) {
113                    $this->deleteProduct($arrPost);
114                    $arrItems = $this->getRecommendProducts();
115                }
116                $this->tpl_onload = "window.alert('" . t('c_Deletion was successful_01') . "');";
117                break;
118            case 'set_item': // 商品を選択する。
119                $this->arrErr = $this->lfCheckError($objFormParam);
120                $arrPost = $objFormParam->getHashArray();
121                if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) {
122                    $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts());
123                    $this->checkRank = $arrPost['rank'];
124                }
125                break;
126            default:
127                $arrItems = $this->getRecommendProducts();
128                break;
129        }
130
131        $this->category_id = intval($arrPost['category_id']);
132        $this->arrItems = $arrItems;
133
134        // カテゴリ取得
135        $objDb = new SC_Helper_DB_Ex();
136        $this->arrCatList = $objDb->sfGetCategoryList('level = 1');
137
138    }
139
140    /**
141     * デストラクタ.
142     *
143     * @return void
144     */
145    function destroy() {
146        parent::destroy();
147    }
148
149    /**
150     * パラメーターの初期化を行う
151     * @param Object $objFormParam
152     */
153    function lfInitParam(&$objFormParam) {
154        $objFormParam->addParam(t('c_Product ID_01'), 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
155        $objFormParam->addParam(t('c_Category ID_01'), 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
156        $objFormParam->addParam(t('c_Rank_01'), 'rank', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
157        $objFormParam->addParam(t('c_Comment_01'), '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        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
167        $objErr->arrErr = $objFormParam->checkError();
168        return $objErr->arrErr;
169    }
170
171    /**
172     * 既に登録されている内容を取得する
173     * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列
174     */
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);
183
184        $arrReturnProducts = array();
185        foreach ($arrProducts as $data) {
186            $arrReturnProducts[$data['rank']] = $data;
187        }
188        return $arrReturnProducts;
189    }
190
191    /**
192     * おすすめ商品の新規登録を行う。
193     * @param Array $arrPost POSTの値を格納した配列
194     * @param Integer $member_id 登録した管理者を示すID
195     */
196    function insertRecommendProduct($arrPost,$member_id) {
197        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
198        // 古いおすすめ商品のデータを削除する。
199        $this->deleteProduct($arrPost);
200
201        $sqlval = array();
202        $sqlval['product_id'] = $arrPost['product_id'];
203        $sqlval['category_id'] = $arrPost['category_id'];
204        $sqlval['rank'] = $arrPost['rank'];
205        $sqlval['comment'] = $arrPost['comment'];
206        $sqlval['creator_id'] = $member_id;
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);
211    }
212
213    /**
214     * データを削除する
215     * @param Array $arrPost POSTの値を格納した配列
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);
223    }
224
225    /**
226     * 商品情報を取得する
227     * @param Integer $product_id 商品ID
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];
238    }
239
240    /**
241     * 商品のデータを表示用に処理する
242     * @param Array $arrPost POSTのデータを格納した配列
243     * @param Array $arrItems フロントに表示される商品の情報を格納した配列
244     */
245    function setProducts($arrPost,$arrItems) {
246        $arrProduct = $this->getProduct($arrPost['product_id']);
247        if (count($arrProduct) > 0) {
248            $rank = $arrPost['rank'];
249            foreach ($arrProduct as $key => $val) {
250                $arrItems[$rank][$key] = $val;
251            }
252            $arrItems[$rank]['rank'] = $rank;
253        }
254        return $arrItems;
255    }
256
257}
Note: See TracBrowser for help on using the repository browser.