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

Revision 21689, 12.7 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 インスタンスを呼び出す処理を統一

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