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

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