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

Revision 22857, 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     * @return void
146     */
147    function destroy()
148    {
149        parent::destroy();
150    }
151
152    /**
153     * フォームパラメーターの初期化を行う.
154     *
155     * @param SC_FormParam $objFormParam SC_FormParam インスタンス.
156     * @param integer $bloc_cnt ブロック数
157     * @return void
158     */
159    function lfInitParam(&$objFormParam, $bloc_cnt = 0)
160    {
161        $objFormParam->addParam('ページID', 'page_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
162        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
163        $objFormParam->addParam('ブロック数', 'bloc_cnt', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
164
165        for ($i = 1; $i <= $bloc_cnt; $i++) {
166            $objFormParam->addParam('ブロック名', 'name_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'GRAPH_CHECK'));
167            $objFormParam->addParam('ブロックID', 'id_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
168            $objFormParam->addParam('ターゲットID', 'target_id_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'ALNUM_CHECK'));
169            $objFormParam->addParam('TOP座標', 'top_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
170            $objFormParam->addParam('全ページ', 'anywhere_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
171        }
172    }
173
174    /**
175     * ブロックのレイアウト情報を取得する.
176     *
177     * @param integer $device_type_id 端末種別ID
178     * @param integer $page_id ページID
179     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
180     * @return array レイアウト情報の配列
181     */
182    function getLayout($device_type_id, $page_id, &$objLayout)
183    {
184        $arrResults = array();
185        $i = 0;
186
187        // レイアウト済みのブロックデータを追加
188        $arrBlocPos = $objLayout->getBlocPositions($device_type_id, $page_id);
189        foreach ($arrBlocPos as $arrBloc) {
190            $this->copyBloc($arrResults, $arrBloc, $i);
191            $i++;
192        }
193
194        // 未使用のブロックデータを追加
195        $arrBloc = $objLayout->getBlocs($device_type_id);
196        foreach ($arrBloc as $arrBloc) {
197            if (!$this->existsBloc($arrBloc, $arrResults)) {
198                $arrBloc['target_id'] = TARGET_ID_UNUSED;
199                $this->copyBloc($arrResults, $arrBloc, $i);
200                $i++;
201            }
202        }
203
204        return $arrResults;
205    }
206
207    /**
208     * ブロック情報の配列をコピーする.
209     *
210     * @param array $arrDest コピー先ブロック情報
211     * @param array $arrFrom コピー元ブロック情報
212     * @param integer $cnt 配列番号
213     * @return void
214     */
215    function copyBloc(&$arrDest, $arrFrom, $cnt)
216    {
217        $arrDest[$cnt]['target_id'] = $this->arrTarget[$arrFrom['target_id']];
218        $arrDest[$cnt]['bloc_id'] = $arrFrom['bloc_id'];
219        $arrDest[$cnt]['bloc_row'] = $arrFrom['bloc_row'];
220        $arrDest[$cnt]['anywhere'] = $arrFrom['anywhere'];
221        $arrDest[$cnt]['name'] = $arrFrom['bloc_name'];
222    }
223
224    /**
225     * ブロックIDがコピー先の配列に追加されているかのチェックを行う.
226     *
227     * @param array $arrBloc ブロックの配列
228     * @param array $arrToBlocs チェックを行うデータ配列
229     * @return bool 存在する場合 true
230     */
231    function existsBloc($arrBloc, $arrToBlocs)
232    {
233        foreach ($arrToBlocs as $arrToBloc) {
234            if ($arrBloc['bloc_id'] === $arrToBloc['bloc_id']) {
235                return true;
236            }
237        }
238
239        return false;
240    }
241
242    /**
243     * プレビューするデータを DB に保存する.
244     *
245     * @param integer $page_id プレビューを行うページID
246     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
247     * @return string プレビューを行う tpl_mainpage ファイル名
248     */
249    function savePreviewData($page_id, &$objLayout)
250    {
251        $arrPageData = $objLayout->getPageProperties(DEVICE_TYPE_PC, $page_id);
252        $objQuery =& SC_Query_Ex::getSingletonInstance();
253        $arrPageData[0]['page_id'] = 0;
254        $objQuery->update('dtb_pagelayout', $arrPageData[0], 'page_id = 0 AND device_type_id = ?', array(DEVICE_TYPE_PC));
255
256        return $arrPageData[0]['filename'];
257    }
258
259    /**
260     * ブロックを配置する.
261     *
262     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
263     * @param boolean $is_preview プレビュー時の場合 true
264     * @return void
265     */
266    function placingBlocs(&$objFormParam, $is_preview = false)
267    {
268        $page_id = $is_preview ? 0 : $objFormParam->getValue('page_id');
269        $device_type_id = $objFormParam->getValue('device_type_id');
270        $bloc_cnt = $objFormParam->getValue('bloc_cnt');
271        $objQuery =& SC_Query_Ex::getSingletonInstance();
272        $objQuery->begin();
273        $objQuery->delete('dtb_blocposition', 'page_id = ? AND device_type_id = ?',
274                          array($page_id, $device_type_id));
275        $arrTargetFlip = array_flip($this->arrTarget);
276        for ($i = 1; $i <= $bloc_cnt; $i++) {
277            // bloc_id が取得できない場合は INSERT しない
278            $id = $objFormParam->getValue('id_' . $i);
279            if (SC_Utils_Ex::isBlank($id)) {
280                continue;
281            }
282            // 未使用は INSERT しない
283            $arrParams['target_id']  = $arrTargetFlip[$objFormParam->getValue('target_id_' . $i)];
284            if ($arrParams['target_id'] == TARGET_ID_UNUSED) {
285                continue;
286            }
287
288            // 他のページに anywhere が存在する場合は INSERT しない
289            $arrParams['anywhere'] = intval($objFormParam->getValue('anywhere_' . $i));
290            if ($arrParams['anywhere'] == 1) {
291                $exists = $objQuery->exists('dtb_blocposition', 'anywhere = 1 AND bloc_id = ? AND device_type_id = ?',
292                                            array($id, $device_type_id));
293                if ($exists) {
294                    continue;
295                }
296            }
297
298            $arrParams['device_type_id'] = $device_type_id;
299            $arrParams['page_id'] = $page_id;
300            $arrParams['bloc_id'] = $id;
301            $arrParams['bloc_row'] = $objFormParam->getValue('top_' . $i);
302
303            if ($arrParams['page_id'] == 0) {
304                $arrParams['anywhere'] = 0;
305            }
306
307            $objQuery->insert('dtb_blocposition', $arrParams);
308        }
309        $objQuery->commit();
310    }
311}
Note: See TracBrowser for help on using the repository browser.