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

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