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

Revision 23124, 10.7 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
PHP4的な書き方の修正

  • 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
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, '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()
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     */
171    public function getProducts($whereAndBind,&$objProduct, $page_max, $startno)
172    {
173        $where = $whereAndBind['where'];
174        $bind = $whereAndBind['bind'];
175        $objQuery =& SC_Query_Ex::getSingletonInstance();
176        $objQuery->setWhere($where);
177        // 取得範囲の指定(開始行番号、行数のセット)
178        $objQuery->setLimitOffset($page_max, $startno);
179        // 表示順序
180        $objQuery->setOrder($order);
181
182        // 検索結果の取得
183        return $objProduct->findProductIdsOrder($objQuery, $bind);
184    }
185
186    /**
187     *
188     * 検索結果対象となる商品の数を返す。
189     * @param array      $whereAndBind
190     * @param SC_Product $objProduct
191     */
192    public function getLineCount($whereAndBind,&$objProduct)
193    {
194        $where = $whereAndBind['where'];
195        $bind = $whereAndBind['bind'];
196        // 検索結果対象となる商品の数を取得
197        $objQuery =& SC_Query_Ex::getSingletonInstance();
198        $objQuery->setWhere($where);
199        $linemax = $objProduct->findProductCount($objQuery, $bind);
200
201        return $linemax;   // 何件が該当しました。表示用
202    }
203
204    /**
205     *
206     * POSTされた値からSQLのWHEREとBINDを配列で返す。
207     * @return array        ('where' => where string, 'bind' => databind array)
208     * @param  SC_FormParam $objFormParam
209     */
210    public function createWhere(&$objFormParam,&$objDb)
211    {
212        $arrForm = $objFormParam->getHashArray();
213        $where = 'alldtl.del_flg = 0';
214        $bind = array();
215        foreach ($arrForm as $key => $val) {
216            if ($val == '') {
217                continue;
218            }
219
220            switch ($key) {
221                case 'search_name':
222                    $where .= ' AND name ILIKE ?';
223                    $bind[] = '%'.$val.'%';
224                    break;
225                case 'search_category_id':
226                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val);
227                    if ($tmp_where != '') {
228                        $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
229                        $bind = array_merge((array) $bind, (array) $tmp_bind);
230                    }
231                    break;
232                case 'search_product_code':
233                    $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)';
234                    $bind[] = '%'.$val.'%';
235                    break;
236
237                default:
238                    break;
239            }
240        }
241
242        return array(
243            'where' => $where,
244            'bind'  => $bind,
245        );
246    }
247
248    /**
249     * リクエストパラメーターnoを取ってくる。
250     * @param unknown_type $globalParams
251     */
252    public function getNo($globalParams)
253    {
254        foreach ($globalParams as $params) {
255            if (isset($params['no']) && $params['no']!= '') {
256                return intval($params['no']);
257            }
258        }
259
260        return null;
261    }
262
263    /**
264     * リクエストパラメーター shipping_id を取ってくる。
265     * @param unknown_type $globalParams
266     */
267    public function getShippingId($globalParams)
268    {
269        foreach ($globalParams as $params) {
270            if (isset($params['shipping_id']) && $params['shipping_id']!= '') {
271                return intval($params['shipping_id']);
272            }
273        }
274
275        return null;
276    }
277
278    /**
279     * 取得している並び順で並び替え
280     * @param $arrProduct_id
281     * @param $productList
282     */
283    public function sortProducts($arrProduct_id,$productList)
284    {
285        $products  = array();
286        foreach ($productList as $item) {
287            $products[ $item['product_id'] ] = $item;
288        }
289        $arrProducts = array();
290        foreach ($arrProduct_id as $product_id) {
291            $arrProducts[] = $products[$product_id];
292        }
293
294        return $arrProducts;
295    }
296
297    /**
298     * パラメーター情報の初期化
299     * @param SC_FormParam $objFormParam
300     */
301    public function lfInitParam(&$objFormParam)
302    {
303        $objFormParam->addParam('オーダーID', 'order_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
304        $objFormParam->addParam('商品名', 'search_name', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
305        $objFormParam->addParam('カテゴリID', 'search_category_id', STEXT_LEN, 'KVa',  array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
306        $objFormParam->addParam('商品コード', 'search_product_code', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
307        $objFormParam->addParam('フッター', 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
308        $objFormParam->addParam('届け先ID', 'shipping_id', LTEXT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
309    }
310}
Note: See TracBrowser for help on using the repository browser.