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

Revision 20503, 8.4 KB checked in by shutta, 13 years ago (diff)

SC_CheckErrorクラスのclass_extends対応

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