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

Revision 21689, 10.5 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 インスタンスを呼び出す処理を統一

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