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

Revision 20538, 8.9 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)
#628(未使用処理・定義などの削除)

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