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

Revision 22567, 8.0 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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