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

Revision 22559, 7.9 KB checked in by Qwert, 11 years ago (diff)

#2143 「おすすめ商品の検索画面にて非公開の商品もリストアップされる」を修正

おすすめ商品管理・おすすめ商品検索画面で非公開の商品のセルは色付きに。またおすすめ商品検索画面で検索条件に商品ステータスを追加。

  • 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
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_Contents_RecommendSearch 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_mainno = 'contents';
47        $this->tpl_subno = '';
48
49        $this->tpl_subtitle = '商品検索';
50    }
51
52    /**
53     * Page のプロセス.
54     *
55     * @return void
56     */
57    function process() {
58        $this->action();
59        $this->sendResponse();
60    }
61
62    /**
63     * Page のアクション.
64     *
65     * @return void
66     */
67    function action() {
68
69        $objDb = new SC_Helper_DB_Ex();
70        $objFormParam = new SC_FormParam_Ex();
71        $this->lfInitParam($objFormParam);
72        $objFormParam->setParam($_POST);
73        $objFormParam->convParam();
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, 'fnNaviSearchOnlyPage', 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->setTemplate('contents/recommend_search.tpl');
107
108    }
109
110    /**
111     * デストラクタ.
112     *
113     * @return void
114     */
115    function destroy() {
116        parent::destroy();
117    }
118
119    /**
120     * パラメーターの初期化を行う
121     * @param Object $objFormParam
122     */
123    function lfInitParam(&$objFormParam) {
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        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
138        $objErr->arrErr = $objFormParam->checkError();
139        return $objErr->arrErr;
140    }
141
142    /**
143     *
144     * POSTされた値からSQLのWHEREとBINDを配列で返す。
145     * @return array ('where' => where string, 'bind' => databind array)
146     * @param SC_FormParam $objFormParam
147     */
148    function createWhere(&$objFormParam,&$objDb) {
149        $arrForm = $objFormParam->getHashArray();
150        $where = 'alldtl.del_flg = 0';
151        $bind = array();
152        foreach ($arrForm as $key => $val) {
153            if ($val == '') {
154                continue;
155            }
156
157            switch ($key) {
158                case 'search_name':
159                    $where .= ' AND name ILIKE ?';
160                    $bind[] = '%'.$val.'%';
161                    break;
162                case 'search_category_id':
163                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val);
164                    if ($tmp_where != '') {
165                        $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
166                        $bind = array_merge((array)$bind, (array)$tmp_bind);
167                    }
168                    break;
169                case 'search_product_code':
170                    $where .=    ' AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)';
171                    $bind[] = '%'.$val.'%';
172                    break;
173                case 'search_status':
174                    $where .= ' AND alldtl.status = ?';
175                    $bind[] = $val;
176                    break;
177                default:
178                    break;
179            }
180        }
181        return array(
182            'where'=>$where,
183            'bind' => $bind
184        );
185    }
186
187    /**
188     *
189     * 検索結果対象となる商品の数を返す。
190     * @param array $whereAndBind
191     * @param SC_Product $objProduct
192     */
193    function getLineCount($whereAndBind,&$objProduct) {
194        $where = $whereAndBind['where'];
195        $bind = $whereAndBind['bind'];
196        // 検索結果対象となる商品の数を取得
197        $objQuery =& SC_Query_Ex::getSingletonInstance();
198        $objQuery->setWhere($where);
199        $linemax = $objProduct->findProductCount($objQuery, $bind);
200        return $linemax;   // 何件が該当しました。表示用
201    }
202
203    /**
204     * 検索結果の取得
205     * @param array $whereAndBind string whereと array bindの連想配列
206     * @param SC_Product $objProduct
207     */
208    function getProducts($whereAndBind,&$objProduct, $page_max, $startno) {
209        $where = $whereAndBind['where'];
210        $bind = $whereAndBind['bind'];
211        $objQuery =& SC_Query_Ex::getSingletonInstance();
212        $objQuery->setWhere($where);
213        // 取得範囲の指定(開始行番号、行数のセット)
214        $objQuery->setLimitOffset($page_max, $startno);
215        // 検索結果の取得
216        return $objProduct->findProductIdsOrder($objQuery, $bind);
217    }
218
219    /**
220     * 商品取得
221     *
222     * @param array $arrProductId
223     * @param SC_Product $objProduct
224     */
225    function getProductList($arrProductId, &$objProduct) {
226        $objQuery =& SC_Query_Ex::getSingletonInstance();
227
228        // 表示順序
229        $order = 'update_date DESC, product_id DESC';
230        $objQuery->setOrder($order);
231        return $objProduct->getListByProductIds($objQuery, $arrProductId);
232    }
233}
Note: See TracBrowser for help on using the repository browser.