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

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