source: branches/version-2_13-dev/data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php @ 23605

Revision 23605, 10.7 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • 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-2014 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
24require_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 */
33class LC_Page_Admin_Order_ProductSelect extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'order/product_select.tpl';
44        $this->tpl_mainno = 'order';
45        $this->tpl_subno = '';
46        $this->tpl_maintitle = '受注管理';
47        $this->tpl_subtitle = '商品選択';
48
49        $masterData = new SC_DB_MasterData_Ex();
50        $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData('mtb_product_status_color');
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    public function process()
59    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    public function action()
70    {
71        $objDb = new SC_Helper_DB_Ex();
72        $objFormParam = new SC_FormParam_Ex();
73        $this->lfInitParam($objFormParam);
74        $objFormParam->setParam($_POST);
75        $objFormParam->convParam();
76
77        $this->tpl_no = $this->getNo(array($_GET, $_POST));
78        $this->shipping_id = $this->getShippingId(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, 'eccube.moveSearchPage', 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()
103                {' . $js_fnOnLoad . '}';
104                $this->tpl_onload .= 'fnOnLoad();';
105                // 規格1クラス名
106                $this->tpl_class_name1 = $objProduct->className1;
107                // 規格2クラス名
108                $this->tpl_class_name2 = $objProduct->className2;
109                // 規格1
110                $this->arrClassCat1 = $objProduct->classCats1;
111                // 規格1が設定されている
112                $this->tpl_classcat_find1 = $objProduct->classCat1_find;
113                // 規格2が設定されている
114                $this->tpl_classcat_find2 = $objProduct->classCat2_find;
115                $this->tpl_product_class_id = $objProduct->product_class_id;
116                $this->tpl_stock_find = $objProduct->stock_find;
117                break;
118            default:
119                break;
120        }
121
122        // カテゴリ取得
123        $this->arrCatList = $objDb->sfGetCategoryList();
124        $this->setTemplate($this->tpl_mainpage);
125    }
126
127    /**
128     * 商品取得
129     *
130     * @param array      $arrProductId
131     * @param SC_Product $objProduct
132     */
133    public function getProductList($arrProductId, &$objProduct)
134    {
135        $objQuery =& SC_Query_Ex::getSingletonInstance();
136
137        // 表示順序
138        $order = 'update_date DESC, product_id DESC';
139        $objQuery->setOrder($order);
140
141        return $objProduct->getListByProductIds($objQuery, $arrProductId);
142    }
143
144    /**
145     * ロード時に実行するJavascriptを生成
146     * @param array $arrProducts
147     */
148    public function getFnOnload($arrProducts)
149    {
150        foreach ($arrProducts as $arrProduct) {
151            $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});";
152        }
153
154        return $js_fnOnLoad;
155    }
156
157    /**
158     * 規格クラス用JavaScript生成
159     * @param SC_Product $objProduct
160     */
161    public function getTplJavascript(&$objProduct)
162    {
163        return 'eccube.productsClassCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories) . '; ';
164    }
165
166    /**
167     * 検索結果の取得
168     * @param array      $whereAndBind string whereと array bindの連想配列
169     * @param SC_Product $objProduct
170     * @param integer $page_max
171     */
172    public function getProducts($whereAndBind, &$objProduct, $page_max, $startno)
173    {
174        $where = $whereAndBind['where'];
175        $bind = $whereAndBind['bind'];
176        $objQuery =& SC_Query_Ex::getSingletonInstance();
177        $objQuery->setWhere($where);
178        // 取得範囲の指定(開始行番号、行数のセット)
179        $objQuery->setLimitOffset($page_max, $startno);
180        // 表示順序
181        $objQuery->setOrder($order);
182
183        // 検索結果の取得
184        return $objProduct->findProductIdsOrder($objQuery, $bind);
185    }
186
187    /**
188     *
189     * 検索結果対象となる商品の数を返す。
190     * @param array      $whereAndBind
191     * @param SC_Product $objProduct
192     */
193    public function getLineCount($whereAndBind, &$objProduct)
194    {
195        $where = $whereAndBind['where'];
196        $bind = $whereAndBind['bind'];
197        // 検索結果対象となる商品の数を取得
198        $objQuery =& SC_Query_Ex::getSingletonInstance();
199        $objQuery->setWhere($where);
200        $linemax = $objProduct->findProductCount($objQuery, $bind);
201
202        return $linemax;   // 何件が該当しました。表示用
203    }
204
205    /**
206     *
207     * POSTされた値からSQLのWHEREとBINDを配列で返す。
208     * @return array        ('where' => where string, 'bind' => databind array)
209     * @param  SC_FormParam $objFormParam
210     * @param SC_Helper_DB_Ex $objDb
211     */
212    public function createWhere(&$objFormParam, &$objDb)
213    {
214        $arrForm = $objFormParam->getHashArray();
215        $where = 'alldtl.del_flg = 0';
216        $bind = array();
217        foreach ($arrForm as $key => $val) {
218            if ($val == '') {
219                continue;
220            }
221
222            switch ($key) {
223                case 'search_name':
224                    $where .= ' AND name ILIKE ?';
225                    $bind[] = '%'.$val.'%';
226                    break;
227                case 'search_category_id':
228                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val);
229                    if ($tmp_where != '') {
230                        $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
231                        $bind = array_merge((array) $bind, (array) $tmp_bind);
232                    }
233                    break;
234                case 'search_product_code':
235                    $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)';
236                    $bind[] = '%'.$val.'%';
237                    break;
238
239                default:
240                    break;
241            }
242        }
243
244        return array(
245            'where' => $where,
246            'bind'  => $bind,
247        );
248    }
249
250    /**
251     * リクエストパラメーターnoを取ってくる。
252     * @param unknown_type $globalParams
253     */
254    public function getNo($globalParams)
255    {
256        foreach ($globalParams as $params) {
257            if (isset($params['no']) && $params['no']!= '') {
258                return intval($params['no']);
259            }
260        }
261
262        return null;
263    }
264
265    /**
266     * リクエストパラメーター shipping_id を取ってくる。
267     * @param unknown_type $globalParams
268     */
269    public function getShippingId($globalParams)
270    {
271        foreach ($globalParams as $params) {
272            if (isset($params['shipping_id']) && $params['shipping_id']!= '') {
273                return intval($params['shipping_id']);
274            }
275        }
276
277        return null;
278    }
279
280    /**
281     * 取得している並び順で並び替え
282     * @param $arrProduct_id
283     * @param $productList
284     */
285    public function sortProducts($arrProduct_id, $productList)
286    {
287        $products  = array();
288        foreach ($productList as $item) {
289            $products[ $item['product_id'] ] = $item;
290        }
291        $arrProducts = array();
292        foreach ($arrProduct_id as $product_id) {
293            $arrProducts[] = $products[$product_id];
294        }
295
296        return $arrProducts;
297    }
298
299    /**
300     * パラメーター情報の初期化
301     * @param SC_FormParam $objFormParam
302     */
303    public function lfInitParam(&$objFormParam)
304    {
305        $objFormParam->addParam('オーダーID', 'order_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
306        $objFormParam->addParam('商品名', 'search_name', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
307        $objFormParam->addParam('カテゴリID', 'search_category_id', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
308        $objFormParam->addParam('商品コード', 'search_product_code', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
309        $objFormParam->addParam('フッター', 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
310        $objFormParam->addParam('届け先ID', 'shipping_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
311    }
312}
Note: See TracBrowser for help on using the repository browser.