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

Revision 22567, 9.0 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init()
46    {
47        parent::init();
48        $this->tpl_mainpage = 'products/class.tpl';
49        $this->tpl_subno = 'class';
50        $this->tpl_subtitle = '規格管理';
51        $this->tpl_maintitle = '商品管理';
52        $this->tpl_mainno = 'products';
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process()
61    {
62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action()
72    {
73
74        $objFormParam = new SC_FormParam_Ex();
75
76        $this->lfInitParam($objFormParam);
77        $objFormParam->setParam($_POST);
78        $objFormParam->convParam();
79        $class_id = $objFormParam->getValue('class_id');
80
81        // 要求判定
82        switch ($this->getMode()) {
83            // 編集処理
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($this->arrForm);
92                if ($is_insert) {
93                    $this->lfInsertClass($this->arrForm); // 新規作成
94                } else {
95                    $this->lfUpdateClass($this->arrForm); // 既存編集
96                }
97
98                // 再表示
99                SC_Response_Ex::reload();
100            }
101            break;
102            // 削除
103        case 'delete':
104            //規格データの削除処理
105            $this->lfDeleteClass($class_id);
106
107            // 再表示
108            SC_Response_Ex::reload();
109            break;
110            // 編集前処理
111        case 'pre_edit':
112            // 規格名を取得する。
113            $class_name = $this->lfGetClassName($class_id);
114            // 入力項目にカテゴリ名を入力する。
115            $this->arrForm['name'] = $class_name;
116            break;
117        case 'down':
118            $this->lfDownRank($class_id);
119
120            // 再表示
121            SC_Response_Ex::reload();
122            break;
123        case 'up':
124            $this->lfUpRank($class_id);
125
126            // 再表示
127            SC_Response_Ex::reload();
128            break;
129        default:
130            break;
131        }
132        // 規格の読込
133        $this->arrClass = $this->lfGetClass();
134        $this->arrClassCatCount = SC_Utils_Ex::sfGetClassCatCount();
135        // POSTデータを引き継ぐ
136        $this->tpl_class_id = $class_id;
137
138    }
139
140    /**
141     * デストラクタ.
142     *
143     * @return void
144     */
145    function destroy()
146    {
147        parent::destroy();
148    }
149
150    /**
151     * パラメーターの初期化を行う.
152     *
153     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
154     * @return void
155     */
156    function lfInitParam(&$objFormParam)
157    {
158        $objFormParam->addParam('規格名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK' ,'SPTAB_CHECK' ,'MAX_LENGTH_CHECK'));
159        $objFormParam->addParam('規格ID', 'class_id', INT_LEN, 'n', array('NUM_CHECK'));
160    }
161
162    /**
163     * 有効な規格情報の取得
164     *
165     * @return array 規格情報
166     */
167    function lfGetClass()
168    {
169        $objQuery =& SC_Query_Ex::getSingletonInstance();
170
171        $where = 'del_flg <> 1';
172        $objQuery->setOrder('rank DESC');
173        $arrClass = $objQuery->select('name, class_id', 'dtb_class', $where);
174        return $arrClass;
175    }
176
177    /**
178     * 規格名を取得する
179     *
180     * @param integer $class_id 規格ID
181     * @return string 規格名
182     */
183    function lfGetClassName($class_id)
184    {
185        $objQuery =& SC_Query_Ex::getSingletonInstance();
186        $where = 'class_id = ?';
187        $class_name = $objQuery->get('name', 'dtb_class', $where, array($class_id));
188        return $class_name;
189    }
190
191    /**
192     * 規格情報を新規登録
193     *
194     * @param array $arrForm フォームパラメータークラス
195     * @return integer 更新件数
196     */
197    function lfInsertClass($arrForm)
198    {
199        $objQuery =& SC_Query_Ex::getSingletonInstance();
200        // INSERTする値を作成する。
201        $sqlval['name'] = $arrForm['name'];
202        $sqlval['creator_id'] = $_SESSION['member_id'];
203        $sqlval['rank'] = $objQuery->max('rank', 'dtb_class') + 1;
204        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
205        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
206        // INSERTの実行
207        $sqlval['class_id'] = $objQuery->nextVal('dtb_class_class_id');
208        $ret = $objQuery->insert('dtb_class', $sqlval);
209        return $ret;
210    }
211
212    /**
213     * 規格情報を更新
214     *
215     * @param array $arrForm フォームパラメータークラス
216     * @return integer 更新件数
217     */
218    function lfUpdateClass($arrForm)
219    {
220        $objQuery =& SC_Query_Ex::getSingletonInstance();
221        // UPDATEする値を作成する。
222        $sqlval['name'] = $arrForm['name'];
223        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
224        $where = 'class_id = ?';
225        // UPDATEの実行
226        $ret = $objQuery->update('dtb_class', $sqlval, $where, array($arrForm['class_id']));
227        return $ret;
228    }
229
230    /**
231     * 規格情報を削除する.
232     *
233     * @param integer $class_id 規格ID
234     * @param SC_Helper_DB $objDb SC_Helper_DBのインスタンス
235     * @return integer 削除件数
236     */
237    function lfDeleteClass($class_id)
238    {
239        $objDb = new SC_Helper_DB_Ex();
240        $objQuery =& SC_Query_Ex::getSingletonInstance();
241
242        $ret = $objDb->sfDeleteRankRecord('dtb_class', 'class_id', $class_id, '', true);
243        $where= 'class_id = ?';
244        $objQuery->delete('dtb_classcategory', $where, array($class_id));
245        return $ret;
246    }
247
248    /**
249     * エラーチェック
250     *
251     * @param array $objFormParam フォームパラメータークラス
252     * @return array エラー配列
253     */
254    function lfCheckError(&$objFormParam)
255    {
256        $objQuery =& SC_Query_Ex::getSingletonInstance();
257        $arrForm = $objFormParam->getHashArray();
258        // パラメーターの基本チェック
259        $arrErr = $objFormParam->checkError();
260        if (!SC_Utils_Ex::isBlank($arrErr)) {
261            return $arrErr;
262        } else {
263            $arrForm = $objFormParam->getHashArray();
264        }
265
266        $where = 'del_flg = 0 AND name = ?';
267        $arrClass = $objQuery->select('class_id, name', 'dtb_class', $where, array($arrForm['name']));
268        // 編集中のレコード以外に同じ名称が存在する場合
269        if ($arrClass[0]['class_id'] != $arrForm['class_id'] && $arrClass[0]['name'] == $arrForm['name']) {
270            $arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br>';
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.