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 |
---|
25 | require_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 | */ |
---|
34 | class LC_Page_Admin_Order_ProductSelect 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_mainpage = 'order/product_select.tpl'; |
---|
47 | $this->tpl_mainno = 'order'; |
---|
48 | $this->tpl_subno = ''; |
---|
49 | $this->tpl_maintitle = '受注管理'; |
---|
50 | $this->tpl_subtitle = '商品選択'; |
---|
51 | |
---|
52 | $masterData = new SC_DB_MasterData_Ex(); |
---|
53 | $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData('mtb_product_status_color'); |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * Page のプロセス. |
---|
58 | * |
---|
59 | * @return void |
---|
60 | */ |
---|
61 | function process() { |
---|
62 | $this->action(); |
---|
63 | $this->sendResponse(); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Page のアクション. |
---|
68 | * |
---|
69 | * @return void |
---|
70 | */ |
---|
71 | function action() { |
---|
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 | $this->tpl_no = $this->getNo(array($_GET,$_POST)); |
---|
79 | |
---|
80 | switch ($this->getMode()) { |
---|
81 | case 'search': |
---|
82 | $objProduct = new SC_Product_Ex(); |
---|
83 | $this->arrForm = $objFormParam->getHashArray(); |
---|
84 | $wheres = $this->createWhere($objFormParam,$objDb); |
---|
85 | $this->tpl_linemax = $this->getLineCount($wheres,$objProduct); |
---|
86 | |
---|
87 | //ぶった斬りポイント================================================================== |
---|
88 | // ページ送りの処理 |
---|
89 | $page_max = SC_Utils_Ex::sfGetSearchPageMax($_POST['search_page_max']); |
---|
90 | |
---|
91 | // ページ送りの取得 |
---|
92 | $objNavi = new SC_PageNavi_Ex($_POST['search_pageno'], $this->tpl_linemax, $page_max, 'fnNaviSearchOnlyPage', NAVI_PMAX); |
---|
93 | $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列 |
---|
94 | $startno = $objNavi->start_row; |
---|
95 | $arrProduct_id = $this->getProducts($wheres, $objProduct, $page_max, $startno); |
---|
96 | $productList = $this->getProductList($arrProduct_id,$objProduct); |
---|
97 | //取得している並び順で並び替え |
---|
98 | $this->arrProducts = $this->sortProducts($arrProduct_id,$productList); |
---|
99 | $objProduct->setProductsClassByProductIds($arrProduct_id); |
---|
100 | $this->tpl_javascript .= $this->getTplJavascript($objProduct); |
---|
101 | $js_fnOnLoad = $this->getFnOnload($this->arrProducts); |
---|
102 | $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}'; |
---|
103 | $this->tpl_onload .= 'fnOnLoad();'; |
---|
104 | // 規格1クラス名 |
---|
105 | $this->tpl_class_name1 = $objProduct->className1; |
---|
106 | // 規格2クラス名 |
---|
107 | $this->tpl_class_name2 = $objProduct->className2; |
---|
108 | // 規格1 |
---|
109 | $this->arrClassCat1 = $objProduct->classCats1; |
---|
110 | // 規格1が設定されている |
---|
111 | $this->tpl_classcat_find1 = $objProduct->classCat1_find; |
---|
112 | // 規格2が設定されている |
---|
113 | $this->tpl_classcat_find2 = $objProduct->classCat2_find; |
---|
114 | $this->tpl_product_class_id = $objProduct->product_class_id; |
---|
115 | $this->tpl_stock_find = $objProduct->stock_find; |
---|
116 | break; |
---|
117 | default: |
---|
118 | break; |
---|
119 | } |
---|
120 | |
---|
121 | // カテゴリ取得 |
---|
122 | $this->arrCatList = $objDb->sfGetCategoryList(); |
---|
123 | $this->setTemplate($this->tpl_mainpage); |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * 商品取得 |
---|
128 | * |
---|
129 | * @param array $arrProductId |
---|
130 | * @param SC_Product $objProduct |
---|
131 | */ |
---|
132 | function getProductList($arrProductId, &$objProduct) { |
---|
133 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
134 | |
---|
135 | // 表示順序 |
---|
136 | $order = 'update_date DESC, product_id DESC'; |
---|
137 | $objQuery->setOrder($order); |
---|
138 | |
---|
139 | return $objProduct->getListByProductIds($objQuery, $arrProductId); |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * ロード時に実行するJavascriptを生成 |
---|
144 | * @param array $arrProducts |
---|
145 | */ |
---|
146 | function getFnOnload($arrProducts) { |
---|
147 | foreach ($arrProducts as $arrProduct) { |
---|
148 | $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});"; |
---|
149 | } |
---|
150 | return $js_fnOnLoad; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * 規格クラス用JavaScript生成 |
---|
155 | * @param SC_Product $objProduct |
---|
156 | */ |
---|
157 | function getTplJavascript(&$objProduct) { |
---|
158 | return 'productsClassCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories) . '; '; |
---|
159 | } |
---|
160 | |
---|
161 | /** |
---|
162 | * 検索結果の取得 |
---|
163 | * @param array $whereAndBind string whereと array bindの連想配列 |
---|
164 | * @param SC_Product $objProduct |
---|
165 | */ |
---|
166 | function getProducts($whereAndBind,&$objProduct, $page_max, $startno) { |
---|
167 | $where = $whereAndBind['where']; |
---|
168 | $bind = $whereAndBind['bind']; |
---|
169 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
170 | $objQuery->setWhere($where); |
---|
171 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
172 | $objQuery->setLimitOffset($page_max, $startno); |
---|
173 | // 表示順序 |
---|
174 | $objQuery->setOrder($order); |
---|
175 | |
---|
176 | // 検索結果の取得 |
---|
177 | return $objProduct->findProductIdsOrder($objQuery, $bind); |
---|
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_Ex::getSingletonInstance(); |
---|
191 | $objQuery->setWhere($where); |
---|
192 | $linemax = $objProduct->findProductCount($objQuery, $bind); |
---|
193 | return $linemax; // 何件が該当しました。表示用 |
---|
194 | } |
---|
195 | |
---|
196 | /** |
---|
197 | * |
---|
198 | * POSTされた値からSQLのWHEREとBINDを配列で返す。 |
---|
199 | * @return array ('where' => where string, 'bind' => databind array) |
---|
200 | * @param SC_FormParam $objFormParam |
---|
201 | */ |
---|
202 | function createWhere(&$objFormParam,&$objDb) { |
---|
203 | $arrForm = $objFormParam->getHashArray(); |
---|
204 | $where = 'alldtl.del_flg = 0'; |
---|
205 | $bind = array(); |
---|
206 | foreach ($arrForm as $key => $val) { |
---|
207 | if ($val == '') { |
---|
208 | continue; |
---|
209 | } |
---|
210 | |
---|
211 | switch ($key) { |
---|
212 | case 'search_name': |
---|
213 | $where .= ' AND name ILIKE ?'; |
---|
214 | $bind[] = '%'.$val.'%'; |
---|
215 | break; |
---|
216 | case 'search_category_id': |
---|
217 | list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val); |
---|
218 | if ($tmp_where != '') { |
---|
219 | $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; |
---|
220 | $bind = array_merge((array)$bind, (array)$tmp_bind); |
---|
221 | } |
---|
222 | break; |
---|
223 | case 'search_product_code': |
---|
224 | $where .= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? AND del_flg = 0 GROUP BY product_id)'; |
---|
225 | $bind[] = '%'.$val.'%'; |
---|
226 | break; |
---|
227 | |
---|
228 | default: |
---|
229 | break; |
---|
230 | } |
---|
231 | } |
---|
232 | return array( |
---|
233 | 'where' => $where, |
---|
234 | 'bind' => $bind, |
---|
235 | ); |
---|
236 | } |
---|
237 | |
---|
238 | /** |
---|
239 | * リクエストパラメーターnoを取ってくる。 |
---|
240 | * @param unknown_type $globalParams |
---|
241 | */ |
---|
242 | function getNo($globalParams) { |
---|
243 | foreach ($globalParams as $params) { |
---|
244 | if (isset($params['no']) && $params['no']!= '') { |
---|
245 | return intval($params['no']); |
---|
246 | } |
---|
247 | } |
---|
248 | return null; |
---|
249 | } |
---|
250 | |
---|
251 | /** |
---|
252 | * 取得している並び順で並び替え |
---|
253 | * @param $arrProduct_id |
---|
254 | * @param $productList |
---|
255 | */ |
---|
256 | function sortProducts($arrProduct_id,$productList) { |
---|
257 | $products = array(); |
---|
258 | foreach ($productList as $item) { |
---|
259 | $products[ $item['product_id'] ] = $item; |
---|
260 | } |
---|
261 | $arrProducts = array(); |
---|
262 | foreach ($arrProduct_id as $product_id) { |
---|
263 | $arrProducts[] = $products[$product_id]; |
---|
264 | } |
---|
265 | return $arrProducts; |
---|
266 | } |
---|
267 | |
---|
268 | /** |
---|
269 | * デストラクタ. |
---|
270 | * @return void |
---|
271 | */ |
---|
272 | function destroy() { |
---|
273 | parent::destroy(); |
---|
274 | } |
---|
275 | |
---|
276 | /** |
---|
277 | * パラメーター情報の初期化 |
---|
278 | * @param SC_FormParam $objFormParam |
---|
279 | */ |
---|
280 | function lfInitParam(&$objFormParam) { |
---|
281 | $objFormParam->addParam('オーダーID', 'order_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
282 | $objFormParam->addParam('商品名', 'search_name', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK')); |
---|
283 | $objFormParam->addParam('カテゴリID', 'search_category_id', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK')); |
---|
284 | $objFormParam->addParam('商品コード', 'search_product_code', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK')); |
---|
285 | $objFormParam->addParam('フッター', 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK')); |
---|
286 | } |
---|
287 | } |
---|