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

Revision 21743, 8.6 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #1692 (プラグイン機能) 各ファイルでフックポイントの呼出を書かないで、自動的にフックポイントを呼び出すように修正。

  • 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-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
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 = 'コンテンツ管理';
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        $objFormParam = new SC_FormParam_Ex();
73        $this->lfInitParam($objFormParam);
74        $objFormParam->setParam($_POST);
75        $objFormParam->convParam();
76
77        switch ($this->getMode()) {
78            case 'regist': // 商品を登録する。
79                $this->arrErr = $this->lfCheckError($objFormParam);
80                $arrPost = $objFormParam->getHashArray();
81                // 登録処理にエラーがあった場合は商品選択の時と同じ処理を行う。
82                if (SC_Utils_Ex::isBlank($this->arrErr)) {
83                    $member_id = $_SESSION['member_id'];
84                    $this->insertRecommendProduct($arrPost,$member_id);
85                    $arrItems = $this->getRecommendProducts();
86                } else {
87                    $arrItems = $this->setProducts($arrPost, $arrItems);
88                    $this->checkRank = $arrPost['rank'];
89                }
90                $this->tpl_onload = "window.alert('編集が完了しました');";
91                break;
92            case 'delete': // 商品を削除する。
93                $this->arrErr = $this->lfCheckError($objFormParam);
94                $arrPost = $objFormParam->getHashArray();
95                if (SC_Utils_Ex::isBlank($this->arrErr)) {
96                    $this->deleteProduct($arrPost);
97                    $arrItems = $this->getRecommendProducts();
98                }
99                $this->tpl_onload = "window.alert('削除しました');";
100                break;
101            case 'set_item': // 商品を選択する。
102                $this->arrErr = $this->lfCheckError($objFormParam);
103                $arrPost = $objFormParam->getHashArray();
104                if (SC_Utils_Ex::isBlank($this->arrErr['rank']) && SC_Utils_Ex::isBlank($this->arrErr['product_id'])) {
105                    $arrItems = $this->setProducts($arrPost, $this->getRecommendProducts());
106                    $this->checkRank = $arrPost['rank'];
107                }
108                break;
109            default:
110                $arrItems = $this->getRecommendProducts();
111                break;
112        }
113
114        $this->category_id = intval($arrPost['category_id']);
115        $this->arrItems = $arrItems;
116
117        // カテゴリ取得
118        $objDb = new SC_Helper_DB_Ex();
119        $this->arrCatList = $objDb->sfGetCategoryList('level = 1');
120
121    }
122
123    /**
124     * デストラクタ.
125     *
126     * @return void
127     */
128    function destroy() {
129        parent::destroy();
130    }
131
132    /**
133     * パラメーターの初期化を行う
134     * @param Object $objFormParam
135     */
136    function lfInitParam(&$objFormParam) {
137        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
138        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
139        $objFormParam->addParam('ランク', 'rank', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
140        $objFormParam->addParam('コメント', 'comment', LTEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
141    }
142
143    /**
144     * 入力されたパラメーターのエラーチェックを行う。
145     * @param Object $objFormParam
146     * @return Array エラー内容
147     */
148    function lfCheckError(&$objFormParam) {
149        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
150        $objErr->arrErr = $objFormParam->checkError();
151        return $objErr->arrErr;
152    }
153
154    /**
155     * 既に登録されている内容を取得する
156     * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列
157     */
158    function getRecommendProducts() {
159        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
160        $col = 'dtb_products.name,dtb_products.main_list_image,dtb_best_products.*';
161        $table = 'dtb_best_products INNER JOIN dtb_products USING (product_id)';
162        $where = 'dtb_best_products.del_flg = 0';
163        $order = 'rank';
164        $objQuery->setOrder($order);
165        $arrProducts = $objQuery->select($col, $table, $where);
166
167        $arrReturnProducts = array();
168        foreach ($arrProducts as $data) {
169            $arrReturnProducts[$data['rank']] = $data;
170        }
171        return $arrReturnProducts;
172    }
173
174    /**
175     * おすすめ商品の新規登録を行う。
176     * @param Array $arrPost POSTの値を格納した配列
177     * @param Integer $member_id 登録した管理者を示すID
178     */
179    function insertRecommendProduct($arrPost,$member_id) {
180        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
181        // 古いおすすめ商品のデータを削除する。
182        $this->deleteProduct($arrPost);
183
184        $sqlval = array();
185        $sqlval['product_id'] = $arrPost['product_id'];
186        $sqlval['category_id'] = $arrPost['category_id'];
187        $sqlval['rank'] = $arrPost['rank'];
188        $sqlval['comment'] = $arrPost['comment'];
189        $sqlval['creator_id'] = $member_id;
190        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
191        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
192        $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id');
193        $objQuery->insert('dtb_best_products', $sqlval);
194    }
195
196    /**
197     * データを削除する
198     * @param Array $arrPost POSTの値を格納した配列
199     */
200    function deleteProduct($arrPost) {
201        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
202        $table = 'dtb_best_products';
203        $where = 'category_id = ? AND rank = ?';
204        $arrWhereVal = array($arrPost['category_id'],$arrPost['rank']);
205        $objQuery->delete($table, $where, $arrWhereVal);
206    }
207
208    /**
209     * 商品情報を取得する
210     * @param Integer $product_id 商品ID
211     * @return Array $arrProduct 商品のデータを格納した配列
212     */
213    function getProduct($product_id) {
214        $objQuery = $objQuery =& SC_Query_Ex::getSingletonInstance();
215        $col = 'product_id,main_list_image,name';
216        $table = 'dtb_products';
217        $where = 'product_id = ? AND del_flg = 0';
218        $arrWhereVal = array($product_id);
219        $arrProduct = $objQuery->select($col, $table, $where, $arrWhereVal);
220        return $arrProduct[0];
221    }
222
223    /**
224     * 商品のデータを表示用に処理する
225     * @param Array $arrPost POSTのデータを格納した配列
226     * @param Array $arrItems フロントに表示される商品の情報を格納した配列
227     */
228    function setProducts($arrPost,$arrItems) {
229        $arrProduct = $this->getProduct($arrPost['product_id']);
230        if (count($arrProduct) > 0) {
231            $rank = $arrPost['rank'];
232            foreach ($arrProduct as $key => $val) {
233                $arrItems[$rank][$key] = $val;
234            }
235            $arrItems[$rank]['rank'] = $rank;
236        }
237        return $arrItems;
238    }
239
240}
Note: See TracBrowser for help on using the repository browser.