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

Revision 22856, 7.9 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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