source: branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_Review.php @ 22926

Revision 22926, 6.8 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 不明確な仕様にコメントを残した。
  • 親デストラクタを呼ぶだけの記述は可読性が悪くなると考え削除した。(上述のチケットで OS の仕様に依存したデストラクタとなるため、敢えてアプリケーション側で記述しておく意義は薄れたという認識のもと。)
  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * お客様の声投稿のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id:LC_Page_Products_Review.php 15532 2007-08-31 14:39:46Z nanasess $
32 */
33class LC_Page_Products_Review extends LC_Page_Ex
34{
35    /** おすすめレベル */
36    var $arrRECOMMEND;
37
38    /** 性別 */
39    var $arrSex;
40
41    /** 入力禁止URL */
42    var $arrReviewDenyURL;
43
44    /**
45     * Page を初期化する.
46     *
47     * @return void
48     */
49    function init()
50    {
51        parent::init();
52
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrRECOMMEND = $masterData->getMasterData('mtb_recommend');
55        $this->arrSex = $masterData->getMasterData('mtb_sex');
56        $this->arrReviewDenyURL = $masterData->getMasterData('mtb_review_deny_url');
57        $this->tpl_mainpage = 'products/review.tpl';
58        $this->httpCacheControl('nocache');
59    }
60
61    /**
62     * Page のプロセス.
63     */
64    function process()
65    {
66        parent::process();
67        $this->action();
68        $this->sendResponse();
69    }
70
71    /**
72     * Page のAction.
73     *
74     * @return void
75     */
76    function action()
77    {
78        $objFormParam = new SC_FormParam_Ex();
79        $this->lfInitParam($objFormParam);
80        $objFormParam->setParam($_POST);
81        $objFormParam->convParam();
82
83        switch ($this->getMode()) {
84            case 'confirm':
85                $this->arrErr = $this->lfCheckError($objFormParam);
86
87                //エラーチェック
88                if (empty($this->arrErr)) {
89                    //重複タイトルでない
90                    $this->tpl_mainpage = 'products/review_confirm.tpl';
91                }
92                break;
93
94            case 'return':
95                break;
96
97            case 'complete':
98                $this->arrErr = $this->lfCheckError($objFormParam);
99                //エラーチェック
100                if (empty($this->arrErr)) {
101                    //登録実行
102                    $this->lfRegistRecommendData($objFormParam);
103
104                    //レビュー書き込み完了ページへ
105                    SC_Response_Ex::sendRedirect('review_complete.php');
106                    SC_Response_Ex::actionExit();
107                }
108                break;
109
110            default:
111                // 最初のproduct_idは、$_GETで渡ってくる。
112                $objFormParam->setParam($_GET);
113                break;
114        }
115
116        $this->arrForm = $objFormParam->getHashArray();
117
118        //商品名の取得
119        $this->arrForm['name'] = $this->lfGetProductName($this->arrForm['product_id']);
120        if (empty($this->arrForm['name'])) {
121            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
122        }
123
124        $this->setTemplate($this->tpl_mainpage);
125    }
126
127    /**
128     * パラメーター情報の初期化を行う.
129     *
130     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
131     * @return void
132     */
133    function lfInitParam(&$objFormParam)
134    {
135        $objFormParam->addParam('レビューID', 'review_id', INT_LEN, 'aKV');
136        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('NUM_CHECK','EXIST_CHECK', 'MAX_LENGTH_CHECK'));
137        $objFormParam->addParam('投稿者名', 'reviewer_name', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
138        $objFormParam->addParam('投稿者URL', 'reviewer_url', MTEXT_LEN, 'a', array('NO_SPTAB', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK', 'URL_CHECK'));
139        $objFormParam->addParam('性別', 'sex', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
140        $objFormParam->addParam('おすすめレベル', 'recommend_level', INT_LEN, 'n', array('EXIST_CHECK', 'SELECT_CHECK'));
141        $objFormParam->addParam('タイトル', 'title', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
142        $objFormParam->addParam('コメント', 'comment', LTEXT_LEN, 'aKV', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
143    }
144
145    /**
146     * 入力内容のチェックを行う.
147     *
148     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
149     * @return array エラーメッセージの配列
150     */
151    function lfCheckError(&$objFormParam)
152    {
153        $arrErr = $objFormParam->checkError();
154
155        $arrForm = $objFormParam->getHashArray();
156
157        // 重複メッセージの判定
158        $objQuery =& SC_Query_Ex::getSingletonInstance();
159        $exists = $objQuery->exists('dtb_review','product_id = ? AND title = ? ', array($arrForm['product_id'], $arrForm['title']));
160        if ($exists) {
161            $arrErr['title'] .= '重複したタイトルは登録できません。';
162        }
163
164        if (REVIEW_ALLOW_URL == false) {
165            $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
166            // コメント欄へのURLの入力を禁止
167            $objErr->doFunc(array('URL', 'comment', $this->arrReviewDenyURL), array('PROHIBITED_STR_CHECK'));
168            $arrErr += $objErr->arrErr;
169        }
170
171        return $arrErr;
172    }
173
174    /**
175     * 商品名を取得
176     *
177     * @param integer $product_id 商品ID
178     * @return string $product_name 商品名
179     */
180    function lfGetProductName($product_id)
181    {
182        $objQuery =& SC_Query_Ex::getSingletonInstance();
183
184        return $objQuery->get('name', 'dtb_products', 'product_id = ? AND ' . SC_Product_Ex::getProductDispConditions(), array($product_id));
185    }
186
187    //登録実行
188    function lfRegistRecommendData(&$objFormParam)
189    {
190        $objQuery =& SC_Query_Ex::getSingletonInstance();
191        $arrRegist = $objFormParam->getDbArray();
192
193        $arrRegist['create_date'] = 'CURRENT_TIMESTAMP';
194        $arrRegist['update_date'] = 'CURRENT_TIMESTAMP';
195        $arrRegist['creator_id'] = '0';
196
197        //-- 登録実行
198        $objQuery->begin();
199        $arrRegist['review_id'] = $objQuery->nextVal('dtb_review_review_id');
200        $objQuery->insert('dtb_review', $arrRegist);
201        $objQuery->commit();
202    }
203}
Note: See TracBrowser for help on using the repository browser.