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

Revision 20335, 8.8 KB checked in by nanasess, 13 years ago (diff)

r20313 の続き. 管理画面各ページの SC_Utils_Ex::sfIsSuccess(new SC_Session) を削除

  • 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_REALDIR . "pages/admin/LC_Page_Admin.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 {
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();
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     * トランザクショントークンを unset しないようオーバーライド.
132     *
133     * @return void
134     */
135    function doValidToken() {
136        if ($_SERVER["REQUEST_METHOD"] == "POST") {
137            if (!SC_Helper_Session_Ex::isValidToken(false)) {
138                //                SC_Utils_Ex::sfDispError(INVALID_MOVE_ERRORR);
139            }
140        }
141    }
142
143     /**
144     * パラメータの初期化を行う
145     * @param Object $objFormParam
146     */
147    function lfInitParam(&$objFormParam){
148        $objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
149        $objFormParam->addParam("カテゴリID", "category_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
150        $objFormParam->addParam("ランク", "rank", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
151        $objFormParam->addParam("コメント", "comment", LTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
152    }
153
154    /**
155     * 入力されたパラメータのエラーチェックを行う。
156     * @param Object $objFormParam
157     * @return Array エラー内容
158     */
159    function lfCheckError(&$objFormParam){
160        $objErr = new SC_CheckError($objFormParam->getHashArray());
161        $objErr->arrErr = $objFormParam->checkError();
162        return $objErr->arrErr;
163    }
164
165    /**
166     * 既に登録されている内容を取得する
167     * @return Array $arrReturnProducts データベースに登録されているおすすめ商品の配列
168     */
169    function getRecommendProducts(){
170        $objQuery = $objQuery =& SC_Query::getSingletonInstance();
171        $col = 'dtb_products.name,dtb_products.main_list_image,dtb_best_products.*';
172        $table = 'dtb_best_products INNER JOIN dtb_products USING (product_id)';
173        $where = 'dtb_best_products.del_flg = 0';
174        $order = 'rank';
175        $objQuery->setOrder($order);
176        $arrProducts = $objQuery->select($col, $table, $where);
177       
178        $arrReturnProducts = array();
179        foreach( $arrProducts as $data ){
180            $arrReturnProducts[$data['rank']] = $data;
181        }
182        return $arrReturnProducts;
183    }
184
185    /**
186     * おすすめ商品の新規登録を行う。
187     * @param Array $arrPost POSTの値を格納した配列
188     * @param Integer $member_id 登録した管理者を示すID
189     */
190    function insertRecommendProduct($arrPost,$member_id){
191        $objQuery = $objQuery =& SC_Query::getSingletonInstance();
192        // 古いおすすめ商品のデータを削除する。
193        $this->deleteProduct($arrPost);
194
195        $sqlval = array();
196        $sqlval['product_id'] = $arrPost['product_id'];
197        $sqlval['category_id'] = $arrPost['category_id'];
198        $sqlval['rank'] = $arrPost['rank'];
199        $sqlval['comment'] = $arrPost['comment'];
200        $sqlval['creator_id'] = $member_id;
201        $sqlval['create_date'] = "NOW()";
202        $sqlval['update_date'] = "NOW()";
203        $sqlval['best_id'] = $objQuery->nextVal('dtb_best_products_best_id');
204        $objQuery->insert("dtb_best_products", $sqlval);
205    }
206
207    /**
208     * データを削除する
209     * @param Array $arrPost POSTの値を格納した配列
210     */
211    function deleteProduct($arrPost){
212        $objQuery = $objQuery =& SC_Query::getSingletonInstance();
213        $table = 'dtb_best_products';
214        $where = 'category_id = ? AND rank = ?';
215        $arrval = array($arrPost['category_id'],$arrPost['rank']);
216        $objQuery->delete($table, $where, $arrval);
217    }
218
219    /**
220     * 商品情報を取得する
221     * @param Integer $product_id 商品ID
222     * @return Array $arrProduct 商品のデータを格納した配列
223     */
224    function getProduct($product_id){
225        $objQuery = $objQuery =& SC_Query::getSingletonInstance();
226        $col = 'product_id,main_list_image,name';
227        $table = 'dtb_products';
228        $where = 'product_id = ? AND del_flg = 0';
229        $arrval = array($product_id);
230        $arrProduct = $objQuery->select($col, $table, $where, $arrval);
231        return $arrProduct[0];
232    }
233
234    /**
235     * 商品のデータを表示用に処理する
236     * @param Array $arrPost POSTのデータを格納した配列
237     * @param Array $arrItems フロントに表示される商品の情報を格納した配列
238     */
239    function setProducts($arrPost,$arrItems){
240        $arrProduct = $this->getProduct($arrPost['product_id']);
241        if (count($arrProduct) > 0) {
242            $rank = $arrPost['rank'];
243            foreach( $arrProduct as $key => $val){
244                $arrItems[$rank][$key] = $val;
245            }
246            $arrItems[$rank]['rank'] = $rank;
247        }
248        return $arrItems;
249    }
250
251}
252?>
Note: See TracBrowser for help on using the repository browser.