source: branches/version-2_13_0/data/class/pages/admin/design/LC_Page_Admin_Design.php @ 23126

Revision 23126, 11.4 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

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