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

Revision 21693, 7.7 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

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