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

Revision 20501, 7.8 KB checked in by shutta, 13 years ago (diff)

SC_FormParamクラスのclass_extends対応

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