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

Revision 22926, 8.7 KB checked in by Seasoft, 11 years ago (diff)

#2287 (環境によりデストラクタが正しく動作しないケースがある)
#2288 (リクエスト単位で実行されるべきログ出力がブロックにも適用されている)
#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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