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

Revision 22502, 10.1 KB checked in by kim, 11 years ago (diff)

#2084 ID振り直し SC_Utils系
#2084 ID振り直し 重複テキストの調整

  • 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-2012 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 = t('c_Orders_01');
50        $this->tpl_subtitle = t('c_Product selection_01');
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        $objDb = new SC_Helper_DB_Ex();
74        $objFormParam = new SC_FormParam_Ex();
75        $this->lfInitParam($objFormParam);
76        $objFormParam->setParam($_POST);
77        $objFormParam->convParam();
78
79        $this->tpl_no = $this->getNo(array($_GET,$_POST));
80
81        switch ($this->getMode()) {
82            case 'search':
83                $objProduct = new SC_Product_Ex();
84                $this->arrForm = $objFormParam->getHashArray();
85                $wheres = $this->createWhere($objFormParam,$objDb);
86                $this->tpl_linemax = $this->getLineCount($wheres,$objProduct);
87
88                //ぶった斬りポイント==================================================================
89                // ページ送りの処理
90                $page_max = SC_Utils_Ex::sfGetSearchPageMax($_POST['search_page_max']);
91
92                // ページ送りの取得
93                $objNavi = new SC_PageNavi_Ex($_POST['search_pageno'], $this->tpl_linemax, $page_max, 'fnNaviSearchOnlyPage', NAVI_PMAX);
94                $this->tpl_strnavi = $objNavi->strnavi;     // 表示文字列
95                $startno = $objNavi->start_row;
96                $arrProduct_id = $this->getProducts($wheres, $objProduct, $page_max, $startno);
97                $productList = $this->getProductList($arrProduct_id,$objProduct);
98                //取得している並び順で並び替え
99                $this->arrProducts = $this->sortProducts($arrProduct_id,$productList);
100                $objProduct->setProductsClassByProductIds($arrProduct_id);
101                $this->tpl_javascript .= $this->getTplJavascript($objProduct);
102                $js_fnOnLoad = $this->getFnOnload($this->arrProducts);
103                $this->tpl_javascript .= 'function fnOnLoad(){' . $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     *
131     * @param array $arrProductId
132     * @param SC_Product $objProduct
133     */
134    function getProductList($arrProductId, &$objProduct) {
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    function getFnOnload($arrProducts) {
149        foreach ($arrProducts as $arrProduct) {
150            $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});";
151        }
152        return $js_fnOnLoad;
153    }
154
155    /**
156     * 規格クラス用JavaScript生成
157     * @param SC_Product $objProduct
158     */
159    function getTplJavascript(&$objProduct) {
160        return 'productsClassCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories) . '; ';
161    }
162
163    /**
164     * 検索結果の取得
165     * @param array $whereAndBind string whereと array bindの連想配列
166     * @param SC_Product $objProduct
167     */
168    function getProducts($whereAndBind,&$objProduct, $page_max, $startno) {
169        $where = $whereAndBind['where'];
170        $bind = $whereAndBind['bind'];
171        $objQuery =& SC_Query_Ex::getSingletonInstance();
172        $objQuery->setWhere($where);
173        // 取得範囲の指定(開始行番号、行数のセット)
174        $objQuery->setLimitOffset($page_max, $startno);
175        // 表示順序
176        $objQuery->setOrder($order);
177
178        // 検索結果の取得
179        return $objProduct->findProductIdsOrder($objQuery, $bind);
180    }
181
182    /**
183     *
184     * 検索結果対象となる商品の数を返す。
185     * @param array $whereAndBind
186     * @param SC_Product $objProduct
187     */
188    function getLineCount($whereAndBind,&$objProduct) {
189        $where = $whereAndBind['where'];
190        $bind = $whereAndBind['bind'];
191        // 検索結果対象となる商品の数を取得
192        $objQuery =& SC_Query_Ex::getSingletonInstance();
193        $objQuery->setWhere($where);
194        $linemax = $objProduct->findProductCount($objQuery, $bind);
195        return $linemax;   // 何件が該当しました。表示用
196    }
197
198    /**
199     *
200     * POSTされた値からSQLのWHEREとBINDを配列で返す。
201     * @return array ('where' => where string, 'bind' => databind array)
202     * @param SC_FormParam $objFormParam
203     */
204    function createWhere(&$objFormParam,&$objDb) {
205        $arrForm = $objFormParam->getHashArray();
206        $where = 'alldtl.del_flg = 0';
207        $bind = array();
208        foreach ($arrForm as $key => $val) {
209            if ($val == '') {
210                continue;
211            }
212
213            switch ($key) {
214                case 'search_name':
215                    $where .= ' AND name ILIKE ?';
216                    $bind[] = '%'.$val.'%';
217                    break;
218                case 'search_category_id':
219                    list($tmp_where, $tmp_bind) = $objDb->sfGetCatWhere($val);
220                    if ($tmp_where != '') {
221                        $where.= ' AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
222                        $bind = array_merge((array)$bind, (array)$tmp_bind);
223                    }
224                    break;
225                case 'search_product_code':
226                    $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)';
227                    $bind[] = '%'.$val.'%';
228                    break;
229
230                default:
231                    break;
232            }
233        }
234        return array(
235            'where' => $where,
236            'bind'  => $bind,
237        );
238    }
239
240    /**
241     * リクエストパラメーターnoを取ってくる。
242     * @param unknown_type $globalParams
243     */
244    function getNo($globalParams) {
245        foreach ($globalParams as $params) {
246            if (isset($params['no']) && $params['no']!= '') {
247                return intval($params['no']);
248            }
249        }
250        return null;
251    }
252
253    /**
254     * 取得している並び順で並び替え
255     * @param $arrProduct_id
256     * @param $productList
257     */
258    function sortProducts($arrProduct_id,$productList) {
259        $products  = array();
260        foreach ($productList as $item) {
261            $products[ $item['product_id'] ] = $item;
262        }
263        $arrProducts = array();
264        foreach ($arrProduct_id as $product_id) {
265            $arrProducts[] = $products[$product_id];
266        }
267        return $arrProducts;
268    }
269
270    /**
271     * デストラクタ.
272     * @return void
273     */
274    function destroy() {
275        parent::destroy();
276    }
277
278    /**
279     * パラメーター情報の初期化
280     * @param SC_FormParam $objFormParam
281     */
282    function lfInitParam(&$objFormParam) {
283        $objFormParam->addParam(t('c_Order ID_01'), 'order_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
284        $objFormParam->addParam(t('c_Product name_01'), 'search_name', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
285        $objFormParam->addParam(t('c_Category ID_01'), 'search_category_id', STEXT_LEN, 'KVa',  array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
286        $objFormParam->addParam(t('c_Product code_01'), 'search_product_code', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
287        $objFormParam->addParam(t('c_Footer_01'), 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
288    }
289}
Note: See TracBrowser for help on using the repository browser.