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

Revision 23605, 11.0 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

  • PHP Analyzer
  • PHP PDepend
  • PHP Similarity Analyzer
  • PHP Change Tracking Analyzer
  • 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-2014 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:LC_Page_Admin_Products_ClassCategory.php 15532 2007-08-31 14:39:46Z nanasess $
32 */
33class LC_Page_Admin_Products_ClassCategory extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'products/classcategory.tpl';
44        $this->tpl_subno = 'class';
45        $this->tpl_maintitle = '商品管理';
46        $this->tpl_subtitle = '規格管理>分類登録';
47        $this->tpl_mainno = 'products';
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    public function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    public function action()
67    {
68        $objFormParam = new SC_FormParam_Ex();
69
70        $this->lfInitParam($objFormParam);
71        $objFormParam->setParam($_REQUEST);
72        $objFormParam->convParam();
73        $class_id = $objFormParam->getValue('class_id');
74        $classcategory_id = $objFormParam->getValue('classcategory_id');
75
76        switch ($this->getMode()) {
77            // 登録ボタン押下
78            // 新規作成 or 編集
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($classcategory_id);
87                    if ($is_insert) {
88                        //新規追加
89                        $this->lfInsertClass($this->arrForm);
90                    } else {
91                        //更新
92                        $this->lfUpdateClass($this->arrForm);
93                    }
94
95                    // 再表示
96                    SC_Response_Ex::reload();
97                }
98                break;
99                // 削除
100            case 'delete':
101                // ランク付きレコードの削除
102                $this->lfDeleteClassCat($class_id, $classcategory_id);
103
104                SC_Response_Ex::reload();
105                break;
106                // 編集前処理
107            case 'pre_edit':
108                // 規格名を取得する。
109                $classcategory_name = $this->lfGetClassCatName($classcategory_id);
110                // 入力項目にカテゴリ名を入力する。
111                $this->arrForm['name'] = $classcategory_name;
112                break;
113            case 'down':
114                //並び順を下げる
115                $this->lfDownRank($class_id, $classcategory_id);
116
117                SC_Response_Ex::reload();
118                break;
119            case 'up':
120                //並び順を上げる
121                $this->lfUpRank($class_id, $classcategory_id);
122
123                SC_Response_Ex::reload();
124                break;
125            default:
126                break;
127        }
128        //規格分類名の取得
129        $this->tpl_class_name = $this->lfGetClassName($class_id);
130        //規格分類情報の取得
131        $this->arrClassCat = $this->lfGetClassCat($class_id);
132        // POSTデータを引き継ぐ
133        $this->tpl_classcategory_id = $classcategory_id;
134    }
135
136    /**
137     * パラメーターの初期化を行う.
138     *
139     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
140     * @return void
141     */
142    public function lfInitParam(&$objFormParam)
143    {
144        $objFormParam->addParam('規格ID', 'class_id', INT_LEN, 'n', array('NUM_CHECK'));
145        $objFormParam->addParam('規格分類名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK' ,'SPTAB_CHECK' ,'MAX_LENGTH_CHECK'));
146        $objFormParam->addParam('規格分類ID', 'classcategory_id', INT_LEN, 'n', array('NUM_CHECK'));
147    }
148
149    /**
150     * 有効な規格分類情報の取得
151     *
152     * @param  integer $class_id 規格ID
153     * @return array   規格分類情報
154     */
155    public function lfGetClassCat($class_id)
156    {
157        $objQuery =& SC_Query_Ex::getSingletonInstance();
158
159        $where = 'del_flg <> 1 AND class_id = ?';
160        $objQuery->setOrder('rank DESC'); // XXX 降順
161        $arrClassCat = $objQuery->select('name, classcategory_id', 'dtb_classcategory', $where, array($class_id));
162
163        return $arrClassCat;
164    }
165
166    /**
167     * 規格名の取得
168     *
169     * @param  integer $class_id 規格ID
170     * @return string  規格名
171     */
172    public function lfGetClassName($class_id)
173    {
174        $objQuery =& SC_Query_Ex::getSingletonInstance();
175
176        $where = 'class_id = ?';
177        $name = $objQuery->get('name', 'dtb_class', $where, array($class_id));
178
179        return $name;
180    }
181
182    /**
183     * 規格分類名を取得する
184     *
185     * @param  integer $classcategory_id 規格分類ID
186     * @return string  規格分類名
187     */
188    public function lfGetClassCatName($classcategory_id)
189    {
190        $objQuery =& SC_Query_Ex::getSingletonInstance();
191        $where = 'classcategory_id = ?';
192        $name = $objQuery->get('name', 'dtb_classcategory', $where, array($classcategory_id));
193
194        return $name;
195    }
196
197    /**
198     * 規格分類情報を新規登録
199     *
200     * @param  array   $arrForm フォームパラメータークラス
201     * @return integer 更新件数
202     */
203    public function lfInsertClass($arrForm)
204    {
205        $objQuery =& SC_Query_Ex::getSingletonInstance();
206        $objQuery->begin();
207        // 親規格IDの存在チェック
208        $where = 'del_flg <> 1 AND class_id = ?';
209        $class_id = $objQuery->get('class_id', 'dtb_class', $where, array($arrForm['class_id']));
210        if (!SC_Utils_Ex::isBlank($class_id)) {
211            // INSERTする値を作成する。
212            $sqlval['name'] = $arrForm['name'];
213            $sqlval['class_id'] = $arrForm['class_id'];
214            $sqlval['creator_id'] = $_SESSION['member_id'];
215            $sqlval['rank'] = $objQuery->max('rank', 'dtb_classcategory', $where, array($arrForm['class_id'])) + 1;
216            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
217            $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
218            // INSERTの実行
219            $sqlval['classcategory_id'] = $objQuery->nextVal('dtb_classcategory_classcategory_id');
220            $ret = $objQuery->insert('dtb_classcategory', $sqlval);
221        }
222        $objQuery->commit();
223
224        return $ret;
225    }
226
227    /**
228     * 規格分類情報を更新
229     *
230     * @param  array   $arrForm フォームパラメータークラス
231     * @return integer 更新件数
232     */
233    public function lfUpdateClass($arrForm)
234    {
235        $objQuery =& SC_Query_Ex::getSingletonInstance();
236        // UPDATEする値を作成する。
237        $sqlval['name'] = $arrForm['name'];
238        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
239        $where = 'classcategory_id = ?';
240        // UPDATEの実行
241        $ret = $objQuery->update('dtb_classcategory', $sqlval, $where, array($arrForm['classcategory_id']));
242
243        return $ret;
244    }
245
246    /**
247     * エラーチェック
248     *
249     * @param  SC_FormParam $objFormParam フォームパラメータークラス
250     * @return array エラー配列
251     */
252    public function lfCheckError(&$objFormParam)
253    {
254        $objQuery =& SC_Query_Ex::getSingletonInstance();
255        $arrForm = $objFormParam->getHashArray();
256        // パラメーターの基本チェック
257        $arrErr = $objFormParam->checkError();
258        if (!SC_Utils_Ex::isBlank($arrErr)) {
259            return $arrErr;
260        } else {
261            $arrForm = $objFormParam->getHashArray();
262        }
263
264        $where = 'class_id = ? AND name = ?';
265        $arrRet = $objQuery->select('classcategory_id, name', 'dtb_classcategory', $where, array($arrForm['class_id'], $arrForm['name']));
266        // 編集中のレコード以外に同じ名称が存在する場合
267        if ($arrRet[0]['classcategory_id'] != $arrForm['classcategory_id'] && $arrRet[0]['name'] == $arrForm['name']) {
268            $arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br>';
269        }
270
271        return $arrErr;
272    }
273
274    /**
275     * 新規規格分類追加かどうかを判定する.
276     *
277     * @param  integer $classcategory_id 規格分類ID
278     * @return boolean 新規商品追加の場合 true
279     */
280    public function lfCheckInsert($classcategory_id)
281    {
282        //classcategory_id のあるなしで新規規格分類化かどうかを判定
283        if (empty($classcategory_id)) {
284            return true;
285        } else {
286            return false;
287        }
288    }
289
290    /**
291     * 規格分類情報を削除する
292     *
293     * @param  integer $class_id         規格ID
294     * @param  integer $classcategory_id 規格分類ID
295     * @return void
296     */
297    public function lfDeleteClassCat($class_id, $classcategory_id)
298    {
299        $objDb = new SC_Helper_DB_Ex();
300        $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id);
301        $objDb->sfDeleteRankRecord('dtb_classcategory', 'classcategory_id', $classcategory_id, $where, true);
302    }
303    /**
304     * 並び順を上げる
305     *
306     * @param  integer $class_id         規格ID
307     * @param  integer $classcategory_id 規格分類ID
308     * @return void
309     */
310    public function lfUpRank($class_id, $classcategory_id)
311    {
312        $objDb = new SC_Helper_DB_Ex();
313        $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id);
314        $objDb->sfRankUp('dtb_classcategory', 'classcategory_id', $classcategory_id, $where);
315    }
316    /**
317     * 並び順を下げる
318     *
319     * @param  integer $class_id         規格ID
320     * @param  integer $classcategory_id 規格分類ID
321     * @return void
322     */
323    public function lfDownRank($class_id, $classcategory_id)
324    {
325        $objDb = new SC_Helper_DB_Ex();
326        $where = 'class_id = ' . SC_Utils_Ex::sfQuoteSmart($class_id);
327        $objDb->sfRankDown('dtb_classcategory', 'classcategory_id', $classcategory_id, $where);
328    }
329}
Note: See TracBrowser for help on using the repository browser.