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

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