source: branches/version-2_12-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Bloc.php @ 22610

Revision 22610, 8.9 KB checked in by pineray, 11 years ago (diff)

#2176 pageクラスからdtb_blocテーブルを直接指定している箇所をなくす

  • 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_Design_Bloc 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 = 'design/bloc.tpl';
49        $this->tpl_subno_edit = 'bloc';
50        $this->text_row = 13;
51        $this->tpl_subno = 'bloc';
52        $this->tpl_mainno = 'design';
53        $this->tpl_maintitle = 'デザイン管理';
54        $this->tpl_subtitle = 'ブロック設定';
55        $masterData = new SC_DB_MasterData_Ex();
56        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
57    }
58
59    /**
60     * Page のプロセス.
61     *
62     * @return void
63     */
64    function process()
65    {
66        $this->action();
67        $this->sendResponse();
68    }
69
70    /**
71     * Page のアクション.
72     *
73     * @return void
74     */
75    function action()
76    {
77
78        $objFormParam = new SC_FormParam_Ex();
79        $this->lfInitParam($objFormParam);
80        $objFormParam->setParam($_REQUEST);
81        $objFormParam->convParam();
82        $this->arrErr = $objFormParam->checkError();
83        $is_error = (!SC_Utils_Ex::isBlank($this->arrErr));
84
85        $this->bloc_id = $objFormParam->getValue('bloc_id');
86        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
87
88        $objBloc = new SC_Helper_Bloc_Ex($this->device_type_id);
89        $objLayout = new SC_Helper_PageLayout_Ex();
90
91        switch ($this->getMode()) {
92            // 登録/更新
93            case 'confirm':
94                if (!$is_error) {
95                    $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objBloc);
96                    if (SC_Utils_Ex::isBlank($this->arrErr)) {
97                        $result = $this->doRegister($objFormParam, $objBloc);
98                        if ($result !== false) {
99                            $arrPram = array(
100                                'bloc_id' => $result,
101                                'device_type_id' => $this->device_type_id,
102                                'msg' => 'on',
103                            );
104
105                            SC_Response_Ex::reload($arrPram, true);
106                            SC_Response_Ex::actionExit();
107                        }
108                    }
109                }
110                break;
111
112            // 削除
113            case 'delete':
114                if (!$is_error) {
115                    if ($this->doDelete($objFormParam, $objBloc)) {
116                        $arrPram = array(
117                            'device_type_id' => $this->device_type_id,
118                            'msg' => 'on',
119                        );
120
121                        SC_Response_Ex::reload($arrPram, true);
122                        SC_Response_Ex::actionExit();
123                    }
124                }
125                break;
126
127            default:
128                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
129                    // 完了メッセージ
130                    $this->tpl_onload = "alert('登録が完了しました。');";
131                }
132                break;
133        }
134
135        if (!$is_error) {
136            // ブロック一覧を取得
137            $this->arrBlocList = $objBloc->getList();
138            // bloc_id が指定されている場合にはブロックデータの取得
139            if (!SC_Utils_Ex::isBlank($this->bloc_id)) {
140                $arrBloc = $this->getBlocTemplate($this->bloc_id, $objBloc);
141                $objFormParam->setParam($arrBloc);
142            }
143        } else {
144            // 画面にエラー表示しないため, ログ出力
145            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
146        }
147        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
148        $this->arrForm = $objFormParam->getFormParamList();
149
150    }
151
152    /**
153     * デストラクタ.
154     *
155     * @return void
156     */
157    function destroy()
158    {
159        parent::destroy();
160    }
161
162    /**
163     * パラメーター情報の初期化
164     *
165     * @param object $objFormParam SC_FormParamインスタンス
166     * @return void
167     */
168    function lfInitParam(&$objFormParam)
169    {
170        $objFormParam->addParam('ブロックID', 'bloc_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
171        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
172        $objFormParam->addParam('ブロック名', 'bloc_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
173        $objFormParam->addParam('ファイル名', 'filename', STEXT_LEN, 'a', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
174        $objFormParam->addParam('ブロックデータ', 'bloc_html');
175    }
176
177    /**
178     * ブロックのテンプレートを取得する.
179     *
180     * @param integer $bloc_id ブロックID
181     * @param SC_Helper_Bloc_Ex $objBloc SC_Helper_Bloc_Ex インスタンス
182     * @return array ブロック情報の配列
183     */
184    function getBlocTemplate($bloc_id, SC_Helper_Bloc_Ex &$objBloc)
185    {
186        $arrBloc = $objBloc->get($bloc_id);
187        return $arrBloc;
188    }
189
190    /**
191     * 登録を実行する.
192     *
193     * ファイルの作成に失敗した場合は, エラーメッセージを出力し,
194     * データベースをロールバックする.
195     *
196     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
197     * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス
198     * @return integer|boolean 登録が成功した場合, 登録したブロックID;
199     *                         失敗した場合 false
200     */
201    function doRegister(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc)
202    {
203        $arrParams = $objFormParam->getHashArray();
204        $result = $objBloc->save($arrParams);
205
206        if (!$result) {
207            $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />';
208        }
209
210        return $result;
211    }
212
213    /**
214     * 削除を実行する.
215     *
216     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
217     * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス
218     * @return boolean 登録が成功した場合 true; 失敗した場合 false
219     */
220    function doDelete(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc)
221    {
222        $arrParams = $objFormParam->getHashArray();
223        $result = $objBloc->delete($arrParams['bloc_id']);
224
225        if (!$result) {
226            $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />';
227        }
228
229        return $result;
230    }
231
232    /**
233     * エラーチェックを行う.
234     *
235     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
236     * @return array エラーメッセージの配列
237     */
238    function lfCheckError(&$objFormParam, &$arrErr, SC_Helper_Bloc_Ex &$objBloc)
239    {
240        $arrParams = $objFormParam->getHashArray();
241        $objErr = new SC_CheckError_Ex($arrParams);
242        $objErr->arrErr =& $arrErr;
243        $objErr->doFunc(array('ブロック名', 'bloc_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
244        $objErr->doFunc(array('ファイル名', 'filename', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK','FILE_NAME_CHECK_BY_NOUPLOAD'));
245
246        $where = 'filename = ?';
247        $arrValues = array($arrParams['filename']);
248
249        // 変更の場合は自ブロックを除外
250        if (!SC_Utils_Ex::isBlank($arrParams['bloc_id'])) {
251            $where .= ' AND bloc_id <> ?';
252            $arrValues[] = $arrParams['bloc_id'];
253        }
254        $arrBloc = $objBloc->getWhere($where, $arrValues);
255        if (!SC_Utils_Ex::isBlank($arrBloc)) {
256            $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />';
257        }
258        return $objErr->arrErr;
259    }
260}
Note: See TracBrowser for help on using the repository browser.