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

Revision 22856, 11.4 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • 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 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/index.tpl';
44        $this->tpl_subno = 'layout';
45        $this->tpl_mainno = 'design';
46        $this->tpl_maintitle = 'デザイン管理';
47        $this->tpl_subtitle = 'レイアウト設定';
48        $masterData = new SC_DB_MasterData_Ex();
49        $this->arrTarget = $masterData->getMasterData('mtb_target');
50        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process()
59    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    function action()
70    {
71        $objLayout = new SC_Helper_PageLayout_Ex();
72        $objFormParam = new SC_FormParam_Ex();
73        $this->lfInitParam($objFormParam, intval($_REQUEST['bloc_cnt']));
74        $objFormParam->setParam($_REQUEST);
75
76        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
77        $this->page_id = $objFormParam->getValue('page_id', 1);
78
79        switch ($this->getMode()) {
80            // 新規ブロック作成
81            case 'new_bloc':
82
83                SC_Response_Ex::sendRedirect('bloc.php', array('device_type_id' => $this->device_type_id));
84                SC_Response_Ex::actionExit();
85                break;
86
87            // 新規ページ作成
88            case 'new_page':
89
90                SC_Response_Ex::sendRedirect('main_edit.php', array('device_type_id' => $this->device_type_id));
91                SC_Response_Ex::actionExit();
92                break;
93
94            // プレビュー
95            case 'preview':
96                $this->placingBlocs($objFormParam, true);
97                $filename = $this->savePreviewData($this->page_id, $objLayout);
98                $_SESSION['preview'] = 'ON';
99
100                SC_Response_Ex::sendRedirectFromUrlPath('preview/' . DIR_INDEX_PATH, array('filename' => $filename));
101                SC_Response_Ex::actionExit();
102
103            // 編集実行
104            case 'confirm':
105                $this->placingBlocs($objFormParam);
106                $arrQueryString = array('device_type_id' => $this->device_type_id, 'page_id' => $this->page_id, 'msg' => 'on');
107
108                SC_Response_Ex::reload($arrQueryString, true);
109                SC_Response_Ex::actionExit();
110
111                break;
112
113            // データ削除処理
114            case 'delete':
115                //ベースデータでなければファイルを削除
116                if ($objLayout->isEditablePage($this->device_type_id, $this->page_id)) {
117                    $objLayout->lfDelPageData($this->page_id, $this->device_type_id);
118
119                    SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id), true);
120                    SC_Response_Ex::actionExit();
121                }
122                break;
123
124            default:
125                // 完了メッセージ表示
126                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
127                    $this->tpl_onload="alert('登録が完了しました。');";
128                }
129                break;
130        }
131
132        $this->arrBlocs = $this->getLayout($this->device_type_id, $this->page_id, $objLayout);
133        $this->bloc_cnt = count($this->arrBlocs);
134        // 編集中のページ
135        $this->arrPageData = $objLayout->getPageProperties($this->device_type_id, $this->page_id);
136        // 編集可能ページ一覧
137        $this->arrEditPage = $objLayout->getPageProperties($this->device_type_id, null);
138        //サブタイトルを取得
139        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
140
141    }
142
143    /**
144     * デストラクタ.
145     *
146     * @return void
147     */
148    function destroy()
149    {
150        parent::destroy();
151    }
152
153    /**
154     * フォームパラメーターの初期化を行う.
155     *
156     * @param SC_FormParam $objFormParam SC_FormParam インスタンス.
157     * @param integer $bloc_cnt ブロック数
158     * @return void
159     */
160    function lfInitParam(&$objFormParam, $bloc_cnt = 0)
161    {
162        $objFormParam->addParam('ページID', 'page_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
163        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
164        $objFormParam->addParam('ブロック数', 'bloc_cnt', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
165
166        for ($i = 1; $i <= $bloc_cnt; $i++) {
167            $objFormParam->addParam('ブロック名', 'name_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'GRAPH_CHECK'));
168            $objFormParam->addParam('ブロックID', 'id_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
169            $objFormParam->addParam('ターゲットID', 'target_id_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'ALNUM_CHECK'));
170            $objFormParam->addParam('TOP座標', 'top_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
171            $objFormParam->addParam('全ページ', 'anywhere_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
172        }
173    }
174
175    /**
176     * ブロックのレイアウト情報を取得する.
177     *
178     * @param integer $device_type_id 端末種別ID
179     * @param integer $page_id ページID
180     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
181     * @return array レイアウト情報の配列
182     */
183    function getLayout($device_type_id, $page_id, &$objLayout)
184    {
185        $arrResults = array();
186        $i = 0;
187
188        // レイアウト済みのブロックデータを追加
189        $arrBlocPos = $objLayout->getBlocPositions($device_type_id, $page_id);
190        foreach ($arrBlocPos as $arrBloc) {
191            $this->copyBloc($arrResults, $arrBloc, $i);
192            $i++;
193        }
194
195        // 未使用のブロックデータを追加
196        $arrBloc = $objLayout->getBlocs($device_type_id);
197        foreach ($arrBloc as $arrBloc) {
198            if (!$this->existsBloc($arrBloc, $arrResults)) {
199                $arrBloc['target_id'] = TARGET_ID_UNUSED;
200                $this->copyBloc($arrResults, $arrBloc, $i);
201                $i++;
202            }
203        }
204
205        return $arrResults;
206    }
207
208    /**
209     * ブロック情報の配列をコピーする.
210     *
211     * @param array $arrDest コピー先ブロック情報
212     * @param array $arrFrom コピー元ブロック情報
213     * @param integer $cnt 配列番号
214     * @return void
215     */
216    function copyBloc(&$arrDest, $arrFrom, $cnt)
217    {
218        $arrDest[$cnt]['target_id'] = $this->arrTarget[$arrFrom['target_id']];
219        $arrDest[$cnt]['bloc_id'] = $arrFrom['bloc_id'];
220        $arrDest[$cnt]['bloc_row'] = $arrFrom['bloc_row'];
221        $arrDest[$cnt]['anywhere'] = $arrFrom['anywhere'];
222        $arrDest[$cnt]['name'] = $arrFrom['bloc_name'];
223    }
224
225    /**
226     * ブロックIDがコピー先の配列に追加されているかのチェックを行う.
227     *
228     * @param array $arrBloc ブロックの配列
229     * @param array $arrToBlocs チェックを行うデータ配列
230     * @return bool 存在する場合 true
231     */
232    function existsBloc($arrBloc, $arrToBlocs)
233    {
234        foreach ($arrToBlocs as $arrToBloc) {
235            if ($arrBloc['bloc_id'] === $arrToBloc['bloc_id']) {
236                return true;
237            }
238        }
239
240        return false;
241    }
242
243    /**
244     * プレビューするデータを DB に保存する.
245     *
246     * @param integer $page_id プレビューを行うページID
247     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
248     * @return string プレビューを行う tpl_mainpage ファイル名
249     */
250    function savePreviewData($page_id, &$objLayout)
251    {
252        $arrPageData = $objLayout->getPageProperties(DEVICE_TYPE_PC, $page_id);
253        $objQuery =& SC_Query_Ex::getSingletonInstance();
254        $arrPageData[0]['page_id'] = 0;
255        $objQuery->update('dtb_pagelayout', $arrPageData[0], 'page_id = 0 AND device_type_id = ?', array(DEVICE_TYPE_PC));
256
257        return $arrPageData[0]['filename'];
258    }
259
260    /**
261     * ブロックを配置する.
262     *
263     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
264     * @param boolean $is_preview プレビュー時の場合 true
265     * @return void
266     */
267    function placingBlocs(&$objFormParam, $is_preview = false)
268    {
269        $page_id = $is_preview ? 0 : $objFormParam->getValue('page_id');
270        $device_type_id = $objFormParam->getValue('device_type_id');
271        $bloc_cnt = $objFormParam->getValue('bloc_cnt');
272        $objQuery =& SC_Query_Ex::getSingletonInstance();
273        $objQuery->begin();
274        $objQuery->delete('dtb_blocposition', 'page_id = ? AND device_type_id = ?',
275                          array($page_id, $device_type_id));
276        $arrTargetFlip = array_flip($this->arrTarget);
277        for ($i = 1; $i <= $bloc_cnt; $i++) {
278            // bloc_id が取得できない場合は INSERT しない
279            $id = $objFormParam->getValue('id_' . $i);
280            if (SC_Utils_Ex::isBlank($id)) {
281                continue;
282            }
283            // 未使用は INSERT しない
284            $arrParams['target_id']  = $arrTargetFlip[$objFormParam->getValue('target_id_' . $i)];
285            if ($arrParams['target_id'] == TARGET_ID_UNUSED) {
286                continue;
287            }
288
289            // 他のページに anywhere が存在する場合は INSERT しない
290            $arrParams['anywhere'] = intval($objFormParam->getValue('anywhere_' . $i));
291            if ($arrParams['anywhere'] == 1) {
292                $exists = $objQuery->exists('dtb_blocposition', 'anywhere = 1 AND bloc_id = ? AND device_type_id = ?',
293                                            array($id, $device_type_id));
294                if ($exists) {
295                    continue;
296                }
297            }
298
299            $arrParams['device_type_id'] = $device_type_id;
300            $arrParams['page_id'] = $page_id;
301            $arrParams['bloc_id'] = $id;
302            $arrParams['bloc_row'] = $objFormParam->getValue('top_' . $i);
303
304            if ($arrParams['page_id'] == 0) {
305                $arrParams['anywhere'] = 0;
306            }
307
308            $objQuery->insert('dtb_blocposition', $arrParams);
309        }
310        $objQuery->commit();
311    }
312}
Note: See TracBrowser for help on using the repository browser.