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

Revision 21689, 10.4 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 インスタンスを呼び出す処理を統一

  • 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-2011 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    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'products/maker.tpl';
47        $this->tpl_subno = 'maker';
48        $this->tpl_maintitle = '商品管理';
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        // フックポイント.
70        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
71        $objPlugin->doAction('lc_page_admin_products_maker_action_start', array($this));
72
73        $objFormParam = new SC_FormParam_Ex();
74
75        // パラメーター情報の初期化
76        $this->lfInitParam($objFormParam);
77
78        // POST値をセット
79        $objFormParam->setParam($_POST);
80
81        // POST値の入力文字変換
82        $objFormParam->convParam();
83
84        //maker_idを変数にセット
85        $maker_id = $objFormParam->getValue('maker_id');
86
87        // 変換後のPOST値を取得
88        $this->arrForm  = $objFormParam->getHashArray();
89
90        // モードによる処理切り替え
91        switch ($this->getMode()) {
92
93            // 編集処理
94            case 'edit':
95            // 入力文字の変換
96
97                // エラーチェック
98                $this->arrErr = $this->lfErrorCheck($this->arrForm);
99                if (count($this->arrErr) <= 0) {
100                    if ($this->arrForm['maker_id'] == '') {
101                        // メーカー情報新規登録
102                        $this->lfInsert($this->arrForm);
103                    } else {
104                        // メーカー情報編集
105                        $this->lfUpdate($this->arrForm);
106                    }
107                     // フックポイント.
108                    $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
109                    $objPlugin->doAction('lc_page_admin_products_maker_action_edit', array($this));
110
111                    // 再表示
112                    $this->objDisplay->reload();
113                } else {
114                    // POSTデータを引き継ぐ
115                    $this->tpl_maker_id = $this->arrForm['maker_id'];
116                }
117                break;
118
119            // 編集前処理
120            case 'pre_edit':
121                $this->arrForm = $this->lfPreEdit($this->arrForm, $this->arrForm['maker_id']);
122                $this->tpl_maker_id = $this->arrForm['maker_id'];
123                break;
124
125            // メーカー順変更
126            case 'up':
127            case 'down':
128                $this->lfRankChange($this->arrForm['maker_id'], $this->getMode());
129                // フックポイント.
130                $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
131                $objPlugin->doAction('lc_page_admin_products_maker_action_down', array($this));
132
133                // リロード
134                SC_Response_Ex::reload();
135                break;
136
137            // 削除
138            case 'delete':
139                $this->lfDelete($this->arrForm['maker_id']);
140                // フックポイント.
141                $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
142                $objPlugin->doAction('lc_page_admin_products_maker_action_delete', array($this));
143
144                // リロード
145                SC_Response_Ex::reload();
146                break;
147
148            default:
149                break;
150        }
151
152        // メーカー情報読み込み
153        $this->arrMaker = $this->lfDisp();
154        // POSTデータを引き継ぐ
155        $this->tpl_maker_id = $maker_id;
156
157        // フックポイント.
158        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
159        $objPlugin->doAction('lc_page_admin_products_maker_action_end', array($this));
160    }
161
162    /**
163     * デストラクタ.
164     *
165     * @return void
166     */
167    function destroy() {
168        parent::destroy();
169    }
170
171    /**
172     * パラメーター情報の初期化を行う.
173     *
174     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
175     * @return void
176     */
177    function lfInitParam(&$objFormParam) {
178        $objFormParam->addParam('メーカーID', 'maker_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
179        $objFormParam->addParam('メーカー名', 'name', SMTEXT_LEN, 'KVa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
180    }
181
182    /**
183     * メーカー情報表示.
184     *
185     * @return array $arrMaker メーカー情報
186     */
187    function lfDisp() {
188        $objQuery =& SC_Query_Ex::getSingletonInstance();
189
190        // 削除されていないメーカー情報を表示する
191        $where = 'del_flg = 0';
192        $objQuery->setOrder('rank DESC');
193        $arrMaker = array();
194        $arrMaker = $objQuery->select('maker_id, name', 'dtb_maker', $where);
195        return $arrMaker;
196    }
197
198    /**
199     * メーカー情報新規登録.
200     *
201     * @param array $arrForm メーカー情報
202     * @return void
203     */
204    function lfInsert(&$arrForm) {
205        $objQuery =& SC_Query_Ex::getSingletonInstance();
206
207        // INSERTする値を作成する
208        $sqlval['name'] = $arrForm['name'];
209        $sqlval['rank'] = $objQuery->max('rank', 'dtb_maker') + 1;
210        $sqlval['creator_id'] = $_SESSION['member_id'];
211        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
212        $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
213        $sqlval['maker_id'] = $objQuery->nextVal('dtb_maker_maker_id');
214
215        // INSERTの実行
216        $objQuery->insert('dtb_maker', $sqlval);
217    }
218
219    /**
220     * メーカー情報更新.
221     *
222     * @param array $arrForm メーカー情報
223     * @return void
224     */
225    function lfUpdate(&$arrForm) {
226        $objQuery =& SC_Query_Ex::getSingletonInstance();
227
228        // UPDATEする値を作成する
229        $sqlval['name'] = $arrForm['name'];
230        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
231        $where = 'maker_id = ?';
232
233        // UPDATEの実行
234        $objQuery->update('dtb_maker', $sqlval, $where, array($arrForm['maker_id']));
235    }
236
237    /**
238     * メーカー情報削除.
239     *
240     * @param integer $maker_id メーカーID
241     * @return void
242     */
243    function lfDelete($maker_id) {
244        $objDb = new SC_Helper_DB_Ex();
245        $objDb->sfDeleteRankRecord('dtb_maker', 'maker_id', $maker_id, '', true);
246    }
247
248    /**
249     * メーカー情報順番変更.
250     *
251     * @param  integer $maker_id メーカーID
252     * @param  string  $mode up か down のモードを示す文字列
253     * @return void
254     */
255    function lfRankChange($maker_id, $mode) {
256        $objDb = new SC_Helper_DB_Ex();
257
258        switch ($mode) {
259            case 'up':
260                $objDb->sfRankUp('dtb_maker', 'maker_id', $maker_id);
261                break;
262
263            case 'down':
264                $objDb->sfRankDown('dtb_maker', 'maker_id', $maker_id);
265                break;
266
267            default:
268                break;
269        }
270    }
271
272    /**
273     * メーカー情報編集前処理.
274     *
275     * @param array   $arrForm メーカー情報
276     * @param integer $maker_id メーカーID
277     * @return array  $arrForm メーカー名を追加
278     */
279    function lfPreEdit(&$arrForm, $maker_id) {
280        $objQuery =& SC_Query_Ex::getSingletonInstance();
281
282        // 編集項目を取得する
283        $where = 'maker_id = ?';
284        $arrMaker = array();
285        $arrMaker = $objQuery->select('name', 'dtb_maker', $where, array($maker_id));
286        $arrForm['name'] = $arrMaker[0]['name'];
287
288        return $arrForm;
289    }
290
291    /**
292     * 入力エラーチェック.
293     *
294     * @param  array $arrForm メーカー情報
295     * @return array $objErr->arrErr エラー内容
296     */
297    function lfErrorCheck(&$arrForm) {
298        $objErr = new SC_CheckError_Ex($arrForm);
299        $objErr->doFunc(array('メーカー名', 'name', SMTEXT_LEN), array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
300
301        // maker_id の正当性チェック
302        if (!empty($arrForm['maker_id'])) {
303            $objDb = new SC_Helper_DB_Ex();
304            if (!SC_Utils_Ex::sfIsInt($arrForm['maker_id'])
305                || SC_Utils_Ex::sfIsZeroFilling($arrForm['maker_id'])
306                || !$objDb->sfIsRecord('dtb_maker', 'maker_id', array($arrForm['maker_id']))
307            ) {
308                // maker_idが指定されていて、且つその値が不正と思われる場合はエラー
309                $objErr->arrErr['maker_id'] = '※ メーカーIDが不正です<br />';
310            }
311        }
312        if (!isset($objErr->arrErr['name'])) {
313            $objQuery =& SC_Query_Ex::getSingletonInstance();
314            $arrMaker = array();
315            $arrMaker = $objQuery->select('maker_id, name', 'dtb_maker', 'del_flg = 0 AND name = ?', array($arrForm['name']));
316
317            // 編集中のレコード以外に同じ名称が存在する場合
318            if ($arrMaker[0]['maker_id'] != $arrForm['maker_id'] && $arrMaker[0]['name'] == $arrForm['name']) {
319                $objErr->arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br />';
320            }
321        }
322
323        return $objErr->arrErr;
324    }
325}
Note: See TracBrowser for help on using the repository browser.