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

Revision 21864, 10.9 KB checked in by h_yoshimoto, 12 years ago (diff)

#1831 Copyrightを更新

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