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

Revision 21250, 7.8 KB checked in by nanasess, 13 years ago (diff)

#954 (管理画面の小画面にサブタイトルが出るものと出ないものがある)

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