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

Revision 22796, 8.9 KB checked in by h_yoshimoto, 11 years ago (diff)

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

  • 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
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     * @return array 規格情報
160     */
161    function lfGetClass() {
162        $objQuery =& SC_Query_Ex::getSingletonInstance();
163
164        $where = 'del_flg <> 1';
165        $objQuery->setOrder('rank DESC');
166        $arrClass = $objQuery->select('name, class_id', 'dtb_class', $where);
167        return $arrClass;
168    }
169
170    /**
171     * 規格名を取得する
172     *
173     * @param integer $class_id 規格ID
174     * @return string 規格名
175     */
176    function lfGetClassName($class_id) {
177        $objQuery =& SC_Query_Ex::getSingletonInstance();
178        $where = 'class_id = ?';
179        $class_name = $objQuery->get('name', 'dtb_class', $where, array($class_id));
180        return $class_name;
181    }
182
183    /**
184     * 規格情報を新規登録
185     *
186     * @param array $arrForm フォームパラメータークラス
187     * @return integer 更新件数
188     */
189    function lfInsertClass($arrForm) {
190        $objQuery =& SC_Query_Ex::getSingletonInstance();
191        // INSERTする値を作成する。
192        $sqlval['name'] = $arrForm['name'];
193        $sqlval['creator_id'] = $_SESSION['member_id'];
194        $sqlval['rank'] = $objQuery->max('rank', 'dtb_class') + 1;
195        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
196        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
197        // INSERTの実行
198        $sqlval['class_id'] = $objQuery->nextVal('dtb_class_class_id');
199        $ret = $objQuery->insert('dtb_class', $sqlval);
200        return $ret;
201    }
202
203    /**
204     * 規格情報を更新
205     *
206     * @param array $arrForm フォームパラメータークラス
207     * @return integer 更新件数
208     */
209    function lfUpdateClass($arrForm) {
210        $objQuery =& SC_Query_Ex::getSingletonInstance();
211        // UPDATEする値を作成する。
212        $sqlval['name'] = $arrForm['name'];
213        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
214        $where = 'class_id = ?';
215        // UPDATEの実行
216        $ret = $objQuery->update('dtb_class', $sqlval, $where, array($arrForm['class_id']));
217        return $ret;
218    }
219
220    /**
221     * 規格情報を削除する.
222     *
223     * @param integer $class_id 規格ID
224     * @param SC_Helper_DB $objDb SC_Helper_DBのインスタンス
225     * @return integer 削除件数
226     */
227    function lfDeleteClass($class_id) {
228        $objDb = new SC_Helper_DB_Ex();
229        $objQuery =& SC_Query_Ex::getSingletonInstance();
230
231        $ret = $objDb->sfDeleteRankRecord('dtb_class', 'class_id', $class_id, '', true);
232        $where= 'class_id = ?';
233        $objQuery->delete('dtb_classcategory', $where, array($class_id));
234        return $ret;
235    }
236
237    /**
238     * エラーチェック
239     *
240     * @param array $objFormParam フォームパラメータークラス
241     * @return array エラー配列
242     */
243    function lfCheckError(&$objFormParam) {
244        $objQuery =& SC_Query_Ex::getSingletonInstance();
245        $arrForm = $objFormParam->getHashArray();
246        // パラメーターの基本チェック
247        $arrErr = $objFormParam->checkError();
248        if (!SC_Utils_Ex::isBlank($arrErr)) {
249            return $arrErr;
250        } else {
251            $arrForm = $objFormParam->getHashArray();
252        }
253
254        $where = 'del_flg = 0 AND name = ?';
255        $arrClass = $objQuery->select('class_id, name', 'dtb_class', $where, array($arrForm['name']));
256        // 編集中のレコード以外に同じ名称が存在する場合
257        if ($arrClass[0]['class_id'] != $arrForm['class_id'] && $arrClass[0]['name'] == $arrForm['name']) {
258            $arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br>';
259        }
260        return $arrErr;
261    }
262
263    /**
264     * 新規規格追加かどうかを判定する.
265     *
266     * @param string $arrForm フォームの入力値
267     * @return boolean 新規商品追加の場合 true
268     */
269    function lfCheckInsert($arrForm) {
270        //class_id のあるなしで新規商品かどうかを判定
271        if (empty($arrForm['class_id'])) {
272            return true;
273        } else {
274            return false;
275        }
276    }
277    /**
278     * 並び順を上げる
279     *
280     * @param integer $class_id 規格ID
281     * @return void
282     */
283    function lfUpRank($class_id) {
284        $objDb = new SC_Helper_DB_Ex();
285        $objDb->sfRankUp('dtb_class', 'class_id', $class_id);
286    }
287    /**
288     * 並び順を下げる
289     *
290     * @param integer $class_id 規格ID
291     * @return void
292     */
293    function lfDownRank($class_id) {
294        $objDb = new SC_Helper_DB_Ex();
295        $objDb->sfRankDown('dtb_class', 'class_id', $class_id);
296    }
297}
Note: See TracBrowser for help on using the repository browser.