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 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
25 | |
---|
26 | /** |
---|
27 | * おすすめ商品管理 商品検索のページクラス. |
---|
28 | * |
---|
29 | * @package Page |
---|
30 | * @author LOCKON CO.,LTD. |
---|
31 | * @version $Id$ |
---|
32 | */ |
---|
33 | class LC_Page_Admin_Contents_RecommendSearch extends LC_Page_Admin_Ex |
---|
34 | { |
---|
35 | /** |
---|
36 | * Page を初期化する. |
---|
37 | * |
---|
38 | * @return void |
---|
39 | */ |
---|
40 | function init() |
---|
41 | { |
---|
42 | parent::init(); |
---|
43 | $this->tpl_mainno = 'contents'; |
---|
44 | $this->tpl_subno = ''; |
---|
45 | |
---|
46 | $this->tpl_subtitle = '商品検索'; |
---|
47 | } |
---|
48 | |
---|
49 | /** |
---|
50 | * Page のプロセス. |
---|
51 | * |
---|
52 | * @return void |
---|
53 | */ |
---|
54 | function process() |
---|
55 | { |
---|
56 | $this->action(); |
---|
57 | $this->sendResponse(); |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * Page のアクション. |
---|
62 | * |
---|
63 | * @return void |
---|
64 | */ |
---|
65 | function action() |
---|
66 | { |
---|
67 | $objDb = new SC_Helper_DB_Ex(); |
---|
68 | $objFormParam = new SC_FormParam_Ex(); |
---|
69 | $this->lfInitParam($objFormParam); |
---|
70 | $objFormParam->setParam($_POST); |
---|
71 | $objFormParam->convParam(); |
---|
72 | |
---|
73 | $rank = intval($_GET['rank']); |
---|
74 | |
---|
75 | switch ($this->getMode()) { |
---|
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(); |
---|
84 | |
---|
85 | $wheres = $this->createWhere($objFormParam,$objDb); |
---|
86 | $this->tpl_linemax = $this->getLineCount($wheres,$objProduct); |
---|
87 | |
---|
88 | $page_max = SC_Utils_Ex::sfGetSearchPageMax($arrPost['search_page_max']); |
---|
89 | |
---|
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; |
---|
94 | |
---|
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; |
---|
102 | } |
---|
103 | |
---|
104 | // カテゴリ取得 |
---|
105 | $this->arrCatList = $objDb->sfGetCategoryList(); |
---|
106 | $this->rank = $rank; |
---|
107 | $this->setTemplate('contents/recommend_search.tpl'); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * デストラクタ. |
---|
112 | * |
---|
113 | * @return void |
---|
114 | */ |
---|
115 | function destroy() |
---|
116 | { |
---|
117 | parent::destroy(); |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * パラメーターの初期化を行う |
---|
122 | * @param Object $objFormParam |
---|
123 | */ |
---|
124 | function lfInitParam(&$objFormParam) |
---|
125 | { |
---|
126 | $objFormParam->addParam('商品ID', 'search_name', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK')); |
---|
127 | $objFormParam->addParam('商品ID', 'search_category_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK','NUM_CHECK')); |
---|
128 | $objFormParam->addParam('商品コード', 'search_product_code', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK')); |
---|
129 | $objFormParam->addParam('商品ステータス', 'search_status', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
130 | $objFormParam->addParam('ページ番号', 'search_pageno', INT_LEN, 'n', array('MAX_LENGTH_CHECK','NUM_CHECK')); |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * 入力されたパラメーターのエラーチェックを行う。 |
---|
135 | * @param Object $objFormParam |
---|
136 | * @return Array エラー内容 |
---|
137 | */ |
---|
138 | function lfCheckError(&$objFormParam) |
---|
139 | { |
---|
140 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
141 | $objErr->arrErr = $objFormParam->checkError(); |
---|
142 | |
---|
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 | { |
---|
154 | $arrForm = $objFormParam->getHashArray(); |
---|
155 | $where = 'alldtl.del_flg = 0'; |
---|
156 | $bind = array(); |
---|
157 | foreach ($arrForm as $key => $val) { |
---|
158 | if ($val == '') { |
---|
159 | continue; |
---|
160 | } |
---|
161 | |
---|
162 | switch ($key) { |
---|
163 | case 'search_name': |
---|
164 | $where .= ' AND name ILIKE ?'; |
---|
165 | $bind[] = '%'.$val.'%'; |
---|
166 | break; |
---|
167 | case 'search_category_id': |
---|
168 | list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val); |
---|
169 | if ($tmp_where != '') { |
---|
170 | $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; |
---|
171 | $bind = array_merge((array)$bind, (array)$tmp_bind); |
---|
172 | } |
---|
173 | break; |
---|
174 | case 'search_product_code': |
---|
175 | $where .= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)'; |
---|
176 | $bind[] = '%'.$val.'%'; |
---|
177 | break; |
---|
178 | case 'search_status': |
---|
179 | $where .= ' AND alldtl.status = ?'; |
---|
180 | $bind[] = $val; |
---|
181 | break; |
---|
182 | default: |
---|
183 | break; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | return array( |
---|
188 | 'where'=>$where, |
---|
189 | 'bind' => $bind |
---|
190 | ); |
---|
191 | } |
---|
192 | |
---|
193 | /** |
---|
194 | * |
---|
195 | * 検索結果対象となる商品の数を返す。 |
---|
196 | * @param array $whereAndBind |
---|
197 | * @param SC_Product $objProduct |
---|
198 | */ |
---|
199 | function getLineCount($whereAndBind,&$objProduct) |
---|
200 | { |
---|
201 | $where = $whereAndBind['where']; |
---|
202 | $bind = $whereAndBind['bind']; |
---|
203 | // 検索結果対象となる商品の数を取得 |
---|
204 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
205 | $objQuery->setWhere($where); |
---|
206 | $linemax = $objProduct->findProductCount($objQuery, $bind); |
---|
207 | |
---|
208 | return $linemax; // 何件が該当しました。表示用 |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * 検索結果の取得 |
---|
213 | * @param array $whereAndBind string whereと array bindの連想配列 |
---|
214 | * @param SC_Product $objProduct |
---|
215 | */ |
---|
216 | function getProducts($whereAndBind,&$objProduct, $page_max, $startno) |
---|
217 | { |
---|
218 | $where = $whereAndBind['where']; |
---|
219 | $bind = $whereAndBind['bind']; |
---|
220 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
221 | $objQuery->setWhere($where); |
---|
222 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
223 | $objQuery->setLimitOffset($page_max, $startno); |
---|
224 | // 検索結果の取得 |
---|
225 | return $objProduct->findProductIdsOrder($objQuery, $bind); |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | * 商品取得 |
---|
230 | * |
---|
231 | * @param array $arrProductId |
---|
232 | * @param SC_Product $objProduct |
---|
233 | */ |
---|
234 | function getProductList($arrProductId, &$objProduct) |
---|
235 | { |
---|
236 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
237 | |
---|
238 | // 表示順序 |
---|
239 | $order = 'update_date DESC, product_id DESC'; |
---|
240 | $objQuery->setOrder($order); |
---|
241 | |
---|
242 | return $objProduct->getListByProductIds($objQuery, $arrProductId); |
---|
243 | } |
---|
244 | } |
---|