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

Revision 22735, 6.6 KB checked in by h_yoshimoto, 11 years ago (diff)

#2193 ユニットテストチームのコミットをマージ(from camp/camp-2_13-tests)

  • 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_Maker 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/maker.tpl';
49        $this->tpl_subno = 'maker';
50        $this->tpl_maintitle = '商品管理';
51        $this->tpl_subtitle = 'メーカー登録';
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        $objMaker = new SC_Helper_Maker_Ex();
75        $objFormParam = new SC_FormParam_Ex();
76
77        // パラメーター情報の初期化
78        $this->lfInitParam($objFormParam);
79
80        // POST値をセット
81        $objFormParam->setParam($_POST);
82
83        // POST値の入力文字変換
84        $objFormParam->convParam();
85
86        //maker_idを変数にセット
87        $maker_id = $objFormParam->getValue('maker_id');
88
89        // モードによる処理切り替え
90        switch ($this->getMode()) {
91
92            // 編集処理
93            case 'edit':
94                // エラーチェック
95                $this->arrErr = $this->lfCheckError($objFormParam, $objMaker);
96                if (!SC_Utils_Ex::isBlank($this->arrErr['maker_id'])) {
97                    trigger_error('', E_USER_ERROR);
98                    return;
99                }
100
101                if (count($this->arrErr) <= 0) {
102                    // POST値の引き継ぎ
103                    $arrParam = $objFormParam->getHashArray();
104                    // 登録実行
105                    $res_maker_id = $this->doRegist($maker_id, $arrParam, $objMaker);
106                    if ($res_maker_id !== FALSE) {
107                        // 完了メッセージ
108                        $maker_id = $res_maker_id;
109                        $this->tpl_onload = "alert('登録が完了しました。');";
110                    }
111                }
112                // POSTデータを引き継ぐ
113                $this->tpl_maker_id = $maker_id;
114                break;
115
116            // 編集前処理
117            case 'pre_edit':
118                $maker = $objMaker->getMaker($maker_id);
119                $objFormParam->setParam($maker);
120
121                // POSTデータを引き継ぐ
122                $this->tpl_maker_id = $maker_id;
123                break;
124
125            // メーカー順変更
126            case 'up':
127                $objMaker->rankUp($maker_id);
128
129                // リロード
130                SC_Response_Ex::reload();
131                break;
132
133            case 'down':
134                $objMaker->rankDown($maker_id);
135
136                // リロード
137                SC_Response_Ex::reload();
138                break;
139
140            // 削除
141            case 'delete':
142                $objMaker->delete($maker_id);
143
144                // リロード
145                SC_Response_Ex::reload();
146                break;
147
148            default:
149                break;
150        }
151
152        $this->arrForm = $objFormParam->getFormParamList();
153
154        // メーカー情報読み込み
155        $this->arrMaker = $objMaker->getList();
156    }
157
158    /**
159     * デストラクタ.
160     *
161     * @return void
162     */
163    function destroy()
164    {
165        parent::destroy();
166    }
167
168    /**
169     * パラメーター情報の初期化を行う.
170     *
171     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
172     * @return void
173     */
174    function lfInitParam(&$objFormParam)
175    {
176        $objFormParam->addParam('メーカーID', 'maker_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
177        $objFormParam->addParam('メーカー名', 'name', SMTEXT_LEN, 'KVa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
178    }
179
180    /**
181     * 登録処理を実行.
182     *
183     * @param integer $maker_id
184     * @param array $sqlval
185     * @param object $objMaker
186     * @return multiple
187     */
188    function doRegist($maker_id, $sqlval, SC_Helper_Maker_Ex $objMaker)
189    {
190        $sqlval['maker_id'] = $maker_id;
191        $sqlval['creator_id'] = $_SESSION['member_id'];
192        return $objMaker->saveMaker($sqlval);
193    }
194
195    /**
196     * 入力エラーチェック.
197     *
198     * @return array $objErr->arrErr エラー内容
199     */
200    function lfCheckError(&$objFormParam, SC_Helper_Maker_Ex &$objMaker)
201    {
202
203        $arrErr = $objFormParam->checkError();
204        $arrForm = $objFormParam->getHashArray();
205
206        // maker_id の正当性チェック
207        if (!empty($arrForm['maker_id'])) {
208            if (!SC_Utils_Ex::sfIsInt($arrForm['maker_id'])
209                || SC_Utils_Ex::sfIsZeroFilling($arrForm['maker_id'])
210                || !$objMaker->getMaker($arrForm['maker_id'])
211            ) {
212                // maker_idが指定されていて、且つその値が不正と思われる場合はエラー
213                $arrErr['maker_id'] = '※ メーカーIDが不正です<br />';
214            }
215        }
216        if (!isset($arrErr['name'])) {
217            $arrMaker = $objMaker->getByName($arrForm['name']);
218
219            // 編集中のレコード以外に同じ名称が存在する場合
220            if (
221                    !SC_Utils_Ex::isBlank($arrMaker)
222                    && $arrMaker['maker_id'] != $arrForm['maker_id']
223                    && $arrMaker['name'] == $arrForm['name']
224                ) {
225                $arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br />';
226            }
227        }
228
229        return $arrErr;
230    }
231}
Note: See TracBrowser for help on using the repository browser.