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

Revision 21867, 9.0 KB checked in by nakanishi, 12 years ago (diff)

#1831 Copyright Update

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