source: branches/version-2_13-dev/data/class/pages/admin/products/LC_Page_Admin_Products_ClassCategory.php @ 22856

Revision 22856, 11.0 KB checked in by Seasoft, 11 years ago (diff)

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

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • 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:LC_Page_Admin_Products_ClassCategory.php 15532 2007-08-31 14:39:46Z nanasess $
32 */
33class LC_Page_Admin_Products_ClassCategory extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'products/classcategory.tpl';
44        $this->tpl_subno = 'class';
45        $this->tpl_maintitle = '商品管理';
46        $this->tpl_subtitle = '規格管理>分類登録';
47        $this->tpl_mainno = 'products';
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    function action()
67    {
68        $objFormParam = new SC_FormParam_Ex();
69
70        $this->lfInitParam($objFormParam);
71        $objFormParam->setParam($_REQUEST);
72        $objFormParam->convParam();
73        $class_id = $objFormParam->getValue('class_id');
74        $classcategory_id = $objFormParam->getValue('classcategory_id');
75
76        switch ($this->getMode()) {
77            // 登録ボタン押下
78            // 新規作成 or 編集
79            case 'edit':
80                // パラメーター値の取得
81                $this->arrForm = $objFormParam->getHashArray();
82                // 入力パラメーターチェック
83                $this->arrErr = $this->lfCheckError($objFormParam);
84                if (SC_Utils_Ex::isBlank($this->arrErr)) {
85                    //新規規格追加かどうかを判定する
86                    $is_insert = $this->lfCheckInsert($classcategory_id);
87                    if ($is_insert) {
88                        //新規追加
89                        $this->lfInsertClass($this->arrForm);
90                    } else {
91                        //更新
92                        $this->lfUpdateClass($this->arrForm);
93                    }
94
95                    // 再表示
96                    SC_Response_Ex::reload();
97                }
98                break;
99                // 削除
100            case 'delete':
101                // ランク付きレコードの削除
102                $this->lfDeleteClassCat($class_id, $classcategory_id);
103
104                SC_Response_Ex::reload();
105                break;
106                // 編集前処理
107            case 'pre_edit':
108                // 規格名を取得する。
109                $classcategory_name = $this->lfGetClassCatName($classcategory_id);
110                // 入力項目にカテゴリ名を入力する。
111                $this->arrForm['name'] = $classcategory_name;
112                break;
113            case 'down':
114                //並び順を下げる
115                $this->lfDownRank($class_id, $classcategory_id);
116
117                SC_Response_Ex::reload();
118                break;
119            case 'up':
120                //並び順を上げる
121                $this->lfUpRank($class_id, $classcategory_id);
122
123                SC_Response_Ex::reload();
124                break;
125            default:
126                break;
127        }
128        //規格分類名の取得
129        $this->tpl_class_name = $this->lfGetClassName($class_id);
130        //規格分類情報の取得
131        $this->arrClassCat = $this->lfGetClassCat($class_id);
132        // POSTデータを引き継ぐ
133        $this->tpl_classcategory_id = $classcategory_id;
134
135    }
136
137    /**
138     * デストラクタ.
139     *
140     * @return void
141     */
142    function destroy()
143    {
144        parent::destroy();
145    }
146
147    /**
148     * パラメーターの初期化を行う.
149     *
150     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
151     * @return void
152     */
153    function lfInitParam(&$objFormParam)
154    {
155        $objFormParam->addParam('規格ID', 'class_id', INT_LEN, 'n', array('NUM_CHECK'));
156        $objFormParam->addParam('規格分類名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK' ,'SPTAB_CHECK' ,'MAX_LENGTH_CHECK'));
157        $objFormParam->addParam('規格分類ID', 'classcategory_id', INT_LEN, 'n', array('NUM_CHECK'));
158    }
159
160    /**
161     * 有効な規格分類情報の取得
162     *
163     * @param integer $class_id 規格ID
164     * @return array 規格分類情報
165     */
166    function lfGetClassCat($class_id)
167    {
168        $objQuery =& SC_Query_Ex::getSingletonInstance();
169
170        $where = 'del_flg <> 1 AND class_id = ?';
171        $objQuery->setOrder('rank DESC'); // XXX 降順
172        $arrClassCat = $objQuery->select('name, classcategory_id', 'dtb_classcategory', $where, array($class_id));
173
174        return $arrClassCat;
175    }
176
177    /**
178     * 規格名の取得
179     *
180     * @param integer $class_id 規格ID
181     * @return string 規格名
182     */
183    function lfGetClassName($class_id)
184    {
185        $objQuery =& SC_Query_Ex::getSingletonInstance();
186
187        $where = 'class_id = ?';
188        $name = $objQuery->get('name', 'dtb_class', $where, array($class_id));
189
190        return $name;
191    }
192
193    /**
194     * 規格分類名を取得する
195     *
196     * @param integer $classcategory_id 規格分類ID
197     * @return string 規格分類名
198     */
199    function lfGetClassCatName($classcategory_id)
200    {
201        $objQuery =& SC_Query_Ex::getSingletonInstance();
202        $where = 'classcategory_id = ?';
203        $name = $objQuery->get('name', 'dtb_classcategory', $where, array($classcategory_id));
204
205        return $name;
206    }
207
208    /**
209     * 規格分類情報を新規登録
210     *
211     * @param array $arrForm フォームパラメータークラス
212     * @return integer 更新件数
213     */
214    function lfInsertClass($arrForm)
215    {
216        $objQuery =& SC_Query_Ex::getSingletonInstance();
217        $objQuery->begin();
218        // 親規格IDの存在チェック
219        $where = 'del_flg <> 1 AND class_id = ?';
220        $class_id = $objQuery->get('class_id', 'dtb_class', $where, array($arrForm['class_id']));
221        if (!SC_Utils_Ex::isBlank($class_id)) {
222            // INSERTする値を作成する。
223            $sqlval['name'] = $arrForm['name'];
224            $sqlval['class_id'] = $arrForm['class_id'];
225            $sqlval['creator_id'] = $_SESSION['member_id'];
226            $sqlval['rank'] = $objQuery->max('rank', 'dtb_classcategory', $where, array($arrForm['class_id'])) + 1;
227            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
228            $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
229            // INSERTの実行
230            $sqlval['classcategory_id'] = $objQuery->nextVal('dtb_classcategory_classcategory_id');
231            $ret = $objQuery->insert('dtb_classcategory', $sqlval);
232        }
233        $objQuery->commit();
234
235        return $ret;
236    }
237
238    /**
239     * 規格分類情報を更新
240     *
241     * @param array $arrForm フォームパラメータークラス
242     * @return integer 更新件数
243     */
244    function lfUpdateClass($arrForm)
245    {
246        $objQuery =& SC_Query_Ex::getSingletonInstance();
247        // UPDATEする値を作成する。
248        $sqlval['name'] = $arrForm['name'];
249        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
250        $where = 'classcategory_id = ?';
251        // UPDATEの実行
252        $ret = $objQuery->update('dtb_classcategory', $sqlval, $where, array($arrForm['classcategory_id']));
253
254        return $ret;
255    }
256
257    /**
258     * エラーチェック
259     *
260     * @param array $objFormParam フォームパラメータークラス
261     * @return array エラー配列
262     */
263    function lfCheckError(&$objFormParam)
264    {
265        $objQuery =& SC_Query_Ex::getSingletonInstance();
266        $arrForm = $objFormParam->getHashArray();
267        // パラメーターの基本チェック
268        $arrErr = $objFormParam->checkError();
269        if (!SC_Utils_Ex::isBlank($arrErr)) {
270            return $arrErr;
271        } else {
272            $arrForm = $objFormParam->getHashArray();
273        }
274
275        $where = 'class_id = ? AND name = ?';
276        $arrRet = $objQuery->select('classcategory_id, name', 'dtb_classcategory', $where, array($arrForm['class_id'], $arrForm['name']));
277        // 編集中のレコード以外に同じ名称が存在する場合
278        if ($arrRet[0]['classcategory_id'] != $arrForm['classcategory_id'] && $arrRet[0]['name'] == $arrForm['name']) {
279            $arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br>';
280        }
281
282        return $arrErr;
283    }
284
285    /**
286     * 新規規格分類追加かどうかを判定する.
287     *
288     * @param integer $classcategory_id 規格分類ID
289     * @return boolean 新規商品追加の場合 true
290     */
291    function lfCheckInsert($classcategory_id)
292    {
293        //classcategory_id のあるなしで新規規格分類化かどうかを判定
294        if (empty($classcategory_id)) {
295            return true;
296        } else {
297            return false;
298        }
299    }
300
301    /**
302     * 規格分類情報を削除する
303     *
304     * @param integer $class_id 規格ID
305     * @param integer $classcategory_id 規格分類ID
306     * @return void
307     */
308    function lfDeleteClassCat($class_id, $classcategory_id)
309    {
310        $objDb = new SC_Helper_DB_Ex();
311        $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id);
312        $objDb->sfDeleteRankRecord('dtb_classcategory', 'classcategory_id', $classcategory_id, $where, true);
313    }
314    /**
315     * 並び順を上げる
316     *
317     * @param integer $class_id 規格ID
318     * @param integer $classcategory_id 規格分類ID
319     * @return void
320     */
321    function lfUpRank($class_id, $classcategory_id)
322    {
323        $objDb = new SC_Helper_DB_Ex();
324        $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id);
325        $objDb->sfRankUp('dtb_classcategory', 'classcategory_id', $classcategory_id, $where);
326    }
327    /**
328     * 並び順を下げる
329     *
330     * @param integer $class_id 規格ID
331     * @param integer $classcategory_id 規格分類ID
332     * @return void
333     */
334    function lfDownRank($class_id, $classcategory_id)
335    {
336        $objDb = new SC_Helper_DB_Ex();
337        $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id);
338        $objDb->sfRankDown('dtb_classcategory', 'classcategory_id', $classcategory_id, $where);
339    }
340}
Note: See TracBrowser for help on using the repository browser.