source: branches/version-2_13-dev/data/class/pages/admin/contents/LC_Page_Admin_Contents_RecommendSearch.php @ 23606

Revision 23606, 8.0 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/e0f27994-b3c7-4fc6-ad70-55d3cd63769b/patches

  • 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-2014 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/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * おすすめ商品管理 商品検索のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Contents_RecommendSearch extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_mainno = 'contents';
44        $this->tpl_subno = '';
45
46        $this->tpl_subtitle = '商品検索';
47    }
48
49    /**
50     * Page のプロセス.
51     *
52     * @return void
53     */
54    public function process()
55    {
56        $this->action();
57        $this->sendResponse();
58    }
59
60    /**
61     * Page のアクション.
62     *
63     * @return void
64     */
65    public function action()
66    {
67        $objDb = new SC_Helper_DB_Ex();
68        $objFormParam = new SC_FormParam_Ex();
69        $this->lfInitParam($objFormParam);
70        $objFormParam->setParam($_POST);
71        $objFormParam->convParam();
72
73        $rank = intval($_GET['rank']);
74
75        switch ($this->getMode()) {
76            case 'search':
77                // POST値の引き継ぎ
78                $this->arrErr = $this->lfCheckError($objFormParam);
79                $arrPost = $objFormParam->getHashArray();
80                // 入力された値にエラーがない場合、検索処理を行う。
81                // 検索結果の数に応じてページャの処理も入れる。
82                if (SC_Utils_Ex::isBlank($this->arrErr)) {
83                    $objProduct = new SC_Product_Ex();
84
85                    $wheres = $this->createWhere($objFormParam, $objDb);
86                    $this->tpl_linemax = $this->getLineCount($wheres, $objProduct);
87
88                    $page_max = SC_Utils_Ex::sfGetSearchPageMax($arrPost['search_page_max']);
89
90                    // ページ送りの取得
91                    $objNavi = new SC_PageNavi_Ex($arrPost['search_pageno'], $this->tpl_linemax, $page_max, 'eccube.moveSearchPage', NAVI_PMAX);
92                    $this->tpl_strnavi = $objNavi->strnavi;      // 表示文字列
93                    $startno = $objNavi->start_row;
94
95                    $arrProduct_id = $this->getProducts($wheres, $objProduct, $page_max, $startno);
96                    $this->arrProducts = $this->getProductList($arrProduct_id, $objProduct);
97                    $this->arrForm = $arrPost;
98                }
99                break;
100            default:
101                break;
102        }
103
104        // カテゴリ取得
105        $this->arrCatList = $objDb->sfGetCategoryList();
106        $this->rank       = $rank;
107        $this->setTemplate('contents/recommend_search.tpl');
108    }
109
110    /**
111     * パラメーターの初期化を行う
112     * @param SC_FormParam_Ex $objFormParam
113     */
114    public function lfInitParam(&$objFormParam)
115    {
116        $objFormParam->addParam('商品ID', 'search_name', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
117        $objFormParam->addParam('商品ID', 'search_category_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
118        $objFormParam->addParam('商品コード', 'search_product_code', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
119        $objFormParam->addParam('商品ステータス', 'search_status', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
120        $objFormParam->addParam('ページ番号', 'search_pageno', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
121    }
122
123    /**
124     * 入力されたパラメーターのエラーチェックを行う。
125     * @param  SC_FormParam_Ex $objFormParam
126     * @return Array  エラー内容
127     */
128    public function lfCheckError(&$objFormParam)
129    {
130        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
131        $objErr->arrErr = $objFormParam->checkError();
132
133        return $objErr->arrErr;
134    }
135
136    /**
137     *
138     * POSTされた値からSQLのWHEREとBINDを配列で返す。
139     * @return array        ('where' => where string, 'bind' => databind array)
140     * @param  SC_FormParam $objFormParam
141     * @param SC_Helper_DB_Ex $objDb
142     */
143    public function createWhere(&$objFormParam, &$objDb)
144    {
145        $arrForm = $objFormParam->getHashArray();
146        $where = 'alldtl.del_flg = 0';
147        $bind = array();
148        foreach ($arrForm as $key => $val) {
149            if ($val == '') {
150                continue;
151            }
152
153            switch ($key) {
154                case 'search_name':
155                    $where .= ' AND name ILIKE ?';
156                    $bind[] = '%'.$val.'%';
157                    break;
158                case 'search_category_id':
159                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val);
160                    if ($tmp_where != '') {
161                        $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
162                        $bind = array_merge((array) $bind, (array) $tmp_bind);
163                    }
164                    break;
165                case 'search_product_code':
166                    $where .=    ' AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)';
167                    $bind[] = '%'.$val.'%';
168                    break;
169                case 'search_status':
170                    $where .= ' AND alldtl.status = ?';
171                    $bind[] = $val;
172                    break;
173                default:
174                    break;
175            }
176        }
177
178        return array(
179            'where'=>$where,
180            'bind' => $bind
181        );
182    }
183
184    /**
185     *
186     * 検索結果対象となる商品の数を返す。
187     * @param array      $whereAndBind
188     * @param SC_Product $objProduct
189     */
190    public function getLineCount($whereAndBind, &$objProduct)
191    {
192        $where = $whereAndBind['where'];
193        $bind = $whereAndBind['bind'];
194        // 検索結果対象となる商品の数を取得
195        $objQuery =& SC_Query_Ex::getSingletonInstance();
196        $objQuery->setWhere($where);
197        $linemax = $objProduct->findProductCount($objQuery, $bind);
198
199        return $linemax;   // 何件が該当しました。表示用
200    }
201
202    /**
203     * 検索結果の取得
204     * @param array      $whereAndBind string whereと array bindの連想配列
205     * @param SC_Product $objProduct
206     * @param integer $page_max
207     */
208    public function getProducts($whereAndBind, &$objProduct, $page_max, $startno)
209    {
210        $where = $whereAndBind['where'];
211        $bind = $whereAndBind['bind'];
212        $objQuery =& SC_Query_Ex::getSingletonInstance();
213        $objQuery->setWhere($where);
214        // 取得範囲の指定(開始行番号、行数のセット)
215        $objQuery->setLimitOffset($page_max, $startno);
216        // 検索結果の取得
217        return $objProduct->findProductIdsOrder($objQuery, $bind);
218    }
219
220    /**
221     * 商品取得
222     *
223     * @param array      $arrProductId
224     * @param SC_Product $objProduct
225     */
226    public function getProductList($arrProductId, &$objProduct)
227    {
228        $objQuery =& SC_Query_Ex::getSingletonInstance();
229
230        // 表示順序
231        $order = 'update_date DESC, product_id DESC';
232        $objQuery->setOrder($order);
233
234        return $objProduct->getListByProductIds($objQuery, $arrProductId);
235    }
236}
Note: See TracBrowser for help on using the repository browser.