source: branches/version-2_12-dev/data/class/pages/admin/products/LC_Page_Admin_Products.php @ 21514

Revision 21514, 16.1 KB checked in by Seasoft, 12 years ago (diff)

#1625 (typo修正・ソース整形・ソースコメントの改善)

  • 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_Products 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 = 'products/index.tpl';
47        $this->tpl_mainno = 'products';
48        $this->tpl_subno = 'index';
49        $this->tpl_pager = 'pager.tpl';
50        $this->tpl_maintitle = '商品管理';
51        $this->tpl_subtitle = '商品マスター';
52
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrPageMax = $masterData->getMasterData('mtb_page_max');
55        $this->arrDISP = $masterData->getMasterData('mtb_disp');
56        $this->arrSTATUS = $masterData->getMasterData('mtb_status');
57        $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData('mtb_product_status_color');
58
59        $objDate = new SC_Date();
60        // 登録・更新検索開始年
61        $objDate->setStartYear(RELEASE_YEAR);
62        $objDate->setEndYear(DATE('Y'));
63        $this->arrStartYear = $objDate->getYear();
64        $this->arrStartMonth = $objDate->getMonth();
65        $this->arrStartDay = $objDate->getDay();
66        // 登録・更新検索終了年
67        $objDate->setStartYear(RELEASE_YEAR);
68        $objDate->setEndYear(DATE('Y'));
69        $this->arrEndYear = $objDate->getYear();
70        $this->arrEndMonth = $objDate->getMonth();
71        $this->arrEndDay = $objDate->getDay();
72
73    }
74
75    /**
76     * Page のプロセス.
77     *
78     * @return void
79     */
80    function process() {
81        $this->action();
82        $this->sendResponse();
83    }
84
85    /**
86     * Page のアクション.
87     *
88     * @return void
89     */
90    function action() {
91        $objDb = new SC_Helper_DB_Ex();
92        $objFormParam = new SC_FormParam_Ex();
93        $objProduct = new SC_Product_Ex();
94        $objQuery =& SC_Query_Ex::getSingletonInstance();
95
96        // パラメーター情報の初期化
97        $this->lfInitParam($objFormParam);
98        $objFormParam->setParam($_POST);
99        $this->arrHidden = $objFormParam->getSearchArray();
100        $this->arrForm = $objFormParam->getFormParamList();
101
102        switch ($this->getMode()) {
103        case 'delete':
104            // 商品、子テーブル(商品規格)、会員お気に入り商品の削除
105            $this->doDelete('product_id = ?', array($objFormParam->getValue('product_id')));
106            // 件数カウントバッチ実行
107            $objDb->sfCountCategory($objQuery);
108            $objDb->sfCountMaker($objQuery);
109            // 削除後に検索結果を表示するため breakしない
110
111        // 検索パラメーター生成後に処理実行するため breakしない
112        case 'csv':
113        case 'delete_all':
114
115        case 'search':
116            $objFormParam->convParam();
117            $objFormParam->trimParam();
118            $this->arrErr = $this->lfCheckError($objFormParam);
119            $arrParam = $objFormParam->getHashArray();
120
121            if (count($this->arrErr) == 0) {
122                $where = 'del_flg = 0';
123                foreach ($arrParam as $key => $val) {
124                    if ($val == '') {
125                        continue;
126                    }
127                    $this->buildQuery($key, $where, $arrval, $objFormParam, $objDb);
128                }
129
130                $order = 'update_date DESC';
131
132                /* -----------------------------------------------
133                 * 処理を実行
134                 * ----------------------------------------------- */
135                switch ($this->getMode()) {
136                    // CSVを送信する。
137                    case 'csv':
138                        $objCSV = new SC_Helper_CSV_Ex();
139                        // CSVを送信する。正常終了の場合、終了。
140                        $objCSV->sfDownloadCsv(1, $where, $arrval, $order, true);
141                        exit;
142
143                    // 全件削除(ADMIN_MODE)
144                    case 'delete_all':
145                        $this->doDelete($where, $arrval);
146                        break;
147
148                    // 検索実行
149                    default:
150                        // 行数の取得
151                        $this->tpl_linemax = $this->getNumberOfLines($where, $arrval);
152                        // ページ送りの処理
153                        $page_max = SC_Utils_Ex::sfGetSearchPageMax($objFormParam->getValue('search_page_max'));
154                        // ページ送りの取得
155                        $objNavi = new SC_PageNavi_Ex($this->arrHidden['search_pageno'],
156                                                   $this->tpl_linemax, $page_max,
157                                                   'fnNaviSearchPage', NAVI_PMAX);
158                        $this->arrPagenavi = $objNavi->arrPagenavi;
159
160                        // 検索結果の取得
161                        $this->arrProducts = $this->findProducts($where, $arrval,
162                                                              $page_max, $objNavi->start_row, $order, $objProduct);
163
164                        // 各商品ごとのカテゴリIDを取得
165                        if (count($this->arrProducts) > 0) {
166                            foreach ($this->arrProducts as $key => $val) {
167                                $this->arrProducts[$key]['categories'] = $objDb->sfGetCategoryId($val['product_id'], 0, true);
168                                $objDb->g_category_on = false;
169                            }
170                        }
171                }
172            }
173            break;
174        }
175
176        // カテゴリの読込
177        list($this->arrCatKey, $this->arrCatVal) = $objDb->sfGetLevelCatList(false);
178        $this->arrCatList = $this->lfGetIDName($this->arrCatKey, $this->arrCatVal);
179    }
180
181    /**
182     * デストラクタ.
183     *
184     * @return void
185     */
186    function destroy() {
187        parent::destroy();
188    }
189
190    /**
191     * パラメーター情報の初期化を行う.
192     *
193     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
194     * @return void
195     */
196    function lfInitParam(&$objFormParam) {
197
198        // POSTされる値
199        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
200        $objFormParam->addParam('カテゴリID', 'category_id', STEXT_LEN, 'n', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
201        $objFormParam->addParam('ページ送り番号','search_pageno', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
202        $objFormParam->addParam('表示件数', 'search_page_max', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
203
204        // 検索条件
205        $objFormParam->addParam('商品ID', 'search_product_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
206        $objFormParam->addParam('商品コード', 'search_product_code', STEXT_LEN, 'KVna', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
207        $objFormParam->addParam('商品名', 'search_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
208        $objFormParam->addParam('カテゴリ', 'search_category_id', STEXT_LEN, 'n', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
209        $objFormParam->addParam('種別', 'search_status', INT_LEN, 'n', array('MAX_LENGTH_CHECK'));
210        // 登録・更新日
211        $objFormParam->addParam('開始年', 'search_startyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
212        $objFormParam->addParam('開始月', 'search_startmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
213        $objFormParam->addParam('開始日', 'search_startday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
214        $objFormParam->addParam('終了年', 'search_endyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
215        $objFormParam->addParam('終了月', 'search_endmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
216        $objFormParam->addParam('終了日', 'search_endday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
217
218        $objFormParam->addParam('商品ステータス', 'search_product_statuses', INT_LEN, 'n', array('MAX_LENGTH_CHECK'));
219    }
220
221    /**
222     * 入力内容のチェックを行う.
223     *
224     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
225     * @return void
226     */
227    function lfCheckError(&$objFormParam) {
228        $objErr = new SC_CheckError_Ex($objFormParam->getHashArray());
229        $objErr->arrErr = $objFormParam->checkError();
230
231        $objErr->doFunc(array('開始日', '終了日', 'search_startyear', 'search_startmonth', 'search_startday', 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_SET_TERM'));
232
233        return $objErr->arrErr;
234    }
235
236    // カテゴリIDをキー、カテゴリ名を値にする配列を返す。
237    function lfGetIDName($arrCatKey, $arrCatVal) {
238        $max = count($arrCatKey);
239        for ($cnt = 0; $cnt < $max; $cnt++) {
240            $key = isset($arrCatKey[$cnt]) ? $arrCatKey[$cnt] : '';
241            $val = isset($arrCatVal[$cnt]) ? $arrCatVal[$cnt] : '';
242            $arrRet[$key] = $val;
243        }
244        return $arrRet;
245    }
246
247    /**
248     * 商品、子テーブル(商品規格)、お気に入り商品の削除
249     *
250     * @param string $where 削除対象の WHERE 句
251     * @param array $arrParam 削除対象の値
252     * @return void
253     */
254    function doDelete($where, $arrParam = array()) {
255        $objQuery =& SC_Query_Ex::getSingletonInstance();
256        $sqlval['del_flg']     = 1;
257        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
258        $objQuery->begin();
259        $objQuery->update('dtb_products_class', $sqlval, "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam);
260        $objQuery->delete('dtb_customer_favorite_products', "product_id IN (SELECT product_id FROM dtb_products WHERE $where)", $arrParam);
261        $objQuery->update('dtb_products', $sqlval, $where, $arrParam);
262        $objQuery->commit();
263    }
264
265    /**
266     * クエリを構築する.
267     *
268     * 検索条件のキーに応じた WHERE 句と, クエリパラメーターを構築する.
269     * クエリパラメーターは, SC_FormParam の入力値から取得する.
270     *
271     * 構築内容は, 引数の $where 及び $arrValues にそれぞれ追加される.
272     *
273     * @param string $key 検索条件のキー
274     * @param string $where 構築する WHERE 句
275     * @param array $arrValues 構築するクエリパラメーター
276     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
277     * @param SC_FormParam $objDb SC_Helper_DB_Ex インスタンス
278     * @return void
279     */
280    function buildQuery($key, &$where, &$arrValues, &$objFormParam, &$objDb) {
281        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
282        switch ($key) {
283        // 商品ID
284        case 'search_product_id':
285            $where .= ' AND product_id = ?';
286            $arrValues[] = sprintf('%d', $objFormParam->getValue($key));
287            break;
288        // 商品コード
289        case 'search_product_code':
290            $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code ILIKE ? GROUP BY product_id)';
291            $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key));
292            break;
293        // 商品名
294        case 'search_name':
295            $where .= ' AND name LIKE ?';
296            $arrValues[] = sprintf('%%%s%%', $objFormParam->getValue($key));
297            break;
298        // カテゴリ
299        case 'search_category_id':
300            list($tmp_where, $tmp_Values) = $objDb->sfGetCatWhere($objFormParam->getValue($key));
301            if ($tmp_where != '') {
302                $where.= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
303                $arrValues = array_merge((array)$arrValues, (array)$tmp_Values);
304            }
305            break;
306        // 種別
307        case 'search_status':
308            $tmp_where = '';
309            foreach ($objFormParam->getValue($key) as $element) {
310                if ($element != '') {
311                    if (SC_Utils_Ex::isBlank($tmp_where)) {
312                        $tmp_where .= ' AND (status = ?';
313                    } else {
314                        $tmp_where .= ' OR status = ?';
315                    }
316                    $arrValues[] = $element;
317                }
318            }
319
320            if (!SC_Utils_Ex::isBlank($tmp_where)) {
321                $tmp_where .= ')';
322                $where .= " $tmp_where ";
323            }
324            break;
325        // 登録・更新日(開始)
326        case 'search_startyear':
327            $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_startyear'),
328                                                $objFormParam->getValue('search_startmonth'),
329                                                $objFormParam->getValue('search_startday'));
330            $where.= ' AND update_date >= ?';
331            $arrValues[] = $date;
332            break;
333        // 登録・更新日(終了)
334        case 'search_endyear':
335            $date = SC_Utils_Ex::sfGetTimestamp($objFormParam->getValue('search_endyear'),
336                                                $objFormParam->getValue('search_endmonth'),
337                                                $objFormParam->getValue('search_endday'), true);
338            $where.= ' AND update_date <= ?';
339            $arrValues[] = $date;
340            break;
341        // 商品ステータス
342        case 'search_product_statuses':
343            if (count($objFormParam->getValue($key)) > 0) {
344                $where .= ' AND product_id IN (SELECT product_id FROM dtb_product_status WHERE product_status_id IN (';
345                foreach ($objFormParam->getValue($key) as $param) {
346                    $where .= '?,';
347                    $arrValues[] = $param;
348                }
349                $where = preg_replace("/,$/", "))", $where);
350            }
351            break;
352        }
353    }
354
355    /**
356     * 検索結果の行数を取得する.
357     *
358     * @param string $where 検索条件の WHERE 句
359     * @param array $arrValues 検索条件のパラメーター
360     * @return integer 検索結果の行数
361     */
362    function getNumberOfLines($where, $arrValues) {
363        $objQuery =& SC_Query_Ex::getSingletonInstance();
364        return $objQuery->count('dtb_products', $where, $arrValues);
365    }
366
367    /**
368     * 商品を検索する.
369     *
370     * @param string $where 検索条件の WHERE 句
371     * @param array $arrValues 検索条件のパラメーター
372     * @param integer $limit 表示件数
373     * @param integer $offset 開始件数
374     * @param string $order 検索結果の並び順
375     * @param SC_Product $objProduct SC_Product インスタンス
376     * @return array 商品の検索結果
377     */
378    function findProducts($where, $arrValues, $limit, $offset, $order, &$objProduct) {
379        $objQuery =& SC_Query_Ex::getSingletonInstance();
380
381        // 読み込む列とテーブルの指定
382        $col = 'product_id, name, main_list_image, status, product_code_min, product_code_max, price02_min, price02_max, stock_min, stock_max, stock_unlimited_min, stock_unlimited_max, update_date';
383        $from = $objProduct->alldtlSQL();
384
385        $objQuery->setLimitOffset($limit, $offset);
386        $objQuery->setOrder($order);
387
388        return $objQuery->select($col, $from, $where, $arrValues);
389    }
390}
Note: See TracBrowser for help on using the repository browser.