source: branches/version-2_12-multilang/data/class/pages/admin/products/LC_Page_Admin_Products_Review.php @ 22492

Revision 22492, 14.7 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_Products_Review 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 = 'products/review.tpl';
47        $this->tpl_mainno = 'products';
48        $this->tpl_subno = 'review';
49        $this->tpl_pager = 'pager.tpl';
50        $this->tpl_maintitle = t('TPL_MAINTITLE_007');
51        $this->tpl_subtitle = t('LC_Page_Admin_Products_Review_001');
52
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrPageMax = $masterData->getMasterData('mtb_page_max');
55        $this->arrRECOMMEND = $masterData->getMasterData('mtb_recommend');
56        $this->arrSex = $masterData->getMasterData('mtb_sex');
57
58        $objDate = new SC_Date_Ex();
59        // 登録・更新検索開始年
60        $objDate->setStartYear(RELEASE_YEAR);
61        $objDate->setEndYear(DATE('Y'));
62        $this->arrStartYear = $objDate->getYear();
63        $this->arrStartMonth = $objDate->getMonth();
64        $this->arrStartDay = $objDate->getDay();
65        // 登録・更新検索終了年
66        $objDate->setStartYear(RELEASE_YEAR);
67        $objDate->setEndYear(DATE('Y'));
68        $this->arrEndYear = $objDate->getYear();
69        $this->arrEndMonth = $objDate->getMonth();
70        $this->arrEndDay = $objDate->getDay();
71    }
72
73    /**
74     * Page のプロセス.
75     *
76     * @return void
77     */
78    function process() {
79        $this->action();
80        $this->sendResponse();
81    }
82
83    /**
84     * Page のアクション.
85     *
86     * @return void
87     */
88    function action() {
89
90        // パラメーター管理クラス
91        $objFormParam = new SC_FormParam_Ex();
92        $this->lfInitParam($objFormParam);
93        $objFormParam->setParam($_POST);
94        $objFormParam->convParam();
95        // URLを小文字に変換
96        $objFormParam->toLower('search_reviewer_url');
97
98        $this->arrForm = $objFormParam->getHashArray();
99        $this->arrHidden = $this->lfSetHidden($this->arrForm);
100
101        // 入力パラメーターチェック
102        $this->arrErr = $this->lfCheckError($objFormParam);
103        if (!SC_Utils_Ex::isBlank($this->arrErr)) {
104            return;
105        }
106
107        switch ($this->getMode()) {
108            case 'delete':
109                $this->lfDeleteReview($this->arrForm['review_id']);
110            case 'search':
111            case 'csv':
112
113                // 検索条件を取得
114                list($where, $arrWhereVal) = $this->lfGetWhere($this->arrForm);
115                // 検索結果を取得
116                $this->arrReview = $this->lfGetReview($this->arrForm, $where, $arrWhereVal);
117
118                //CSVダウンロード
119                if ($this->getMode() == 'csv') {
120                    $this->lfDoOutputCsv($where, $arrWhereVal);
121
122                    SC_Response_Ex::actionExit();
123                }
124
125                break;
126            default:
127                break;
128        }
129
130    }
131
132    /**
133     * デストラクタ.
134     *
135     * @return void
136     */
137    function destroy() {
138        parent::destroy();
139    }
140
141    /**
142     * 入力内容のチェックを行う.
143     *
144     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
145     * @return void
146     */
147    function lfCheckError(&$objFormParam) {
148        // 入力データを渡す。
149        $arrRet =  $objFormParam->getHashArray();
150        $objErr = new SC_CheckError_Ex($arrRet);
151        $objErr->arrErr = $objFormParam->checkError();
152
153        switch ($this->getMode()) {
154            case 'search':
155                $objErr->doFunc(array(t('c_Start day_01'), 'search_startyear', 'search_startmonth', 'search_startday'), array('CHECK_DATE'));
156                $objErr->doFunc(array(t('c_Completion date_01'), 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_DATE'));
157                $objErr->doFunc(array(t('c_Start day_01'), t('c_Completion date_01'), 'search_startyear', 'search_startmonth', 'search_startday', 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_SET_TERM'));
158                break;
159
160            case 'complete':
161                $objErr->doFunc(array(t('PARAM_LABEL_RECOMMEND_LEVEL'), 'recommend_level'), array('SELECT_CHECK'));
162                $objErr->doFunc(array(t('c_Title_01'), 'title', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
163                $objErr->doFunc(array(t('PARAM_LABEL_COMMENT'), 'comment', LTEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
164                break;
165            default:
166                break;
167        }
168        return $objErr->arrErr;
169    }
170
171    /**
172     * 商品レビューの削除
173     *
174     * @param integer $review_id 商品レビューのID
175     * @return void
176     */
177    function lfDeleteReview($review_id) {
178        $objQuery =& SC_Query_Ex::getSingletonInstance();
179        $sqlval['del_flg'] = 1;
180        $objQuery->update('dtb_review', $sqlval, 'review_id = ?', array($review_id));
181    }
182
183    /**
184     * hidden情報の作成
185     *
186     * @param array $arrForm フォームデータ
187     * @return array hidden情報
188     */
189    function lfSetHidden($arrForm) {
190        $arrHidden = array();
191        foreach ($arrForm AS $key=>$val) {
192            if (preg_match('/^search_/', $key)) {
193                switch ($key) {
194                    case 'search_sex':
195                        $arrHidden[$key] = SC_Utils_Ex::sfMergeParamCheckBoxes($val);
196                        if (!is_array($val)) {
197                            $arrForm[$key] = explode('-', $val);
198                        }
199                        break;
200                    default:
201                        $arrHidden[$key] = $val;
202                        break;
203                }
204            }
205        }
206        return $arrHidden;
207    }
208
209    /**
210     * パラメーター情報の初期化を行う.
211     *
212     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
213     * @return void
214     */
215    function lfInitParam(&$objFormParam) {
216        $objFormParam->addParam(t('PARAM_LABEL_REVIEWER_NAME'), 'search_reviewer_name', STEXT_LEN, 'KVas', array('MAX_LENGTH_CHECK'),'',false);
217        $objFormParam->addParam(t('PARAM_LABEL_REVIEWER_URL'), 'search_reviewer_url', STEXT_LEN, 'KVas', array('MAX_LENGTH_CHECK'),'',false);
218        $objFormParam->addParam(t('c_Product name_01'), 'search_name', STEXT_LEN, 'KVas', array('MAX_LENGTH_CHECK'),'',false);
219        $objFormParam->addParam(t('c_Product code_01'), 'search_product_code', STEXT_LEN, 'KVas', array('MAX_LENGTH_CHECK'),'',false);
220        $objFormParam->addParam(t('c_Gender_01'), 'search_sex', INT_LEN, 'n', array('MAX_LENGTH_CHECK'),'',false);
221        $objFormParam->addParam(t('PARAM_LABEL_RECOMMEND_LEVEL'), 'search_recommend_level', INT_LEN, 'n', array('MAX_LENGTH_CHECK'),'',false);
222        $objFormParam->addParam(t('PARAM_LABEL_POST_YEAR'), 'search_startyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'),'',false);
223        $objFormParam->addParam(t('PARAM_LABEL_POST_MONTH'), 'search_startmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'),'',false);
224        $objFormParam->addParam(t('PARAM_LABEL_POST_DATE'), 'search_startday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'),'',false);
225        $objFormParam->addParam(t('PARAM_LABEL_POST_YEAR'), 'search_endyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'),'',false);
226        $objFormParam->addParam(t('PARAM_LABEL_POST_MONTH'), 'search_endmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'),'',false);
227        $objFormParam->addParam(t('PARAM_LABEL_POST_DATE'), 'search_endday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'),'',false);
228        $objFormParam->addParam(t('PARAM_LABEL_MAX_DISP_NUM'), 'search_page_max', INT_LEN, 'n', array('MAX_LENGTH_CHECK'),'',false);
229        $objFormParam->addParam(t('PARAM_LABEL_PAGE_NUM'), 'search_pageno', INT_LEN, 'n', array('MAX_LENGTH_CHECK'),'',false);
230        $objFormParam->addParam(t('PARAM_LABEL_REVIEW_ID'), 'review_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK'),'',false);
231    }
232
233    /**
234     * CSV ファイル出力実行
235     *
236     * @param string $where WHERE文
237     * @param array $arrWhereVal WHERE文の判定値
238     * @return void
239     */
240    function lfDoOutputCsv($where, $arrWhereVal) {
241        $objCSV = new SC_Helper_CSV_Ex();
242        if ($where != '') {
243            $where = 'WHERE ' . $where;
244        }
245        $objCSV->sfDownloadCsv('4', $where, $arrWhereVal, '', true);
246    }
247
248    /**
249     * WHERE文の作成
250     *
251     * @param array $arrForm フォームデータ
252     * @return array WHERE文、判定値
253     */
254    function lfGetWhere($arrForm) {
255        //削除されていない商品を検索
256        $where = 'A.del_flg = 0 AND B.del_flg = 0';
257        $arrWhereVal = array();
258
259        foreach ($arrForm AS $key=>$val) {
260            if (empty($val)) continue;
261
262            switch ($key) {
263                case 'search_reviewer_name':
264                    $val = preg_replace('/ /', '%', $val);
265                    $where.= ' AND reviewer_name LIKE ? ';
266                    $arrWhereVal[] = "%$val%";
267                    break;
268
269                case 'search_reviewer_url':
270                    $val = preg_replace('/ /', '%', $val);
271                    $where.= ' AND reviewer_url LIKE ? ';
272                    $arrWhereVal[] = "%$val%";
273                    break;
274
275                case 'search_name':
276                    $val = preg_replace('/ /', '%', $val);
277                    $where.= ' AND name LIKE ? ';
278                    $arrWhereVal[] = "%$val%";
279                    break;
280
281                case 'search_product_code':
282                    $val = preg_replace('/ /', '%', $val);
283                    $where.= ' AND A.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ?)';
284                    $arrWhereVal[] = "%$val%";
285                    break;
286
287                case 'search_sex':
288                    $tmp_where = '';
289                    //$val=配列の中身,$element=各キーの値(1,2)
290                    if (is_array($val)) {
291                        foreach ($val as $element) {
292                            if ($element != '') {
293                                if ($tmp_where == '') {
294                                    $tmp_where .= ' AND (sex = ?';
295                                } else {
296                                    $tmp_where .= ' OR sex = ?';
297                                }
298                                $arrWhereVal[] = $element;
299                            }
300                        }
301                        if ($tmp_where != '') {
302                            $tmp_where .= ')';
303                            $where .= " $tmp_where ";
304                        }
305                    }
306
307                    break;
308
309                case 'search_recommend_level':
310                    $where.= ' AND recommend_level = ? ';
311                    $arrWhereVal[] = $val;
312                    break;
313
314                case 'search_startyear':
315                    if (isset($_POST['search_startyear']) && isset($_POST['search_startmonth']) && isset($_POST['search_startday'])) {
316                        $date = SC_Utils_Ex::sfGetTimestamp($_POST['search_startyear'], $_POST['search_startmonth'], $_POST['search_startday']);
317                        $where.= ' AND A.create_date >= ? ';
318                        $arrWhereVal[] = $date;
319                    }
320                    break;
321
322                case 'search_endyear':
323                    if (isset($_POST['search_startyear']) && isset($_POST['search_startmonth']) && isset($_POST['search_startday'])) {
324                        $date = SC_Utils_Ex::sfGetTimestamp($_POST['search_endyear'], $_POST['search_endmonth'], $_POST['search_endday']);
325                        $end_date = date('Y/m/d',strtotime('1 day' ,strtotime($date)));
326                        $where.= " AND A.create_date <= cast('$end_date' as date) ";
327                    }
328                    break;
329
330                default:
331                    break;
332            }
333
334        }
335        return array($where, $arrWhereVal);
336    }
337
338    /**
339     * レビュー検索結果の取得
340     *
341     * @param array $arrForm フォームデータ
342     * @param string $where WHERE文
343     * @param array $arrWhereVal WHERE文の判定値
344     * @return array レビュー一覧
345     */
346    function lfGetReview($arrForm, $where, $arrWhereVal) {
347        $objQuery =& SC_Query_Ex::getSingletonInstance();
348
349        // ページ送りの処理
350        $page_max = SC_Utils_Ex::sfGetSearchPageMax($arrForm['search_page_max']);
351
352        if (!isset($arrWhereVal)) $arrWhereVal = array();
353
354        $from = 'dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id ';
355        $linemax = $objQuery->count($from, $where, $arrWhereVal);
356        $this->tpl_linemax = $linemax;
357
358        $this->tpl_pageno = isset($arrForm['search_pageno']) ? $arrForm['search_pageno'] : '';
359
360        // ページ送りの取得
361        $objNavi = new SC_PageNavi_Ex($this->tpl_pageno, $linemax, $page_max,
362                                      'fnNaviSearchPage', NAVI_PMAX);
363        $this->arrPagenavi = $objNavi->arrPagenavi;
364        $startno = $objNavi->start_row;
365
366        // 取得範囲の指定(開始行番号、行数のセット)
367        $objQuery->setLimitOffset($page_max, $startno);
368
369        // 表示順序
370        $order = 'A.create_date DESC';
371        $objQuery->setOrder($order);
372        //検索結果の取得
373        //レビュー情報のカラムの取得
374        $col = 'review_id, A.product_id, reviewer_name, sex, recommend_level, ';
375        $col .= 'reviewer_url, title, comment, A.status, A.create_date, A.update_date, name';
376        $from = 'dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id ';
377        $arrReview = $objQuery->select($col, $from, $where, $arrWhereVal);
378
379        return $arrReview;
380    }
381
382}
Note: See TracBrowser for help on using the repository browser.