source: branches/version-2_13_0/data/class/pages/admin/contents/LC_Page_Admin_Contents_RecommendSearch.php @ 23140

Revision 23140, 7.9 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23128 - r23137 をマージ

  • 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    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 Object $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  Object $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     */
142    public function createWhere(&$objFormParam,&$objDb)
143    {
144        $arrForm = $objFormParam->getHashArray();
145        $where = 'alldtl.del_flg = 0';
146        $bind = array();
147        foreach ($arrForm as $key => $val) {
148            if ($val == '') {
149                continue;
150            }
151
152            switch ($key) {
153                case 'search_name':
154                    $where .= ' AND name ILIKE ?';
155                    $bind[] = '%'.$val.'%';
156                    break;
157                case 'search_category_id':
158                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val);
159                    if ($tmp_where != '') {
160                        $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
161                        $bind = array_merge((array) $bind, (array) $tmp_bind);
162                    }
163                    break;
164                case 'search_product_code':
165                    $where .=    ' AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)';
166                    $bind[] = '%'.$val.'%';
167                    break;
168                case 'search_status':
169                    $where .= ' AND alldtl.status = ?';
170                    $bind[] = $val;
171                    break;
172                default:
173                    break;
174            }
175        }
176
177        return array(
178            'where'=>$where,
179            'bind' => $bind
180        );
181    }
182
183    /**
184     *
185     * 検索結果対象となる商品の数を返す。
186     * @param array      $whereAndBind
187     * @param SC_Product $objProduct
188     */
189    public function getLineCount($whereAndBind,&$objProduct)
190    {
191        $where = $whereAndBind['where'];
192        $bind = $whereAndBind['bind'];
193        // 検索結果対象となる商品の数を取得
194        $objQuery =& SC_Query_Ex::getSingletonInstance();
195        $objQuery->setWhere($where);
196        $linemax = $objProduct->findProductCount($objQuery, $bind);
197
198        return $linemax;   // 何件が該当しました。表示用
199    }
200
201    /**
202     * 検索結果の取得
203     * @param array      $whereAndBind string whereと array bindの連想配列
204     * @param SC_Product $objProduct
205     */
206    public function getProducts($whereAndBind,&$objProduct, $page_max, $startno)
207    {
208        $where = $whereAndBind['where'];
209        $bind = $whereAndBind['bind'];
210        $objQuery =& SC_Query_Ex::getSingletonInstance();
211        $objQuery->setWhere($where);
212        // 取得範囲の指定(開始行番号、行数のセット)
213        $objQuery->setLimitOffset($page_max, $startno);
214        // 検索結果の取得
215        return $objProduct->findProductIdsOrder($objQuery, $bind);
216    }
217
218    /**
219     * 商品取得
220     *
221     * @param array      $arrProductId
222     * @param SC_Product $objProduct
223     */
224    public function getProductList($arrProductId, &$objProduct)
225    {
226        $objQuery =& SC_Query_Ex::getSingletonInstance();
227
228        // 表示順序
229        $order = 'update_date DESC, product_id DESC';
230        $objQuery->setOrder($order);
231
232        return $objProduct->getListByProductIds($objQuery, $arrProductId);
233    }
234}
Note: See TracBrowser for help on using the repository browser.