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

Revision 22567, 12.2 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

  • 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        $objLayout = new SC_Helper_PageLayout_Ex();
89
90        switch ($this->getMode()) {
91            // 登録/更新
92            case 'confirm':
93                if (!$is_error) {
94                    $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objLayout);
95                    if (SC_Utils_Ex::isBlank($this->arrErr)) {
96                        $result = $this->doRegister($objFormParam, $objLayout);
97                        if ($result !== false) {
98                            $arrPram = array(
99                                'bloc_id' => $result,
100                                'device_type_id' => $this->device_type_id,
101                                'msg' => 'on',
102                            );
103
104                            SC_Response_Ex::reload($arrPram, true);
105                            SC_Response_Ex::actionExit();
106                        }
107                    }
108                }
109                break;
110
111            // 削除
112            case 'delete':
113                if (!$is_error) {
114                    if ($this->doDelete($objFormParam, $objLayout)) {
115                        $arrPram = array(
116                            'device_type_id' => $this->device_type_id,
117                            'msg' => 'on',
118                        );
119
120                        SC_Response_Ex::reload($arrPram, true);
121                        SC_Response_Ex::actionExit();
122                    }
123                }
124                break;
125
126            default:
127                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
128                    // 完了メッセージ
129                    $this->tpl_onload = "alert('登録が完了しました。');";
130                }
131                break;
132        }
133
134        if (!$is_error) {
135            // ブロック一覧を取得
136            $this->arrBlocList = $objLayout->getBlocs($this->device_type_id);
137            // bloc_id が指定されている場合にはブロックデータの取得
138            if (!SC_Utils_Ex::isBlank($this->bloc_id)) {
139                $arrBloc = $this->getBlocTemplate($this->device_type_id, $this->bloc_id, $objLayout);
140                $objFormParam->setParam($arrBloc);
141            }
142        } else {
143            // 画面にエラー表示しないため, ログ出力
144            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
145        }
146        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
147        $this->arrForm = $objFormParam->getFormParamList();
148
149    }
150
151    /**
152     * デストラクタ.
153     *
154     * @return void
155     */
156    function destroy()
157    {
158        parent::destroy();
159    }
160
161    /**
162     * パラメーター情報の初期化
163     *
164     * @param object $objFormParam SC_FormParamインスタンス
165     * @return void
166     */
167    function lfInitParam(&$objFormParam)
168    {
169        $objFormParam->addParam('ブロックID', 'bloc_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
170        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
171        $objFormParam->addParam('ブロック名', 'bloc_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
172        $objFormParam->addParam('ファイル名', 'filename', STEXT_LEN, 'a', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
173        $objFormParam->addParam('ブロックデータ', 'bloc_html');
174    }
175
176    /**
177     * ブロックのテンプレートを取得する.
178     *
179     * @param integer $device_type_id 端末種別ID
180     * @param integer $bloc_id ブロックID
181     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
182     * @return array ブロック情報の配列
183     */
184    function getBlocTemplate($device_type_id, $bloc_id, &$objLayout)
185    {
186        $arrBloc = $objLayout->getBlocs($device_type_id, 'bloc_id = ?', array($bloc_id));
187        if (SC_Utils_Ex::isAbsoluteRealPath($arrBloc[0]['tpl_path'])) {
188            $tpl_path = $arrBloc[0]['tpl_path'];
189        } else {
190            $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id) . BLOC_DIR . $arrBloc[0]['tpl_path'];
191        }
192        if (file_exists($tpl_path)) {
193            $arrBloc[0]['bloc_html'] = file_get_contents($tpl_path);
194        }
195        return $arrBloc[0];
196    }
197
198    /**
199     * 登録を実行する.
200     *
201     * ファイルの作成に失敗した場合は, エラーメッセージを出力し,
202     * データベースをロールバックする.
203     *
204     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
205     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
206     * @return integer|boolean 登録が成功した場合, 登録したブロックID;
207     *                         失敗した場合 false
208     */
209    function doRegister(&$objFormParam, &$objLayout)
210    {
211        $arrParams = $objFormParam->getHashArray();
212
213        $objQuery =& SC_Query_Ex::getSingletonInstance();
214        $objQuery->begin();
215
216        // blod_id が空の場合は新規登録
217        $is_new = SC_Utils_Ex::isBlank($arrParams['bloc_id']);
218        $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR;
219        // 既存データの重複チェック
220        if (!$is_new) {
221            $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ?', array($arrParams['bloc_id']));
222
223            // 既存のファイルが存在する場合は削除しておく
224            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl';
225            if (file_exists($exists_file)) {
226                unlink($exists_file);
227            }
228        }
229
230        $table = 'dtb_bloc';
231        $arrValues = $objQuery->extractOnlyColsOf($table, $arrParams);
232        $arrValues['tpl_path'] = $arrParams['filename'] . '.tpl';
233        $arrValues['update_date'] = 'CURRENT_TIMESTAMP';
234
235        // 新規登録
236        if ($is_new || SC_Utils_Ex::isBlank($arrExists)) {
237            $objQuery->setOrder('');
238            $arrValues['bloc_id'] = 1 + $objQuery->max('bloc_id', $table, 'device_type_id = ?',
239                                                       array($arrValues['device_type_id']));
240            $arrValues['create_date'] = 'CURRENT_TIMESTAMP';
241            $objQuery->insert($table, $arrValues);
242        }
243        // 更新
244        else {
245            $objQuery->update($table, $arrValues, 'bloc_id = ? AND device_type_id = ?',
246                              array($arrValues['bloc_id'], $arrValues['device_type_id']));
247        }
248
249        $bloc_path = $bloc_dir . $arrValues['tpl_path'];
250        if (!SC_Helper_FileManager_Ex::sfWriteFile($bloc_path, $arrParams['bloc_html'])) {
251            $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />';
252            $objQuery->rollback();
253            return false;
254        }
255
256        $objQuery->commit();
257        return $arrValues['bloc_id'];
258    }
259
260    /**
261     * 削除を実行する.
262     *
263     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
264     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
265     * @return boolean 登録が成功した場合 true; 失敗した場合 false
266     */
267    function doDelete(&$objFormParam, &$objLayout)
268    {
269        $arrParams = $objFormParam->getHashArray();
270        $objQuery =& SC_Query_Ex::getSingletonInstance();
271        $objQuery->begin();
272
273        $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ? AND deletable_flg = 1',
274                                          array($arrParams['bloc_id']));
275        $is_error = false;
276        if (!SC_Utils_Ex::isBlank($arrExists)) {
277            $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?',
278                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id']));
279            $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?',
280                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id']));
281
282            $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR;
283            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl';
284
285            // ファイルの削除
286            if (file_exists($exists_file)) {
287                if (!unlink($exists_file)) {
288                    $is_error = true;
289                }
290            }
291        } else {
292            $is_error = true;
293        }
294
295        if ($is_error) {
296            $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />';
297            $objQuery->rollback();
298            return false;
299        }
300        $objQuery->commit();
301        return true;
302    }
303
304    /**
305     * エラーチェックを行う.
306     *
307     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
308     * @return array エラーメッセージの配列
309     */
310    function lfCheckError(&$objFormParam, &$arrErr, &$objLayout)
311    {
312        $arrParams = $objFormParam->getHashArray();
313        $objErr = new SC_CheckError_Ex($arrParams);
314        $objErr->arrErr =& $arrErr;
315        $objErr->doFunc(array('ブロック名', 'bloc_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
316        $objErr->doFunc(array('ファイル名', 'filename', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK','FILE_NAME_CHECK_BY_NOUPLOAD'));
317
318        $where = 'filename = ?';
319        $arrValues = array($arrParams['filename']);
320
321        // 変更の場合は自ブロックを除外
322        if (!SC_Utils_Ex::isBlank($arrParams['bloc_id'])) {
323            $where .= ' AND bloc_id <> ?';
324            $arrValues[] = $arrParams['bloc_id'];
325        }
326        $arrBloc = $objLayout->getBlocs($arrParams['device_type_id'], $where, $arrValues);
327        if (!SC_Utils_Ex::isBlank($arrBloc)) {
328            $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />';
329        }
330        return $objErr->arrErr;
331    }
332}
Note: See TracBrowser for help on using the repository browser.