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

Revision 22796, 7.6 KB checked in by h_yoshimoto, 11 years ago (diff)

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

  • 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
RevLine 
[15661]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[22206]5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
[15661]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15661]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15661]26
27/**
[17455]28 * おすすめ商品管理 商品検索のページクラス.
[15661]29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[22796]34class LC_Page_Admin_Contents_RecommendSearch extends LC_Page_Admin_Ex {
[15661]35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
[22796]44    function init() {
[15661]45        parent::init();
46        $this->tpl_mainno = 'contents';
[21514]47        $this->tpl_subno = '';
[15661]48
[21250]49        $this->tpl_subtitle = '商品検索';
[15661]50    }
51
52    /**
53     * Page のプロセス.
54     *
55     * @return void
56     */
[22796]57    function process() {
[19661]58        $this->action();
59        $this->sendResponse();
60    }
61
62    /**
63     * Page のアクション.
64     *
65     * @return void
66     */
[22796]67    function action() {
[21591]68
[15661]69        $objDb = new SC_Helper_DB_Ex();
[20501]70        $objFormParam = new SC_FormParam_Ex();
[20265]71        $this->lfInitParam($objFormParam);
72        $objFormParam->setParam($_POST);
73        $objFormParam->convParam();
[15661]74
[20044]75        switch ($this->getMode()) {
[21526]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();
[20391]84
[21526]85                    $wheres = $this->createWhere($objFormParam,$objDb);
86                    $this->tpl_linemax = $this->getLineCount($wheres,$objProduct);
[20391]87
[21526]88                    $page_max = SC_Utils_Ex::sfGetSearchPageMax($arrPost['search_page_max']);
[15661]89
[21526]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;
[15661]94
[21526]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;
[20265]102        }
103
104        // カテゴリ取得
105        $this->arrCatList = $objDb->sfGetCategoryList();
106        $this->setTemplate('contents/recommend_search.tpl');
[21591]107
[20265]108    }
109
110    /**
111     * デストラクタ.
112     *
113     * @return void
114     */
[22796]115    function destroy() {
[20265]116        parent::destroy();
117    }
118
119    /**
[20970]120     * パラメーターの初期化を行う
[20265]121     * @param Object $objFormParam
122     */
[22796]123    function lfInitParam(&$objFormParam) {
[21514]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'));
[21829]126        $objFormParam->addParam('商品コード', 'search_product_code', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
[21514]127        $objFormParam->addParam('ページ番号', 'search_pageno', INT_LEN, 'n', array('MAX_LENGTH_CHECK','NUM_CHECK'));
[20265]128    }
129
130    /**
[20970]131     * 入力されたパラメーターのエラーチェックを行う。
[20265]132     * @param Object $objFormParam
133     * @return Array エラー内容
134     */
[22796]135    function lfCheckError(&$objFormParam) {
[20503]136        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
[20265]137        $objErr->arrErr = $objFormParam->checkError();
138        return $objErr->arrErr;
139    }
140
141    /**
[20391]142     *
143     * POSTされた値からSQLのWHEREとBINDを配列で返す。
144     * @return array ('where' => where string, 'bind' => databind array)
145     * @param SC_FormParam $objFormParam
[20265]146     */
[22796]147    function createWhere(&$objFormParam,&$objDb) {
[20391]148        $arrForm = $objFormParam->getHashArray();
[21514]149        $where = 'alldtl.del_flg = 0';
[20391]150        $bind = array();
151        foreach ($arrForm as $key => $val) {
[21514]152            if ($val == '') {
[20391]153                continue;
154            }
155
156            switch ($key) {
[15661]157                case 'search_name':
[21514]158                    $where .= ' AND name ILIKE ?';
159                    $bind[] = '%'.$val.'%';
[15661]160                    break;
161                case 'search_category_id':
[20391]162                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val);
[21514]163                    if ($tmp_where != '') {
164                        $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
[20391]165                        $bind = array_merge((array)$bind, (array)$tmp_bind);
[15661]166                    }
167                    break;
[21793]168                case 'search_product_code':
[21829]169                    $where .=    ' AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)';
[21793]170                    $bind[] = '%'.$val.'%';
171                    break;
[15661]172                default:
173                    break;
174            }
[20391]175        }
176        return array(
177            'where'=>$where,
178            'bind' => $bind
179        );
[20265]180    }
[15661]181
[20288]182    /**
[20391]183     *
184     * 検索結果対象となる商品の数を返す。
185     * @param array $whereAndBind
186     * @param SC_Product $objProduct
[20288]187     */
[22796]188    function getLineCount($whereAndBind,&$objProduct) {
[20391]189        $where = $whereAndBind['where'];
190        $bind = $whereAndBind['bind'];
191        // 検索結果対象となる商品の数を取得
[20507]192        $objQuery =& SC_Query_Ex::getSingletonInstance();
[20391]193        $objQuery->setWhere($where);
194        $linemax = $objProduct->findProductCount($objQuery, $bind);
[21659]195        return $linemax;   // 何件が該当しました。表示用
[20265]196    }
[15661]197
[20288]198    /**
[20391]199     * 検索結果の取得
200     * @param array $whereAndBind string whereと array bindの連想配列
201     * @param SC_Product $objProduct
[20288]202     */
[22796]203    function getProducts($whereAndBind,&$objProduct, $page_max, $startno) {
[20391]204        $where = $whereAndBind['where'];
205        $bind = $whereAndBind['bind'];
[20507]206        $objQuery =& SC_Query_Ex::getSingletonInstance();
[20391]207        $objQuery->setWhere($where);
208        // 取得範囲の指定(開始行番号、行数のセット)
209        $objQuery->setLimitOffset($page_max, $startno);
210        // 検索結果の取得
211        return $objProduct->findProductIdsOrder($objQuery, $bind);
[15661]212    }
213
[20391]214    /**
[21256]215     * 商品取得
[21743]216     *
[21256]217     * @param array $arrProductId
[20391]218     * @param SC_Product $objProduct
219     */
[22796]220    function getProductList($arrProductId, &$objProduct) {
[20507]221        $objQuery =& SC_Query_Ex::getSingletonInstance();
[21256]222
[20412]223        // 表示順序
[21514]224        $order = 'update_date DESC, product_id DESC';
[20412]225        $objQuery->setOrder($order);
[21256]226        return $objProduct->getListByProductIds($objQuery, $arrProductId);
[20391]227    }
[15661]228}
Note: See TracBrowser for help on using the repository browser.